16.4. HighlightAuto-Update, Sync, Sychronize, Real-Time Figure 16-8. Metaphor16.4.1. Goal StorySasha notices that a few spam comments have appeared on an old blog posting. When she clicks on the comments, they are successively Highlightedthe background color switches from white to yellow. Because she's already logged in, there's a Delete Spam button below the comments, which she clicks to send them where they belong. 16.4.2. ProblemHow can you make elements stand out? 16.4.3. Forces
16.4.4. SolutionHighlight elements by rendering them in a consistent, attention-grabbing format. This pattern has been applied to dynamic web sites prior to Ajax but is particularly important in the context of rich displays and interaction. Consistency is important here; when items are selected, they should look the same. One straightforward way to achieve this is with selected and deselected CSS classes. By dynamically switching the element's className property, you can easily Highlight and de-Highlight. Highlighting is useful in the following ways:
16.4.5. Decisions16.4.5.1. How will the Highlight look?You want the Highlight to be noticeable but not distracting. Here are some guidelines for deciding how the Highlight should look:
16.4.5.2. How will the Highlight appear and disappear?The most obvious thing to do is make Highlight state binaryan element is either Highlighted or it's not. But consider using visual effects to make the transition smoother and support visual pattern recognition (see the following "Teacher!" example). 16.4.6. Real-World Examples16.4.6.1. GmailGmail presents a list of mail messages one row at a time. You select messages by clicking on the checkbox, which causes the entire row to change to a light tan background color. The appearance of various tan-colored rows makes it easy to spot selected items, and the checkboxes also provide a clue. 16.4.6.2. A9A9 provides search results in different "Columns." Visit the Preferences page, then request to add more Columns. If you have an account, you're allowed to choose multiple Columns at once. Each Column is shown as a horizontal block in the Preferences page, and when you click the Add button, the block Highlights to confirm your choice. The interface uses Highlighting effectively, but it would be even more helpful if all added elements remained Highlighted instead of just the most recent one. 16.4.6.3. Teacher!Teacher! (http://teacherly.com/) shows a table of student grades and Highlights whichever row your mouse is hovering over. What's novel here is that when you move to another row, the Highlight doesn't just disappear, but slowly fades away (One-Second Spotlight). An AjaxPatterns demo replicates the effect (http://ajaxify.com/run/time/periodicRefresh/spotlightCustom/highlight/). 16.4.6.4. WhitespaceWhitespace (http9rules.com/whitespace/) prominently Highlights links on the side menu as you roll the mouse over them. This is a common technique used on many web sites and can be achieved entirely by using CSS styling to modify the anchor tag, absent of any JavaScript. 16.4.7. Code Example: AjaxPatterns WikiThe Wiki demo (http://ajaxify.com/run/wiki) uses Highlighting in a couple of ways:
Figure 16-9. A9 columnsThe first example is detailed in Malleable Content (Chapter 15), in which I explain the buffering Highlight. When you click outside the message area, the application checks whether you changed any text from the version originally downloaded, and if so, that text is Highlighted and prepared for uploading: function onMessageBlur(event) { ... var initialMessageContent = message.serverMessage.content; if (message.value != initialMessageContent) { pendingMessages[message.id] = true; message.style.backgroundColor = "#ffcc33"; } startPeriodicSync( ); } The sync is started again, so the item will soon be uploaded. If any further edits begin in the next few seconds, the upload will be placed on hold and the second message alteration will also be Highlighted. At any point in time, then, all of the buffered messages are Highlighted. When the messages are eventually uploaded, they revert to their normal, readonly color: for (messageId in pendingMessages) { ... $(messageId).style.backgroundColor = "#cccccc"; } 16.4.8. Related Patterns16.4.8.1. Status AreaThe Status Area (Chapter 15) is a convenient place to explain why an element is Highlighted. 16.4.8.2. One-Second SpotlightOne-Second Spotlight (see earlier) is often convenient for transitioning into and out of longer-duration Highlight periods. 16.4.9. MetaphorA fluorescent marker is used to highlight text. |