Top Banner
Building Accessible Building Accessible User Interfaces User Interfaces with JavaScript and jQuery with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of Computer Science, University of Colorado at Boulder
198

Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Dec 18, 2015

Download

Documents

Dulcie Golden
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Building Accessible User Building Accessible User InterfacesInterfaces

with JavaScript and jQuerywith JavaScript and jQuery

Antranig Basman, Core Framework Architect, The Fluid ProjectClayton Lewis, Professor of Computer Science,University of Colorado at Boulder

Page 2: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Our Goals•Guide to the ropes and pitfalls of

– JavaScript

– jQuery

•A special emphasis on techniques appropriate for

– Portals, Mashups and CMSs

– Designing accessible, flexible apps

• Finish by leading into the basics of Fluid Infusion

Page 3: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Portals, Mashups, and CMSs

•These days, diverse code and markup coexists

•Most JavaScript is written as if it owns the whole browser

•As you combine stuff, things can break

•Namespacing and privacy is essential

Page 4: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Schedule

– Javascript 101

• 8:55 Break

– jQuery

– AJAX

– Accessibility Basics

• 9:55 Break

– Accessibility Nuts and Bolts

• 10:55 Break

– Web 2.0 Accessibility and ARIA

– Fluid Infusion

• 11:55 Closing

Page 5: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Modus Operandi

•Brief introductions, so get to know one another a little

•We’ll ask you to discuss with your neighbors from time to time

•Questions, comments, and especially arguments are urged at any time!

Page 6: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Javascript 101

Page 7: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Everything is an “object”

• Extremely loose type system

- Only 6 types for values

- No types for references

• No classes

• Functions are first class

• Some annoying quirks

JavaScript is Different

Page 8: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Netscape rushed JS to market, bugs and all, and with a shabbily motivated name

• Microsoft reverse-engineered it.

• Standards committee enforced the bugs.

• In recent years JS has become a crucial technology

• Big efforts on improved implementations have delivered huge performance gains

Super-Quick History

Page 9: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Variables

• null vs. undefined

• Type coercion

• Objects and Arrays

Part 1: The Basics

Page 10: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

•Define variables with var

•Types are not specified

var mango = "yum";

mango = 12345;

mango = false;

Defining Variables

Page 11: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

•If you omit var, it will be defined as a global variable.

•This is accident prone; JavaScript won't warn you!

rottenTomato = "gross!"; // This is global

Defining Variables

Page 12: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Numbers

– lots of precision

– no distinction between floats and ints

– NaN !== NaN

• Strings

– Unicode (mostly)

– Immutable

– No character type

Numbers and Strings

Page 13: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• null is the "nothing" value

• undefined is extremely nothing

– Default value for uninitialized variables

– Also the value of missing members of objects and arguments

•exception thrown when the language encounters names which are not found in any scope

– “typeof” expressions are safe and need to be used for detection here

Null vs. Undefined

Page 14: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Truthy and Falsey

• JavaScript does a lot of automatic type coercion

– A common case is in conditions

•Shades of true and false

•Use with care

if (x)x? thing1: thing2

Page 15: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Falsey Values• false

• null

• undefined

• ""

• 0 (zero)

• NaN

• Everything else is truthy. Careful...

• -1, "false", "0" are all true

Page 16: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Equal vs. Equivalent

•Comparisons are coercive:

1 == "1" // true

0 == false // true

Non-coercive comparison:

• 0 === false // false

• 1 !== "1" // true

• 1 === Number("1") // true

Don’t use this operator!

Use this operator!

Page 17: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Objects

Page 18: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Objects Are Containers

Don’t use this!• At their core, objects are just maps or “dictionaries”

• new Object() or {} returns an empty container of key/value pairs

• Keys can be any string, values can be anything

• Two different ways to access members:

basketOfFruit.kiwis; // dot notationbasketOfFruit["figs"]; // subscript notation

• You can add new members to any object at any time

Use this!

Use this!

Page 19: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Objects Are Modifiable

var basketOfFruit = {};

// New property

basketOfFruit.apples = "macintosh";

// New method

basketOfFruit.eat = function () {

return “tasty”;

}

Page 20: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

No Classes• JavaScript doesn't have any

concept of classes

• Methods (functions) are just properties in a container:

– pass them around

– modify them

– delete them

Page 21: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Determining Types

• JavaScript has a typeof keyword for determining type

var plum = "yum";

if (typeof plum === "string") {

alert("Plum is a String!");

}

Page 22: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

typeof is Inaccurate// Inaccurate results for some built-in typestypeof({}) // 'object'typeof([]) // 'object'typeof(function() {}) // 'function'typeof(“”) // 'string'typeof(3) // 'number'typeof(false) // 'boolean'typeof(null) // 'object'typeof(undefined) // 'undefined'

Page 23: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Duck Typing• The best way to check for types: don’t.

• Check for behaviour:

