13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We could incorporate the JavaScript to do this in many ways. In order to maintain our solid HTML base, we use JavaScript<br />

that intercepts, or “hijacks,” the click on the navigational items and toggles the state of the navigational panes. It employs a<br />

function called toggle, which switches between an exposed navigational pane and its original state. It would be best to<br />

assign these dynamically to each of the navigational items, but for the sake of clarity, this ultimately results in the following<br />

for our navigational links:<br />

<br />

Recent Posts<br />

<br />

Here is a quick look at the first version of the toggle function from wscslide.js:<br />

function toggle(element) {<br />

var inner = document.getElementById('inner-wrap');<br />

/* if the scripting isn't supported, we want to return true so that<br />

default behavior of clicking the link works (i.e., take the user<br />

to the bottom part of the page)<br />

*/<br />

if (!document.getElementById) return true;<br />

var elt = document.getElementById(element);<br />

// do a test on the className property on the element to<br />

// check for the exposed class<br />

if (/exposed/i.test(elt.className)) {<br />

// exposed state was found, so remove it<br />

elt.className = elt.className.replace(/exposed/g,'');<br />

} else {<br />

// add exposed to current class to respect any<br />

// styles/classes that already exist<br />

elt.className += " exposed";<br />

}<br />

return false;<br />

}<br />

In this case, the core functionality is provided by the hrefs. Ensuring that they are in place means that we achieve<br />

a base level of interoperability with scripting either on or off. Don’t confuse this with accessibility for people with<br />

disabilities. We’ll address accessibility later after we’ve taken care of the basic interoperability needs.<br />

The critical component of this script is that we’re using scripting to take over for the functionality provided by the<br />

links in the HTML. This ensures that a person using a browser without scripting support will be<br />

taken to the correct part of the page.<br />

This serves as the base for the rest of the scripting. With this main toggle in place, we can add in our sliding behaviors.<br />

chapter 10 Accessible Sliding Navigation<br />

251

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

Saved successfully!

Ooh no, something went wrong!