13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

246<br />

Accessibility and JavaScript<br />

For years, both accessibility and JavaScript have been the<br />

realm of the expert who is well-versed in a niche subject<br />

area. Work in this area has been hindered by the longstanding<br />

myth that has been handed down from<br />

generation to generation of web developers. This myth is<br />

very simply stated: To make sure that your web page is<br />

accessible, it must work with JavaScript on or off.<br />

This misconception is in large part due to WCAG<br />

checkpoint 6.3 (www.w3.org/TR/WCAG10/wai-pageauth.<br />

html#tech-scripts), which states:<br />

Ensure that pages are usable when scripts,<br />

applets, or other programmatic objects are<br />

turned off or not supported. If this is not possible,<br />

provide equivalent information on an<br />

alternative accessible page.<br />

In 1999, when WCAG 1.0 was published, this was a reasonable<br />

guideline. Screen readers and browsers were not<br />

nearly as advanced as they are today. It was widely<br />

accepted (and propagated) that screen readers just didn’t<br />

understand JavaScript. The on/off scenario used to be<br />

reasonably accurate.<br />

Today’s screen readers do understand much of the<br />

JavaScript that is supported in today’s browsers, yet many<br />

people are still holding on to the idea that this isn’t possible.<br />

They cling to the assumption necessary for WCAG<br />

checkpoint 6.3: accessibility and scripting as a binary<br />

on/off scenario.<br />

Enter the modern era of web accessibility and assistive<br />

technology. Yes, some people with disabilities may use<br />

browsers that can’t handle scripting, or even turn off<br />

JavaScript, but the majority of the population is likely to<br />

be using a regular browser with scripting support. It is no<br />

longer a black and white matter. Ensuring that a page<br />

works with scripting on or off is more about<br />

interoperability—providing at least basic functionality in<br />

either state—than it is about accessibility.<br />

So the trick to creating accessible JavaScript is not solely<br />

about ensuring that our solutions work with JavaScript on<br />

or off. We must also make sure that our solutions are<br />

compatible with users of varying abilities and with assistive<br />

technologies. Keep this in mind as we progress<br />

through the rest of the chapter.<br />

The accessible solution<br />

We know from our experience that basic accessibility for<br />

people with disabilities and basic interoperability with different<br />

devices are provided by a standards-based<br />

approach to web development: structural HTML, CSS for<br />

presentation, and a final layer of JavaScript on top to provide<br />

behavior. This approach will be used in this chapter’s<br />

example to ensure that we’ve covered the basics. We’ll<br />

use semantic HTML, design with CSS, and deliver a solution<br />

that works with both JavaScript on or off. Once we<br />

have done that, we’ll add some more scripting to make<br />

sure that the system works well for people using a variety<br />

of assistive technologies.<br />

Before we start getting into code, let’s take a look at a<br />

brief overview of the solution as well as the files that<br />

make it all happen (these are available for download from<br />

this book's page on www.friendsofed.com):<br />

Base HTML file, wscslide.html<br />

Style sheet, wscslide.css<br />

JavaScript functions, wscslide.js<br />

Figure 10-2 shows a simple wireframe of the effect we are<br />

trying to achieve with our sliding navigation. The initial<br />

position for the navigational panes when the page loads<br />

and before any JavaScript has taken effect is at the bottom<br />

after the content. Once the main navigational link<br />

for Recent Posts has been activated, we use some basic<br />

JavaScript to change the CSS that is applied to the navigational<br />

pane to visually place it just below the navigation.<br />

Once we have achieved that, we’ll use some additional<br />

JavaScript to set the height of that pane to 0, and then<br />

create a sliding effect by changing that height one step at<br />

a time, returning the height to its original value. For<br />

example, if the original height of the Recent Posts pane is<br />

180px, we’ll set the height to 0, and then change it to<br />

90px, then 135px, then 158px, and so on, until the height<br />

is back to its original size of 180px.<br />

In the finished solution, the initial state for the navigational<br />

panes will appear as shown in Figure 10-3.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!