function countChickens (flock) {if (flock.length && typeof flock.length === “number”) { //flock is ok to count.}

}: fluid.isArrayable(eggs)

Page 24: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Functions are first class

• Determining types

• Understanding this

• Closures

Part 2: Functions & Scope

Page 25: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

First Class Functions• Functions are data (variable values)

•You can assign them

•You can pass them as arguments

•You can return them as results

•You can add members to a function(!)

– convenient for managing names

Page 26: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Defining and Using Functions

function squeeze(aFruit) { // familiarish……}var puree = function (aFruit) { // more generally useful…};function popsicle(juiceMakerFn, fruit) {

var juice = juiceMakerFn(fruit);return freeze(juice);

}var goody = popsicle(puree, berries);var goody2 = popsicle(squeeze, berries);

Page 27: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What Does This Mean?

• No more anonymous inner classes!

• You can pass bits of logic around and have them be invoked later

• Callbacks are easy to write and ubiquitous

• Functions are our basic building block

Page 28: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

this

Page 29: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Context and this

• JavaScript this pointer is wild and unpredictable

• It points to different objects depending on the context

• Subtle, confusing, and inexplicable

Page 30: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

The Reason For This, We Will Not Discuss

• this is part of a package of language features (new, prototype, instanceof, constructor, this) which we (Fluid) do not recommend

• We will present a simpler subset of the language that lets you get all your work done

• Other dangerous features: eval, with

• Ask us in the break or afterwards if you want to know more

Page 31: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

that

Page 32: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Coping With the Problems

• this can be confusing and unstable

• Constructor functions can accidentally clobber the global namespace

• Prototypal inheritance can easily cause existing code to break

• Can we simplify things?

Page 33: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Plain Old Functions & Objects

// Just use plain old functions and objects.

function orange () {

// Stable pointer to the current instance.

var that = {};

// Anything private stays inside here.

// For public methods, just add properties.

that.squeeze = function () {...}

return that;

}

Page 34: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Closures•Functions can be defined inside other

functions

•Inner functions have access to the outer function's variables

•A closure is formed by returning the inner function from the outer function

•The inner function will still have access to all the variables from the outer function

Page 35: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

A Simple Closure – Challenge #1

function addNumbers (a, b) { var sum = a + b; function addEmUp (c) { return sum + c; } return addEmUp;}var func = addNumbers(1, 2);

func(3); // Result is ???func(5); // Result is ???

Page 36: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

A Simple Closurefunction addNumbers (a, b) {

var sum = a + b;

function addEmUp (c) {

return sum + c;

}

return addEmUp;

}

var add3 = addNumbers(1, 2);

// result is an “add 3” Function

add3(3); // Result is 6

add3(5); // Result is 8

Page 37: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Closures Simplify Event Handlers

function makeShowMessage(todaysPie) { var messageToDisplay = “Today’s Pie is: ”;

return function(event) {alert(messageToDisplay + " " + todaysPie);showPictureOfPie(event.target, todaysPie);

}}var clickHandler = makeShowMessage(“Banana creme pie”);$(element).click(clickHandler); //attach click handler using jQuery

// Shows an alert: "Today's pie is: Banana creme pie"$(element).click(); //trigger event using jQuery

Page 38: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Over to Antranig

Page 39: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

JavaScript Pitfall Challenge #2

What is wrong with the following code?

for (var i = 0; i < elements.length; i++) { var el = elements[i]; el.addEventListener('click', function() {     doSomethingWith(i, el); });}

Page 40: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

“Creating functions in a loop”

•A standard complaint from JSLint, a useful code quality tool

•Sometimes this is OK

• In this case it is not – the function body makes use of a variable held in the outer closure scope

•Every listener will see i as n and el as undefined

Page 41: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Basic Remedy #1 – extra function

•An extra function needs to be created somehow to store fixed values in a scope

•What a mess!

for (var i = 0; i < elements.length; i++) { (function(i, el) { el.addEventListener('click', function() {     doSomethingWith(i, el); }); })(i, elements[i]);}

Page 42: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Basic Remedy #2 – Use Framework support for

iteration

•Note that 2 functions are still needed

$.each(elements, function(i, el) { el.addEventListener('click', function() {     doSomethingWith(i, el); }); });

fluid.each(elements, function(el, i) { el.addEventListener('click', function() {     doSomethingWith(i, el); }); });

OR

Page 43: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Advanced Remedy #3 –

jQuery vectorisation

• jQuery.click() is one of a large family of portable event binding methods provided by jQuery (mousemove, keydown, focus, etc.)

• “A jQuery” wraps some collection of DOM elements

• A jQuery be used to treat the wrapped collection homogeneously

• Changes:

– We don’t get to use the index “i” any more

– Outer function level has disappeared, replaced by magic “this”

$(elements).click(function(event) {     doSomethingWith(event.target); }; );

Page 44: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Advanced Remedy #4 –

jQuery.delegate()

• Container is some DOM node containing the elements

• “elementSelector” is some selector (from the CSS dialect) matching the elements

• This is much more efficient, since it registers just ONE listener, no matter how many elements there are

• event.target will differ from “this” which remains the container, but holds the element which received the event

• Takes a bit more setting up, but is worthwhile in the long run

$(container).delegate(“elementSelector”, “click”, function(event) {     doSomethingWith(event.target); }; });

