Archive for the Category 'semantic web'

(Another) Scrollable Plugin for jQuery

I was having a bit of difficulty finding a jQuery plugin that not only provided scrolling behavior to a list of elements, but also used & then generated markup that could still be accessible, semantic & validate whether or not the user ran the javascript.

jQueryThe best plugin that I could find that was already out there was Tero Piirainen's jquery.scrollable.js. If you check it out you'll quickly see that the markup that's used to generate the scrolling items could be improved upon. Nothing in my version of jquery.scrollable.js removes functionality from what Tero put together, and the improvements are basic.

  1. make those items scrollable horizotally or vertically
  2. decide how many items are visible at once
  3. scroll elements with mouse, arrow keys and mousewheel (requires mousewheel.js)
  4. make navigational buttons without programming
  5. have programmatic actions: next, prev, nextPage, prevPage, seekTo, begin, end
  6. need to know when list is scrolled with custom event listener
  7. You can now start with semantic markup
  8. I want this all in single js file that weights only 3.9 4.1 Kb minified!

First we start with simple & semantic markup

There's nothing fancy going on here at all, just a wrapping element, an anchor and an unordered list. Unfortunately due to the design requirements of this particular implementation, an additional <div> had to be added. If it wasn't for the creative constraint, and the lack of support for vertical-align: middle across many browsers, this extra <div> would have not been included.

HTML:
  1. <div class="scrolling-list">
  2.     <a href="#newspage" class="more-link">More News</a>
  3.   <ol>
  4.         <li><div><a href="#">Someone reports second-quarter 2008 earnings &raquo;</a></div></li>
  5.         <li><div><a href="#">Bear scares comedian, everybody laughs &raquo;</a></div></li>
  6.         <li><div><a href="#">Someone Completes Someone else's Acquisition &raquo;</a></div></li>
  7.         <li><div><a href="#">Someone selected by Some Company, S.A.B. de C.V. for ADR program &raquo;</a></div></li>
  8.         <li><div><a href="#">Someone wins landmark multinational asset pooling mandate &raquo;</a></div></li>
  9.         <li><div><a href="#">Someone Announces Internal Restructuring Transactions and Guarantees Related to Acquisition &raquo;</a></div></li>
  10.         <li><div><a href="#">Someone wins comprehensive custodial mandate with one of New Zealand's largest organizations &raquo;</a></div></li>
  11.         <li><div><a href="#">Someone selected by East Timor to provide custodial services and training opportunities &raquo;</a></div></li>
  12.         <li><div><a href="#">Someone launches latest Global Derivatives Collateral offering &raquo;</a></div></li>
  13.         <li><div><a href="#">Someone expands Boston fund services operations &raquo;</a></div></li>
  14.   </ol>
  15. </div>

Presentation

Now we add styling that makes it match the look & feel of the main site.

The css required to make this bit work for you will be different for every project, so take a look at the included styles and tweak as necessary.

And now for the behavior

If the user's browser allows javascript to run, we add some additional unobtrusive behavior (including mousewheel support)

JavaScript:
  1. jQuery(function( $ ){
  2.     /**
  3.      * make sure the CSS knows that we're modifying the DOM and then style accordingly
  4.      **/       
  5.     $('.scrollable').addClass('js');
  6.     /**
  7.      * If you have an element you'd like to use the same style, but not attach the
  8.      * behavior you can turn it off by first adding the scrollable classname, but making
  9.      * sure the js classname is not applied to the element (this is what I did to show the
  10.      * "no javascript" version in the second example). Keeping the use of the scrollable
  11.      * classname for the general styles prevents having to write redundant styles
  12.      **/
  13.     $('.scrollable.nojs').removeClass('js');
  14.     /**
  15.      * a little DOM modification to keep all of the markup valid
  16.      **/
  17.     $('.scrollable.js ol').attr('id','items').wrap('<ul><li></li></ul>');
  18.     $('.scrollable.js ul>li').attr('id','itemswrapper');
  19.     var emptyLinkTarget = (window.opera) ? "#" : "javascript:function(){return}"; // a hash breaks a few flavors of IE & a javascript link (though it's poor form) breaks Opera.
  20.     $('.scrollable.js ul').prepend('<li><a class="prev" href="'+emptyLinkTarget+'">&lt;&lt;</a></li>').append('<li><a class="next" href="'+emptyLinkTarget+'">&gt;&gt;</a></li>');
  21.     /**
  22.      * and now we initiate
  23.      **/
  24.     $('.scrollable.js').scrollable({
  25.         size:3,
  26.         horizontal:false,
  27.         duration:1500,
  28.         items:'#items',
  29.         prev:'.prev',
  30.         next:'.next'
  31.     });
  32. });

