Child pages
  • Tutorial - Keyboard Accessibility Plugin

Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 24 Next »

The Fluid library includes a jQuery Keyboard Accessibility (a11y) plugin. This plugin allows developers to add keyboard handlers to their code without a lot of extra overhead. This tutorial will walk the reader through an example of using the plugin.

This tutorial assumes that:

  • you are already familiar with HTML, Javascript and CSS
  • you are basically familiar with what the Keyboard Accessibility Plugin is and does
  • now you just want to know how to use it.

For technical API documentation, see Keyboard Accessibility Plugin API.

Tutorial: How to Use the Keyboard Accessibility Plugin

Scenario

Let's say you are creating a set of tabs using an unordered list. This tutorial will show you how to use the jQuery Keyboard Accessibility Plugin to ensure that your tabs can be used with the keyboard.

There are five basic steps to adding Keyboard Accessibility to your application:

  • Setup
  • Step 1: Prepare your markup
  • Step 2: Write the script
  • Step 3: Add the script to your HTML
  • Step 4: Apply styles

The rest of this tutorial will explain each of these steps in detail.

On This Page
Still need help?

Join the fluid-talk mailing list and ask your questions there.

Setup: Download and install the Fluid Infusion library

  1. Download a copy of the Fluid Infusion component library from:
  2. Unpack the zip file you just downloaded, and place the resulting folder somewhere convenient for your development purposes.
    The folder will have the release number in its name (e.g. infusion-1.4/). The rest of this tutorial will use infusion-1.4 in its examples, but if you downloaded a different version, you'll have to adjust.

Step 1: Prepare the required files

You'll need to create a file, say initalize.js, to contain your code - the script you write to apply keyboard a11y to your tabs.
If you use the InfusionAll file, then your <head> might look like:

<script type="text/javascript" src="infusion-1.2/InfusionAll.js"></script>
<script type="text/javascript" src="initialize.js"></script>

NOTE that the InfusionAll.js file is minified - all of the whitespace has been removed, so it isn't really human-readable.

If you want to be able to debug the code, you'll want to include each of the required files individually. This would look like this:

<script type="text/javascript" src="infusion-1.2/lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="infusion-1.2/lib/jquery/ui/js/ui.core.js"></script>
<script type="text/javascript" src="infusion-1.2/src/webapp/lib/jquery/plugins/delegate/js/jquery.delegate.js"></script>
<script type="text/javascript" src="infusion-1.2/framework/core/js/jquery.keyboard-a11y.js"></script>
<script type="text/javascript" src="initialize.js"></script>

You'll also want to link to the FSS style sheets to get a tab-like appearance:

<link href="infusion-1.2/framework/fss/css/fss-layout.css" rel="stylesheet" type="text/css" />
<link href="infusion-1.2/framework/fss/css/fss-theme-mist.css" rel="stylesheet" type="text/css" />

Step 2: Your markup

You want to make your tabs keyboard accessible. Your markup might look like this (with FSS to give us a quick tab appearance):


<body class="fl-theme-mist">

        <!-- Code for the tabs -->
        <ul id="tabs" class="fl-tabs">
          <li class="fl-tabs-active"><a href="#catsPanel">Cats</a></li>
          <li><a href="#dogsPanel">Dogs</a></li>
          <li><a href="#hamstersPanel">Hamsters</a></li>
          <li><a href="#alligatorsPanel">Alligators</a></li>
        </ul>

        <!-- Code for the tab content panels -->
        <div id="panels">
            <div id="catsPanel">Cats <a href="http://icanhascheezburger.com/2007/01/11/i-can-has-cheezburger/">meow</a>.</div>
            <div id="dogsPanel">Dogs <a href="http://thebark.com/">bark</a>.</div>
            <div id="hamstersPanel">Hamsters <a href="http://en.wikipedia.org/wiki/Hamster_wheel">wheel</a>.</div>
            <div id="alligatorsPanel">Alligators <a href="http://www.drinknation.com/drink/Alligator-Bite">bite</a>.</div>
        </div>
</body>

In a browser window, this might look something like this:

(This made use of the following FSS files: fss-layout.css, fss-theme-mist.css)

Step 3: Create your script

Remember that initalize.js file we prepared before? We'll use that file to contain your initialization script - the script you write to apply keyboard a11y to your tabs.

In this file, write a function that enables the list items to be selectable with the arrow keys, and show/hide the appropriate panel:

jQuery(document).ready(function(){
    var tabs = $("#tabs");
    
    tabs.fluid("selectable", {
        selectableSelector : 'li',
        direction: fluid.a11y.orientation.HORIZONTAL,
        onUnselect: function(el){
            // hide the panel we're leaving....
            $(el).removeClass('fl-tabs-active');            
            $($('a',el).attr('href')).css('display','none');            
        },
        onSelect : function(el){
            // ...and show the panel we're entering
            $(el).addClass('fl-tabs-active');
            $($('a',el).attr('href')).css('display','block');            
        }        
    });
});

This function says "once the DOM is ready to be traversed, make all the <LI> elements within the #tabs container selectable with the left and right arrow keys.

selectableSelector could be any selector, but for the purposes of this tutorial we're interested in the list items themselves.

That's it! That's all you need to do to add keyboard functionality to your document.

Since there is no visual cues for keyboard accesssibility, it's important to understand that you need to create those cues to know what is selected and where. In CSS, the most basic approach is to take advantage of the outline border-esque feature, added by default in FSS.

  • No labels