Page 45: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

that

Page 46: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Coping With Bugs• this can be confusing and unstable

• Constructor functions can accidentally clobber the global namespace

• Prototypal inheritance can easily cause existing code to break

• Can we simplify things?

Page 47: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Plain Old Functions & Objects

// Just use plain old functions and objects.function orange () { // Stable pointer to the current instance. var that = {}; // Anything private stays inside here.

// For public methods, just add properties. that.squeeze = function () {...}

return that;}

Page 48: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Writing Collision-Free JavaScript

•Put code in a unique namespace

•Use closures for privacy

•Support more than one on the page

– Scope all variables to an instance

– Avoid hard-baking ID selectors

•Constrain selectors within a specific element

These are policies followed by Fluid Infusion

Page 49: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keeping it to Ourselves

•You should take namespacing seriously

•Don’t steal global names

– JavaScript globals

– jQuery plugin names

– HTML id values

– others

•Components are carefully scoped

•Don’t expect control of the page

Page 50: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Start With a Unique

Namespace// Add on to the fluid object if it exists,// otherwise initialize it as an empty object.

var fluid = fluid || {};

Page 51: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Use Closures for Privacy

var fluid = fluid || {};(function() {

// Private stuff. function myPrivateFunction () {

}

// Add public stuff to your namespace.fluid.tabs = function () {

// Public creator function.};

})();

Page 52: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keep Common Aliases Private

Pass important dependencies in as an argument to the closure:

jQuery.noConflict(); // Tell jQuery to surrender $

(function ($) { // $ is now only visible in our private space.//$ === jQuery;

}) (jQuery);

//$ === undefined;

Page 53: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

JSON syntax

•Use of {} and [],

•Equivalence of assignment and JSON forms

•A curly bracket doesn’t just mean a block

Page 54: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

JavaScript pitfalls

•Corrupting Object.prototype and Array.prototype (or any prototypes for that matter)

•Writing for (var x in v) for an array

•Asynchrony in AJAX (Talk about promises) and jQuery.when() – single-threaded!

Page 55: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What is in jQuery?

Browser-independence for:

•Querying $(“a.myLinkClass”)

•Attaching events

$(“a.myLinkClass”).click(myHandler)

•Manipulating markup

$(“div.myDivClass”).append(“<a href=‘#’></a>”);

•Making AJAX requests $.post(“ajax/test.html”, myPostHandler);

Page 56: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery and jQuery UI

•jQuery: Foundational Library

– version 1.6.1

•jQuery UI: Library of plugins and widgets for jQuery

– Datepicker, Accordion, Slider, Tabs

– version 1.8.3

Page 57: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

finding something without a framework

function stripeListElements(listID) {// get the items from the listvar myItems = getElementsByTagName("li");// skip line 0 as it's the header row for(var i = 0; i < myItems.length; i++) {

if ((count % 2) === 0) {myItems[count].className = "odd";

}}

}

Page 58: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

var myItems = jQuery('li');

finding something with jQueryfinding something with jQuery

Page 59: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery("<selector>")

selectors :tags: jQuery("tr")

ids: jQuery("#myId")

classes: jQuery(".myClass")

pseudo tags: jQuery("div:first")

jQuery("<selector>")

selectors :tags: jQuery("tr")

ids: jQuery("#myId")

classes: jQuery(".myClass")

pseudo tags: jQuery("div:first")

finding something with jQueryfinding something with jQuery

} These forms as supported in CSS

Page 60: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery("<selector>")

more selectors = combining selectorselement by class: jQuery("li.selected");

relationships: jQuery("tbody tr:even");

children: jQuery("div > p");

siblings: jQuery("div ~ p");

etc, etc, etc...

jQuery("<selector>")

more selectors = combining selectorselement by class: jQuery("li.selected");

relationships: jQuery("tbody tr:even");

children: jQuery("div > p");

siblings: jQuery("div ~ p");

etc, etc, etc...

finding something with jQueryfinding something with jQuery

Page 61: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery("li");

doing something with jQuerydoing something with jQuery

Page 62: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery("li:even");

doing something with jQuerydoing something with jQuery

Page 63: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery("li:even").addClass("odd");

doing something with jQuerydoing something with jQuery

Page 64: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