This is the generated source we end up with... There's one thing you might notice, and that's the div class="__scrollable", though I initially placed that element outside of it's parent ol it did not work. It has something to do with how the xhtml 1.0 strict doctype is handled by the browsers. Though this may work in HTML 4.0 or various browser quirks modes, I haven't specifically tested all possible cases.

HTML:
  1. <div class="scrollable js">
  2.     <a href="#" class="more-link">More News</a>
  3.     <ul>
  4.         <li><a class="prev" href="javascript:function(){return}">&lt;&lt;</a></li>
  5.         <li id="itemswrapper">
  6.             <ol style="overflow: hidden; position: relative; visibility: visible; height: 124px;" id="items">
  7.                 <div class="__scrollable" style="position: absolute; height: 200000em;">
  8.                     <li><div><a href="#">Someone reports second-quarter 2008 earnings »</a></div></li>
  9.                     <li><div><a href="#">Bear scares comedian, everybody laughs »</a></div></li>
  10.                     <li><div><a href="#">Someone Completes Someone else's Acquisition »</a></div></li>
  11.                     <li><div><a href="#">Someone selected by Some Company, S.A.B. de C.V. for ADR program »</a></div></li>
  12.                     <li><div><a href="#">Someone wins landmark multinational asset pooling mandate »</a></div></li>
  13.                     <li><div><a href="#">Someone Announces Internal Restructuring Transactions and Guarantees Related to Acquisition »</a></div></li>
  14.                     <li><div><a href="#">Someone wins comprehensive custodial mandate with one of New Zealand's largest organizations »</a></div></li>
  15.                     <li><div><a href="#">Someone selected by East Timor to provide custodial services and training opportunities »</a></div></li>
  16.                     <li><div><a href="#">Someone launches latest Global Derivatives Collateral offering »</a></div></li>
  17.                     <li><div><a href="#">Someone expands Boston fund services operations »</a></div></li>
  18.                 </div>
  19.                 <br clear="all"/>
  20.             </ol>
  21.         </li>
  22.         <li><a class="next" href="javascript:function(){return}">&gt;&gt;</a></li>
  23.     </ul>
  24. </div>

This build is currently in a non-public svn repository, but I will be moving it to google code or github shortly (depending on whether or not I feel like learning how to use Git)

Standalone Demo:
http://www.naterkane.com/sandbox/scrollable/
Download:
First you'll of course need jQuery v.1.2.6
jquery.scrollable.js (7.5k)
jquery.scrollable.min.js (4.1k)
scrolling-list.css – the stylesheet used for the example
You can also grab a copy of jquery.mousewheel.js here


Participating without Participating


I've been playing with Summize for a bit now. Their super-fast queries are just really gratifying. I'm also a fan of Get Satisfaction (and trying to get satisfaction in life in general as well), though my relationship with GS is much more recent. Yesterday I found an article that showed me something pretty cool that GS is doing. They call it Overheard.

What is Overheard?