function stripeListElements(listId) {jQuery('#' + listId + "

li:even").addClass("odd");}

$(“li:even”, fluid.byId(listId)).addClass(“odd”)

doing something with jQuery

Page 65: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery === $

Page 66: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

$(".some-hidden-thing").show();

$(".some-hidden-thing").fadeIn("slow");

$("<li>A new list item</li>").appendTo("#myList");

$("#myList li:last").replaceWith("<li>A new list item</li>");

$("div.container").clone().appendTo("body");

$(".some-hidden-thing").show();

$(".some-hidden-thing").fadeIn("slow");

$("<li>A new list item</li>").appendTo("#myList");

$("#myList li:last").replaceWith("<li>A new list item</li>");

$("div.container").clone().appendTo("body");

doing something with jQuery

Page 67: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

$("div.container").clone().appendTo("body");

chaining...

$("div#mytemplate").addClass('menu').clone().appendTo("body").click(dosomething());

$("div.container").clone().appendTo("body");

chaining...

$("div#mytemplate").addClass('menu').clone().appendTo("body").click(dosomething());

doing something with jQuery

Page 68: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

$(".button").click(function(){doSomething();

});

$(".button").hover(function(){jQuery(this).addClass("hilite");

}, function(){jQuery(this).removeClass("hilite");

});

$(".button").focus(function(){jQuery(this).addClass("hilite");

});

$(".button").blur(function(){jQuery(this).addClass("hilite");

});

$(".button").click(function(){doSomething();

});

$(".button").hover(function(){jQuery(this).addClass("hilite");

}, function(){jQuery(this).removeClass("hilite");

});

$(".button").focus(function(){jQuery(this).addClass("hilite");

});

$(".button").blur(function(){jQuery(this).addClass("hilite");

});

Attaching events

}In real life, do these 3using CSS:It’s more performant,and more reliable

Page 69: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

$(".button").click();$(".button").click();

Doing things with jQuery

Page 70: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

jQuery AJAX•Various short forms for special

cases

– $.get(), $.post(), $.load()

•Long form allows any function in HTTP

– $.ajax()

Page 71: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

All I/O is Asynchronous

•JavaScript’s function-oriented design makes it easy to supply callbacks

•Note, however, that browser JavaScript is single-threaded, even if multiple requests may be “in flight”

$.post('ajax/test.html', function(data) { $('.result').html(data);});

Page 72: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

API wrinkles•Historically, short-form jQuery

AJAX didn’t supply a position for error() callbacks

– Essential in a robust application

•However, as of 1.5, jQuery AJAX API supports Promises (interesting topic)

var jqxhr = $.post("example.php", function() { console.log("success"); }).error(function() { console.log(“POST failed”);});

Page 73: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Loading markup•A useful shorthand API is jQuery.load()

•Example from the docs:

• In practice, don’t use id-based selectors like this!

– Violates portal-friendliness

$('#result').load(“ajax/test.html #container”, myCallback);

Put the markupin here From this URL

Select just this partof the remote document

Call this functionwhen completed

Page 74: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Over to Clayton

Page 75: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What is Accessibility?

Page 76: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Definitions•Accessibility is the ability of the

system to accommodate the needs of the user

•Disability is the mismatch between the user and the interface provided

•We all experience disability

•Accessible software = better software

Page 77: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Motivations for Accessibility

•Legislative (ADA and Section 508)

•Business and outreach (reach everyone)

•Accessible is better (for everyone)

Page 78: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

It’s just better•“curb cut effect” -- everyone benefits

•accessible technology tends to be

– more interoperable

– easier to re-purpose

– more future-proof

– more robust

– easier to use on a variety of devices

Page 79: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Models for Web Accessibility

•Text-only site

•One site, accessible for all

•Adaptable and Personalizable

Discuss

Page 80: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Models for Web Accessibility

•Text-only site-- really?

•One site, accessible for all --better

•Adaptable and Personalizable --best

Page 81: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

W3C: Web Content Accessibility Guidelines (WCAG) 2.0

Page 82: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

• Principle 1: Perceivable - Information and user interface components must be presentable to users in ways they can perceive.

• Principle 2: Operable - User interface components and navigation must be operable.

• Principle 3: Understandable - Information and the operation of user interface must be understandable.

• Principle 4: Robust - Content must be robust enough that it can be interpreted reliably by a wide variety of user agents, including assistive technologies.

Page 83: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

WCAG is Good Design

Page 84: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Perceivable•Text alternatives for:

– Images

– Time-based media

– CAPTCHAs

•Adaptable presentation

•Use colour and contrast effectively

•Organize content in a meaningful sequence

Searchable, readable, faster

Page 85: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Operable

•Content needs to work with the keyboard

•Provide enough time to read and use

•Help users to navigate, find content, and locate themselves in your siteEasier to use and interact

with

Page 86: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Understandable

•Use plain language

•Define jargon and abbreviations

•Consistent and predictable user interfaces

•Help users avoid mistakesSpeaks to users on their terms; less frustrating UX

Page 87: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Robust

•Use valid markup and standards

•Describe the names, roles, and values of all user interface controls

Sites last longer, and are easier to repurpose

Page 88: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Better UsabilityDesigning for everyone

•Look at what an interaction is like for various users and contexts and then (re)envision how it could be

•start with interactions, not technology

•iterative testing

•have a wide-open community

Page 89: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Designing for Everyone

•Accessibility is no longer optional

•Visual design is no longer optional

•Accessibility cannot be absolutely measured

•Accessibility is a continuum

•Accessibility and Design have the same GOAL

http://webaim.org/blog/access_vs_design/

Page 90: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Taking a Look at Accessibility

Page 91: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Testing and Checking

•Fluid UX Walkthroughs

•Evaluators: AChecker, WAVE, and more

•General principles:

•Flexibility

•Labelling

•Alternatives

Page 92: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Step in the shoes of your users...

• Fluid UX Walkthroughs

• Easy ways to assess usability and accessibility

• Combination heuristic evaluation and cognitive walkthrough

• Translated: a checklist with scenarios

• Anyone can do onehttp://wiki.fluidproject.org/display/fluid/User+Experience+Walkthroughs

Page 93: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Simple Accessibility Evaluation

1. Try changing your font size, window size and resolution

2. Look critically at your page’s layout, structure & content

3. Use the Tab key to navigate through all controls

4. Check for alternatives to images, sound, and video

Page 94: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Screen Enlargement

1. Is all the text visible?

2. Does it overlap or break up in any way?

3. Are headers and labels still correctly associated?

4. Do columns shift or realign unexpectedly?

When you make things bigger or resize...

Page 95: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Layout and Structure

• Is the page structured into logical sections?

• Are the sections clearly labeled?

• Are there sufficient non-visual cues for site structure?

• Are there sufficient visual cues?

• Is the most important information prominent?

• Is navigation consistent from page to page?

Page 96: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation

• Many different types of users use the keyboard

• You probably do, too!

• Keyboard access is one-dimensional: forward & back

• Aim: Everything that works with the mouse, works with the keyboard

Page 97: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation Conventions

Page 98: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation Conventions

1. The Tab key moves focus to the next control

Page 99: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation Conventions

1. The Tab key moves focus to the next control

2. Shift-Tab moves focus backwards

Page 100: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation Conventions

1. The Tab key moves focus to the next control

2. Shift-Tab moves focus backwards

3. The Enter and Spacebar keys activate a control

Page 101: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation Checklist

1. Do all links, buttons, and form controls receive focus?

2. Can all controls be activated with Enter or Spacebar?

3. Are there any areas you get stuck or need the mouse?

4. Do calendar pickers and other rich widgets work?

Page 102: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What About Shortcuts?

• Accessibility guidelines use to suggest “access keys”

• Keyboard shortcuts bound to the alt key

• A huge source of controversy

• Bottom line: don’t add new keyboard shortcuts

Page 103: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Alternatives to Media

1. Do all images have meaningful, non-redundant alt text?

2. Do videos have captions? (They’re easy to add!)

3. Does audio have a transcript?

Hover your mouse over images in Internet Explorer to see alt text...

Page 104: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Tools for Evaluating Accessibility

Page 105: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Evaluation Tools

1.Static Analyzers

2.HTML and CSS

3.Accessibility

Page 106: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

HTML & CSS Validation• Validators ensure that HTML and CSS are

to spec

• Passing doesn’t mean you’re accessible, but it’s a start

• HTML

• http://validator.w3.org/

• http://jigsaw.w3.org/css-validator/

Page 107: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility Checkers

aChecker

http://achecker.ca/checker/index.php

Wave

http://jigsaw.w3.org/css-validator/

Page 108: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility Checkers

aChecker

http://achecker.ca/checker/index.php

Page 109: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility CheckersWave

http://jigsaw.w3.org/css-validator/

Page 110: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility Checkers:What They Do

• Statically analyze markup

• Specify the Guideline for Validation

• e.g. WCAG 2.0 AA

• Will alert you to in accessible markup

• e.g. missing alt text on images

Page 111: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility Checkers:Limitations

• No Magic

• Is the alt text meaningful?

• Static analysis

• Will javascript make it inaccessible?

• Markup based validation

• How will CSS affect the page?

Page 112: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Colour Validation

• View in respect to Colour Blindness

• Determine Adjustability of Colours

http://colorfilter.wickline.org

http://vischeck.com

Page 113: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Colour ValidationLimitations

• Automating testing of interfaces is hard

• e.g. determining contrast levels

Is this contrast level to spec?

Page 114: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Design Color Scheme Early

Easier and cheaper to make good design

choices early

http://gmazzocato.altervista.org/colorwheel/wheel.php

http://www.snook.ca/technical/colour_contrast/colour.html

Colour Pickers that also measure contrast

Page 115: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessible Markup

Page 116: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Concepts of HTML Accessibility

•Label as much as you can

•Use semantic markup to describe your page

•Design in layers

•Textual alternatives

•Clearly delineate navigation from content

Page 117: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

what is “alt” text?• It is read by screen readers in place of images

allowing the content and function of the image to be accessible to those with visual or certain cognitive disabilities.

• It is displayed in place of the image in user agents (browsers) that don't support the display of images or when the user has chosen not to view images.

• It provides a semantic meaning and description to images which can be read by search engines or be used to later determine the content of the image from page context alone.

http://www.webaim.org/techniques/alttext/

Page 118: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

The “alt” attribute•Be accurate and equivalent in presenting the same content and function as presented by the image.

•Be succinct. Typically no more than a few words are necessary.

•do NOT be redundant or provide the exact same information as text within the context.

•do NOT use the phrases "image of ..." or "graphic of ..." to describe the image. It usually apparent to the user that it is an image.

http://www.webaim.org/techniques/alttext/

Page 119: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

“alt” text in code

<img src="boat.gif" alt="Big Boat" />

Page 120: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

VideoYouTube

Page 121: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

CaptioningYouTube and beyond

•Captions are great for everyone

•They make your videos search-friendly

•YouTube Automatic Captioning

•Speech recognition: pretty awkward

•Supply a transcript: quick and reliable

•Flash has accessibility problems, but HTML 5 is coming

Page 122: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Video (Cont.)HTML 5

Page 123: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Avoiding Repetition

Page 124: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Avoiding Repetition

Navigation Bar

Page 125: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Avoiding Repetition

Navigation Bar

Main Content

Page 126: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Avoid Repetition

<div id="jumplinks"> <a href="#content" title="Jump to content"></a> <a href="#nav" title="Jump to navigation menu"></a></div>

<a id="nav" title="navigation menu"></a><!-- Navigation bar goes here --><a title="content area" name="content"></a><!-- Main page content goes here -->

Skip Links

Navigation Bar

Main Content

Page 127: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Designing Navigation

•Keep in mind that keyboard navigation is:

•not just for screen reader users

•is linear and one-dimensional

•can be slow and tedious

•Skip links should be available and visible to all

•Place them as high in the page as possible

Page 128: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

Page 129: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

Level One

Page 130: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

Level One

Level Two

Page 131: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

Level One

Level Two

Level Three Level Three

Level Three

Level Three

Page 132: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Level One

Level Two

Level Three Level Three

Level Three

Level Three

Navigable Headings

Level Four

Page 133: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

<H1>

<H2>

<H3>

<H4>

<H3>

<H3>

<H3>

Page 134: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigating Headings

Page 135: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Navigable Headings

<body> <h1>Fluid: Designing Software that works - For everyone.</h1>    <h2>Fluid Daily Build Resources</h2>      <div>        <div class="fl-col">          <h3>Fluid Integration Examples</h3>            <h4>uPortal Instance</h4>            <-- Content goes here --> <h4>Sakai Mock-up</h4>          </div>          <div class="fl-col">        <h3>Infrastructure</h3>            ...

Page 136: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Labelling Forms

Page 137: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Labelling Forms

Label

Page 138: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Labelling Forms

Label for

Page 139: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Labelling Forms

<li> <label for="text-font">Font style:</label> <select id="text-font" name="text-font-selection"> <option value="serif">Serif</option> <option value="sansSerif">Sans-Serif</option> <option value="arial">Arial</option> <option value="verdana">Verdana</option> <option value="courier">Courier</option> <option value="times">Times</option> </select><li>

Label for

Page 140: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Grouping Forms

Field Set

Page 141: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Grouping Forms

Legend

Page 142: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Grouping Forms

Field Set

<fieldset>  <legend>Background Images</legend> <span>  <input type="radio" value="true" checked="checked" name="background-images-selection" id="background-yes">    <label for="background-yes">Yes</label>  </span> <span>  <input type="radio" value="false" name="background-images-selection" id="background-no">    <label for="background-no">No</label>    </span></fieldset>

Page 143: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

These Features Aid Screen Reader

Users

Page 144: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Tables

•Tables got a really bad rap in the ‘90s

•Deservedly so

•Use them for data, not layouts

•They can be big: summarize them

•Seriously, you don’t need them for layouts

Page 145: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Table Structure

Header

Body

Page 146: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Table Structure

<table summary="An editable table of student grades and instructor comments."> <thead>  <tr>    <th>Name</th>      <th abbr="I.D.”>User ID</th>      <th>Points</th>      <td>Comments</th>    </tr>  </thead>  <tbody>  <tr>    <td>Ahn, Jason</td>      <td>15234314</td>      <td><input type="text" name="points" value="87"></td>      <td>Lorem ipsum dolor sit amet.</td>    </tr> </tbody></table>

Header

Body

Page 147: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Break: 9:55

Page 148: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Web 2.0 Accessibility

Page 149: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What is Accessibility?

Page 150: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

A New Definition•Accessibility is the ability of the

system to accommodate the needs of the user

•Disability is the mismatch between the user and the interface provided

•We all experience disability

•Accessible software = better software

Page 151: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Assistive Technologies•Present and control the user

interface in different ways

•Not just screen readers!

•Use built-in operating system APIs to understand the user interface

Screen readersScreen magnifiers

On-screen keyboards

Page 152: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

DHTML: A New Can of Worms

•Shift from documents to applications

•Familiar a11y techniques aren’t enough

•Most DHTML is completely inaccessible

•New techniques are still being figured out

Page 153: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

The Problem•Custom widgets often look, but

don’t act, like their counterparts on the desktop

•HTML provides only simple semantics

•Not enough information for ATs

•Dynamic updates require new design strategies to be accessible

Page 154: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

The Solution

•Describe user interfaces with ARIA

•Add consistent keyboard controls

•Provide flexible styling and presentation

Page 155: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Supporting Assistive Technology

Page 156: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Opaque Markup// These are tabs. How would you know?<ol>

<li><a href=”#cats”>Cats</a></li> <li><a href=”#dogs”>Dogs</a></li> <li><a href=”#gators”>Gators</a></li>

</ol><div>

<div id=”cats”>Cats meow.</div> <div id=”dogs”>Dogs bark.</div> <div id=”gators”>Gators bite.</div>

</div>

Page 157: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Opaque Markup: Tabs

Page 158: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

ARIA

•Accessible Rich Internet Applications

•W3C specification in the works

•Fills the semantic gaps in HTML

•Roles, states, and properties

•Live regions

Page 159: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Roles, States, Properties

•Roles describe widgets not present in HTML 4

•slider, menubar, tab, dialog

•Properties describe characteristics:

– draggable, hasPopup, required

•States describe what’s happening:

– busy, disabled, selected, hidden

Page 160: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Using ARIA// Now *these* are Tabs!<ol id=”animalTabs” role=”tablist” tabindex=”0”>

<!-- Individual Tabs shouldn’t be focusable --> <!-- We’ll focus them with JavaScript instead -->

<li role=”tab”><a href=”#” tabindex=”-1”>Cats</a></li>

<li role=”tab”><a href=”#” tabindex=”-1”>Dogs</a></li>

<li role=”tab”><a href=”#” tabindex=”-1”>Gators</a></li>

</ol><div id=”panels”>

<div role=”tabpanel” aria-labelledby=”cats”>Cats meow.</div>

<div role=”tabpanel” aria-labelledby=”dogs”>Dogs bark.</div>

<div role=”tabpanel” aria-labelledby=”gators”>Gators bite.</div>

</div>

Page 161: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Adding ARIA in Code

// Identify the container as a list of tabs.tabContainer.attr("role", "tablist"); // Give each tab the "tab" role.tabs.attr("role", "tab"); // Give each panel the appropriate role, panels.attr("role", "tabpanel");panels.each(function (idx, panel) { var tabForPanel = that.tabs.eq(idx); // Relate the panel to the tab that labels it. $(panel).attr("aria-labelledby", tabForPanel[0].id);});

Page 162: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Accessibility

Page 163: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Navigation

•Everything that works with the mouse should work with the keyboard

•... but not always in the same way

•Support familiar conventionshttp://dev.aol.com/dhtml_style_guide

Page 164: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard Conventions

•Tab key focuses the control or widget

•Arrow keys select an item

•Enter or Spacebar activate an item

•Tab is handled by the browser. For the rest, you need to write code. A lot of code.

Page 165: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Keyboard a11y: Tabs

Page 166: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Tabindex examples<!-- Tab container should be focusable --><ol id=”animalTabs” tabindex=”0”>

<!-- Individual Tabs shouldn’t be focusable --> <!-- We’ll focus them with JavaScript instead -->

<li id=”tab1”> <a href=”#cats” tabindex=”-1”>Cats</a> </li> <li id=”tab2”> <a href=”#cats” tabindex=”-1”>Dogs</a> </li> <li id=”tab3”> <a href=”#cats” tabindex=”-1”>Alligators</a> </li>

</ol>

Page 167: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Making Things Tabbable

// Make the tablist accessible with the Tab key.tabContainer.attr("tabindex", "0");// And take the anchors out of the Tab order.$(“a”, tabs).attr("tabindex", "-1");

•Tabindex varies subtly across browsers

•jWuery.attr() normalizes it as of 1.3

• Should be jQuery.prop() as of 1.6

•For all the gory details:http://fluidproject.org/blog/2008/01/09/g

etting-setting-and-removing-tabindex-values-with-javascript/

Page 168: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Adding the Arrow Keys

// Make each tab accessible with the left and right arrow keys.tabContainer.fluid("selectable", { selectableSelector: that.options.selectors.tabs, direction: fluid.a11y.orientation.HORIZONTAL, onSelect: function (tab) { $(tab).addClass(that.options.styles.highlighted); }, onUnselect: function (tab) { $(tab).removeClass(that.options.styles.highlighted); }});

Page 169: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Making Them Activatable

// Make each tab activatable with Spacebar and Enter.

tabs.fluid("activatable", function (evt) { // Your handler code here. Maybe the same as

.click()?});

Page 170: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Documentation

Tutorial:http://wiki.fluidproject.org/display/fluid/Keyboard+Accessibility+Tutorial

API Reference:http://wiki.fluidproject.org/display/fluid/Keyboard+Accessibility+Plugin+API

Page 171: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Accessibility Resources

http://codetalks.orghttp://wiki.fluidproject.org/display/fluid/DHTML+Developer+Checklisthttp://wiki.fluidproject.org/display/fluid/UX+Accessibility+Walkthrough+Protocolshttp://developer.mozilla.org/en/docs/Accessible_DHTMLhttp://developer.mozilla.org/en/docs/Key-navigable_custom_DHTML_widgetshttp://developer.mozilla.org/en/docs/AJAX:WAI_ARIA_Live_Regions

Page 172: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Tying it All Together

•Infusion helps you with accessibility

•Components you can really work with

•Simple structure so your code can grow

•Totally transparent, event-driven design

•Markup and models are under your control

•No inheritance or controller cruft

Page 173: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

An Open Source Community for Inclusive Design

Fluid is much more than a software project. Fluid is culture change, best practices, a way to approach design, development, and the power therein.

Page 174: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Fluid...

•Is an open source community of

– Designers

– Developers

– Accessibility experts

•Helps other open communities

•Consists of universities, museums and individuals

http://fluidproject.org

Page 175: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What We Do•Code (examples, tools, best-

practices)

•Design (advice, tools)

•Expertise & Resources

•Teaching & Evangelism

•Help

Page 176: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Tangibles•core product: framework,

code, components

•project with museums: visitor experience

•project with museums: collections management

Page 177: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

http://fluidproject.org/products/infusion/

Page 178: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Meet Infusion

•Application framework built on top of jQuery

•The culmination of our work helping others

•Designed for usability and accessibility

•Open architecture: everything is configurable

Page 179: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

What’s in Infusion?

•A development framework for building apps

•UI components you can reuse and adapt

•Lightweight CSS framework for styling

•Accessibility tools and plugins for jQuery

Page 180: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

a11y: Infusion Goes Deeper

•jQuery Keyboard Navigation Plugin

•ARIA everywhere

•Everything is highly adaptable and flexible

•UI Options and the Fluid Skinning System:

– Users can customize their environment

Page 181: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Building Great UIs Is Hard

•Your code gets unruly as it grows

•UIs are hard to reuse or repurpose

•Design change requires big code change

•Accessibility is confusing

•Combining different code/libraries doesn’t always work

Page 182: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Flexible User Interfaces

•Infusion is an application framework designed to provide unprecedented flexibility while preserving interoperability.

Page 183: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Types of JavaScript Tools

•Foundational Toolkits

•Widget libraries

•Application Frameworks... compare and contrast

Page 184: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Foundational toolkits

•Totally presentation focused

•DOM manipulation

•Event binding

•AjaxjQuery

Prototype

Dojo core

Page 185: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Widget Libraries

•Reusable user interface widgets

– Drag & Drop

– Tabs

– Sliders

– Accordions

jQuery UI

Ext

Scriptaculous

Page 186: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Application frameworks

•Model notifications “something changed here”

•Views to help keep your presentational code clean

•Data binding to sync the display with your model

SproutCore

Dojo/Dijit/Dojox

Cappuccino

Page 187: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

The Reorderer Family

layouts grids lists

Page 188: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Uploader

Page 189: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Pager

Page 190: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

UI Options•One size doesn’t fit all

•Allows users to customize your app:

– layout

– styling

– navigation

•Uses FSS by default; can be configured to work with your own classes

Page 191: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Let end-users transform the content they see according to their own preferences and needs.

Page 192: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

UI Options

Page 193: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

UI Options: High Contrast Theme

Page 194: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Infusion is Different•Accessibility baked right in

•Carefully designed interactions

•Markup is in your control

•Not the same old MVC

•Supports portals, mashups and CMS’s

Page 195: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

CSS Frameworks“If you’re going to use a framework, it should be yours; one that you’ve created. You can look at existing frameworks for ideas and hack at it. But the professionals in this room are not well served by picking up a framework and using it as-is.”

- Eric Meyer

Page 196: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Fluid Skinning System

•FSS is built to be hacked on

•Provides a core set of building blocks

•Reset, text, layouts, themes

•Namespaced: no conflicts with your stuff

•Themes for better legibility & readability

http://wiki.fluidproject.org/x/96M7

Page 197: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Links to get started

•http://www.alistapart.com

•http://webaim.org

•http://wiki.fluidproject.org/display/fluid/Design+Handbook

Page 198: Building Accessible User Interfaces with JavaScript and jQuery Antranig Basman, Core Framework Architect, The Fluid Project Clayton Lewis, Professor of.

Questions?