Overheard is a new feature of Get Satisfaction that bridges the public Twitter stream into Get Satisfaction's support network. Overheard lists recent Twitter posts ("tweets") related to a company and allows any user, employee, or customer to convert a selected tweet into a rich, searchable Get Satisfaction topic.

When somebody replies to a tweet via Overheard, Get Satisfaction sends a reply to that person to let them know a conversation was started in response to their issue.

So now, whenever you post something on Twitter about a company, brand, service or product that's been added to Get Satisfaction, you're indirectly adding content to Get Satisfaction. It's similar to when users of Facebook would accidentally add content to their profiles with Beacon, but not so creepy.

Image captions the semantic way

Last week I was in a meeting with a current client who put together a nice little presentation on webstandards and accessibility. Their corporate standards are very progressive and they don't let anything slide. This is a very grateful situation, as I've found it pretty rare that a client is savvy enough to say "We need all of your deliverables to be W3C compliant, accessible and semantic".

Going through their IA documents (which are estensibly just wireframes) I was still left with a few important questions. This site has alot of articles as it's the web-based version of a print publication, and many articles have images inline with the text content, just like a magazine. And one of my questions was, "How can I wite xhtml for images with captions in a semantic and meaningful way?". Part of understanding the most appropriate approach to this problem is understanding what a caption is and how it relates to an img.

What is a caption?

I decided to go to one of my favorite places and look it up.

cap–tion [kap–shuhn]
-noun

  1. a title or explanation for a picture or illustration, esp. in a magazine.
  2. a heading or title, as of a chapter, article, or page.

Interesting eh? So it looks like a caption is two things, and technically heading tags (ie. <h1>, <h2>, <h3>, <h4>, etc…) are all considered captions. So how does a caption relate to an image?

A caption is the definition of an image

Since we use <caption> (and alt attributes) to describe what is represented visually in an image, we can surmise that a definition list (<dl>) is going to be the most appropriate solution to this issue. By using definition lists we can define the relation ship between the image is the definition's title (<dt>) and the text is the definition's definition (<dd>)

CODE:
  1. <dl>
  2.     <dt><img src="http://www.naterkane.com/blog/wp-content/uploads/2006/09/motorcycle.jpg" /></dt>
  3.     <dd>This is my <em>new</em> 1978 Honda CB750 F2 cafe racer.</dd>
  4. </dl>

Image of a 1978 Honda CB750 F2 cafe racer motorcycle
This is my new 1978 Honda CB750 F2 cafe racer.

So as you can see, providing image captions this way allows you to group and associate the content together without requiring a wrapper <div> for positioning or referencing. and if there isn't a caption available, the image can still sit within the <dl> and <dt> tags for a logical inclusion of a caption at a later time.

It turns out that Darren Brierton write this article back in Feb of '05 about this very same topic. He goes to mention in a comment to his own post that definition list's aren't limited to one <dt> element followed by one <dd> element.

The semantics of definition lists is implicit rather than explicit. A <dl> element can contain any old mish-mash of <dt> and <dd> elements and still be valid. It might not, however, make any sense

Progressive Enhancement, Accessibility, Semantics and Flash

This next monday On Monday October 2 I will be giving a presentation to the lovely folks at ULTRA16 on Progressive Enhancement, Accessibility, Semantics and also how to make it happen with Flash. After monday, the presentation will be available here for anyone who may have interest.

Categories

Archives

About

Nater Kane is freelance developer and user experience & technology consultant based in Brooklyn, NY.

Nater's focus is to make the web a better place, one decision at a time.

He likes to spend time playing with his cats, riding bicycles around the city, working on his diesel vw rabbit or motorcycle, and enjoying a decent espresso.

RSS

Twitter » What I'm Up To

How I'm Social

Basecamp

Meta


Nater Kane naterkane personal http://www.naterkane.com LinkedIn Profile Web Technologist personal nater@naterkane.com 1978-09-12 voice 845.234.6698 | fax 707.922.0593
964 Flushing Ave. Brooklyn, NY 11206