|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<title>YUI Library Examples: Focus Manager Node Plugin: Accessible TabView</title> |
|
|
6 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
7 |
<link rel="stylesheet" type="text/css" href="../../assets/yui.css" > |
|
|
8 |
|
|
|
9 |
<style> |
|
|
10 |
/*Supplemental CSS for the YUI distribution*/ |
|
|
11 |
#custom-doc { width: 95%; min-width: 950px; } |
|
|
12 |
#pagetitle {background-image: url(../../assets/bg_hd.gif);} |
|
|
13 |
/* #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/ |
|
|
14 |
</style> |
|
|
15 |
|
|
|
16 |
<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css"> |
|
|
17 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
18 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
19 |
<style type="text/css"> |
|
|
20 |
|
|
|
21 |
/* The following style rules necessary to override style rules in the |
|
|
22 |
YUI CSS file. */ |
|
|
23 |
|
|
|
24 |
#example ul, |
|
|
25 |
#example li { |
|
|
26 |
list-style: none; |
|
|
27 |
list-style: none; |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
#example em { |
|
|
31 |
font-style: normal; |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
#example .yui-tabpanel { |
|
|
35 |
|
|
|
36 |
/* Use the "zoom" property to set the the hasLayout property to true. |
|
|
37 |
This ensures that the background color of the tab's panel will |
|
|
38 |
be rendered correctly when the example is running in the |
|
|
39 |
example chrome. |
|
|
40 |
*/ |
|
|
41 |
|
|
|
42 |
_zoom: 1; |
|
|
43 |
|
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
#example .yui-tabpanel a { |
|
|
47 |
text-decoration: underline; |
|
|
48 |
color: blue; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
#example h3 { |
|
|
52 |
color: #000; |
|
|
53 |
font-size: 100%; |
|
|
54 |
font-weight: bold; |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
#example .yui-tabview { |
|
|
58 |
margin: 0 .25em; |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
|
|
|
62 |
/* Hide the instructional text used to label the tabview offscreen. |
|
|
63 |
This ensures it is still available to users of screen readers, but is |
|
|
64 |
not visible to sighted users. */ |
|
|
65 |
|
|
|
66 |
#tabview-heading em { |
|
|
67 |
position: absolute; |
|
|
68 |
left: -999em; |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
/* Hide the list while it is being transformed into a tabview. */ |
|
|
73 |
|
|
|
74 |
.yui-loading #tabview-1 { |
|
|
75 |
display: none; |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
</style> |
|
|
79 |
<script type="text/javascript"> |
|
|
80 |
|
|
|
81 |
// Add a class to the documentElement to prevent the user from seeing |
|
|
82 |
// the unstyled menu while the necessary CSS and JavaScript |
|
|
83 |
// dependancies are being fetched. |
|
|
84 |
|
|
|
85 |
document.documentElement.className = "yui-loading"; |
|
|
86 |
|
|
|
87 |
</script> |
|
|
88 |
</head> |
|
|
89 |
<body id="yahoo-com" class=" yui-skin-sam"> |
|
|
90 |
<div id="custom-doc" class="yui-t2"> |
|
|
91 |
<div id="hd"> |
|
|
92 |
<div id="ygunav"> |
|
|
93 |
<p> |
|
|
94 |
<em> |
|
|
95 |
<a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i> |
|
|
96 |
</em> |
|
|
97 |
</p> |
|
|
98 |
<form action="http://search.yahoo.com/search" id="sitesearchform"> |
|
|
99 |
<input name="vs" type="hidden" value="developer.yahoo.com"> |
|
|
100 |
<input name="vs" type="hidden" value="yuiblog.com"> |
|
|
101 |
<div id="sitesearch"> |
|
|
102 |
<label for="searchinput">Site Search (YDN & YUIBlog): </label> |
|
|
103 |
<input type="text" id="searchinput" name="p"> |
|
|
104 |
<input type="submit" value="Search" id="searchsubmit" class="ygbt"> |
|
|
105 |
</div> |
|
|
106 |
</form> |
|
|
107 |
</div> |
|
|
108 |
<div id="ygma"><a href="../../"><img src="../../assets/logo.gif" border="0" width="200" height="93"></a></div> |
|
|
109 |
<div id="pagetitle"><h1>YUI Library Examples: Focus Manager Node Plugin: Accessible TabView</h1></div> |
|
|
110 |
</div> |
|
|
111 |
<div id="bd"> |
|
|
112 |
|
|
|
113 |
<div id="bar-note"><p><strong>Note:</strong> This is YUI 3.x. Looking for <a href="http://developer.yahoo.com/yui/">YUI 2.x</a>?</p></div> |
|
|
114 |
|
|
|
115 |
<div id="yui-main"> |
|
|
116 |
<div class="yui-b"> |
|
|
117 |
<div class="yui-ge"> |
|
|
118 |
<div class="yui-u first example" id="main"> |
|
|
119 |
|
|
|
120 |
<h2>Focus Manager Node Plugin: Accessible TabView</h2> |
|
|
121 |
|
|
|
122 |
<div id="example" class="promo"> |
|
|
123 |
<p> |
|
|
124 |
<p> |
|
|
125 |
This example illustrates how to create an accessible tabview widget using the |
|
|
126 |
Focus Manager Node Plugin, |
|
|
127 |
<a href="../../api/YUI.html#event_delegate">Event's delegation support</a>, and |
|
|
128 |
Node's support for the |
|
|
129 |
<a href="http://www.w3.org/TR/wai-aria/">WAI-ARIA Roles and States</a>. |
|
|
130 |
</p> </p> |
|
|
131 |
|
|
|
132 |
<div class="module example-container "> |
|
|
133 |
<div class="hd exampleHd"> |
|
|
134 |
<p class="newWindowButton yui-skin-sam"> |
|
|
135 |
<a href="node-focusmanager-2_clean.html" target="_blank">View example in new window.</a> |
|
|
136 |
</p> |
|
|
137 |
</div> <div id="example-canvas" class="bd"> |
|
|
138 |
|
|
|
139 |
|
|
|
140 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
141 |
|
|
|
142 |
<h3 id="tabview-heading">Today's News</h3> |
|
|
143 |
<div id="tabview-1" class="yui-tabview"> |
|
|
144 |
<ul> |
|
|
145 |
<li class="yui-tab yui-tab-selected"><a href="#top-stories"><em>Top Stories</em></a></li> |
|
|
146 |
<li class="yui-tab"><a href="#world-news"><em>World</em></a></li> |
|
|
147 |
<li class="yui-tab"><a href="#entertainment-news"><em>Entertainment</em></a></li> |
|
|
148 |
<li class="yui-tab"><a href="#sports-news"><em>Sports</em></a></li> |
|
|
149 |
<li class="yui-tab"><a href="#technology-news"><em>Technology</em></a></li> |
|
|
150 |
</ul> |
|
|
151 |
<div> |
|
|
152 |
<div class="yui-tabpanel yui-tabpanel-selected" id="top-stories"> |
|
|
153 |
<h3>Top Stories</h3> |
|
|
154 |
|
|
|
155 |
</div> |
|
|
156 |
<div class="yui-tabpanel" id="world-news"> |
|
|
157 |
<h3>World News</h3> |
|
|
158 |
</div> |
|
|
159 |
<div class="yui-tabpanel" id="entertainment-news"> |
|
|
160 |
<h3>Entertainment News</h3> |
|
|
161 |
|
|
|
162 |
</div> |
|
|
163 |
<div class="yui-tabpanel" id="sports-news"> |
|
|
164 |
<h3>Sports News</h3> |
|
|
165 |
|
|
|
166 |
</div> |
|
|
167 |
<div class="yui-tabpanel" id="technology-news"> |
|
|
168 |
<h3>Technology News</h3> |
|
|
169 |
|
|
|
170 |
</div> |
|
|
171 |
</div> |
|
|
172 |
</div> |
|
|
173 |
|
|
|
174 |
<!-- YUI Seed --> |
|
|
175 |
<script type="text/javascript" src="../../build/yui/yui.js"></script> |
|
|
176 |
<script type="text/javascript"> |
|
|
177 |
|
|
|
178 |
YUI({ |
|
|
179 |
|
|
|
180 |
base: "../../build/", |
|
|
181 |
modules: { |
|
|
182 |
"tabview-css": { |
|
|
183 |
type: "css", |
|
|
184 |
fullpath: "assets/tabview.css" |
|
|
185 |
} |
|
|
186 |
}, |
|
|
187 |
timeout: 10000 |
|
|
188 |
|
|
|
189 |
}).use("tabview-css", "node-focusmanager", "node-event-simulate", function(Y) { |
|
|
190 |
|
|
|
191 |
|
|
|
192 |
var tabView = Y.Node.get("#tabview-1"), |
|
|
193 |
tabList = tabView.query("ul"), |
|
|
194 |
tabHeading = Y.Node.get("#tabview-heading"), |
|
|
195 |
sInstructionalText = tabHeading.get("innerHTML"); |
|
|
196 |
selectedTabAnchor = tabView.query(".yui-tab-selected>a"), |
|
|
197 |
bGeckoIEWin = ((Y.UA.gecko || Y.UA.ie) && navigator.userAgent.indexOf("Windows") > -1), |
|
|
198 |
panelMap = {}; |
|
|
199 |
|
|
|
200 |
|
|
|
201 |
// Remove the "yui-loading" class from the documentElement |
|
|
202 |
// now that the necessary YUI dependencies are loaded. |
|
|
203 |
|
|
|
204 |
tabView.get("ownerDocument").get("documentElement").removeClass("yui-loading"); |
|
|
205 |
|
|
|
206 |
|
|
|
207 |
// Apply the ARIA roles, states and properties. |
|
|
208 |
|
|
|
209 |
// Add some instructional text to the heading that will be read by |
|
|
210 |
// the screen reader when the first tab in the tabview is focused. |
|
|
211 |
|
|
|
212 |
tabHeading.set("innerHTML", (sInstructionalText + " <em>Press the enter key to load the content of each tab.</em>")); |
|
|
213 |
tabList.set("aria-labelledby", "tabview-heading"); |
|
|
214 |
|
|
|
215 |
tabList.set("role", "tablist"); |
|
|
216 |
tabView.query("div").set("role", "presentation"); |
|
|
217 |
|
|
|
218 |
|
|
|
219 |
tabView.plug(Y.Plugin.NodeFocusManager, { |
|
|
220 |
descendants: ".yui-tab>a", |
|
|
221 |
keys: { next: "down:39", // Right arrow |
|
|
222 |
previous: "down:37" }, // Left arrow |
|
|
223 |
focusClass: { |
|
|
224 |
className: "yui-tab-focus", |
|
|
225 |
fn: function (node) { |
|
|
226 |
return node.get("parentNode"); |
|
|
227 |
} |
|
|
228 |
}, |
|
|
229 |
circular: true |
|
|
230 |
}); |
|
|
231 |
|
|
|
232 |
|
|
|
233 |
// If the list of tabs loses focus, set the activeDescendant |
|
|
234 |
// attribute to the currently selected tab. |
|
|
235 |
|
|
|
236 |
tabView.focusManager.after("focusedChange", function (event) { |
|
|
237 |
|
|
|
238 |
if (!event.newVal) { // The list of tabs has lost focus |
|
|
239 |
this.set("activeDescendant", selectedTabAnchor); |
|
|
240 |
} |
|
|
241 |
|
|
|
242 |
}); |
|
|
243 |
|
|
|
244 |
|
|
|
245 |
tabView.queryAll(".yui-tab>a").each(function (anchor) { |
|
|
246 |
|
|
|
247 |
var sHref = anchor.getAttribute("href", 2), |
|
|
248 |
sPanelID = sHref.substring(1, sHref.length), |
|
|
249 |
panel; |
|
|
250 |
|
|
|
251 |
// Apply the ARIA roles, states and properties to each tab |
|
|
252 |
|
|
|
253 |
anchor.set("role", "tab"); |
|
|
254 |
anchor.get("parentNode").set("role", "presentation"); |
|
|
255 |
|
|
|
256 |
|
|
|
257 |
// Remove the "href" attribute from the anchor element to |
|
|
258 |
// prevent JAWS and NVDA from reading the value of the "href" |
|
|
259 |
// attribute when the anchor is focused |
|
|
260 |
|
|
|
261 |
if (bGeckoIEWin) { |
|
|
262 |
anchor.removeAttribute("href"); |
|
|
263 |
} |
|
|
264 |
|
|
|
265 |
// Cache a reference to id of the tab's corresponding panel |
|
|
266 |
// element so that it can be made visible when the tab |
|
|
267 |
// is clicked. |
|
|
268 |
panelMap[anchor.get("id")] = sPanelID; |
|
|
269 |
|
|
|
270 |
|
|
|
271 |
// Apply the ARIA roles, states and properties to each panel |
|
|
272 |
|
|
|
273 |
panel = Y.Node.get(("#" + sPanelID)); |
|
|
274 |
|
|
|
275 |
panel.setAttrs({ |
|
|
276 |
role: "tabpanel", |
|
|
277 |
"aria-labelledby": anchor.get("id") |
|
|
278 |
}); |
|
|
279 |
|
|
|
280 |
}); |
|
|
281 |
|
|
|
282 |
|
|
|
283 |
// Use the "delegate" custom event to listen for the "click" event |
|
|
284 |
// of each tab's <A> element. |
|
|
285 |
|
|
|
286 |
Y.on("delegate", function (event) { |
|
|
287 |
|
|
|
288 |
var selectedPanel, |
|
|
289 |
oTarget = event.currentTarget, |
|
|
290 |
sID = oTarget.get("id"); |
|
|
291 |
|
|
|
292 |
// Deselect the currently selected tab and hide its |
|
|
293 |
// corresponding panel. |
|
|
294 |
|
|
|
295 |
if (selectedTabAnchor) { |
|
|
296 |
selectedTabAnchor.get("parentNode").removeClass("yui-tab-selected"); |
|
|
297 |
Y.Node.get(("#" + panelMap[selectedTabAnchor.get("id")])).removeClass("yui-tabpanel-selected"); |
|
|
298 |
} |
|
|
299 |
|
|
|
300 |
selectedTabAnchor = oTarget; |
|
|
301 |
selectedTabAnchor.get("parentNode").addClass("yui-tab-selected"); |
|
|
302 |
|
|
|
303 |
selectedPanel = Y.Node.get(("#" + panelMap[sID])); |
|
|
304 |
selectedPanel.addClass("yui-tabpanel-selected"); |
|
|
305 |
|
|
|
306 |
creatingPaging(selectedPanel); |
|
|
307 |
|
|
|
308 |
// Prevent the browser from following the URL specified by the |
|
|
309 |
// anchor's "href" attribute when clicked. |
|
|
310 |
|
|
|
311 |
event.preventDefault(); |
|
|
312 |
|
|
|
313 |
}, tabView, "click", ".yui-tab>a"); |
|
|
314 |
|
|
|
315 |
|
|
|
316 |
// Since the anchor's "href" attribute has been removed, the |
|
|
317 |
// element will not fire the click event in Firefox when the |
|
|
318 |
// user presses the enter key. To fix this, dispatch the |
|
|
319 |
// "click" event to the anchor when the user presses the |
|
|
320 |
// enter key. |
|
|
321 |
|
|
|
322 |
if (bGeckoIEWin) { |
|
|
323 |
|
|
|
324 |
Y.on("delegate", function (event) { |
|
|
325 |
|
|
|
326 |
if (event.charCode === 13) { |
|
|
327 |
event.currentTarget.simulate("click"); |
|
|
328 |
} |
|
|
329 |
|
|
|
330 |
}, "#tabview-1", "keydown", ">ul>li>a"); |
|
|
331 |
|
|
|
332 |
} |
|
|
333 |
|
|
|
334 |
|
|
|
335 |
var creatingPaging = function (panel) { |
|
|
336 |
|
|
|
337 |
var listitem, |
|
|
338 |
sHTML, |
|
|
339 |
paging; |
|
|
340 |
|
|
|
341 |
if (!panel.query(".paging")) { |
|
|
342 |
|
|
|
343 |
listitem = selectedTabAnchor.get("parentNode"); |
|
|
344 |
sHTML = ""; |
|
|
345 |
|
|
|
346 |
if (listitem.previous()) { |
|
|
347 |
sHTML += '<button type="button" class="yui-tabview-prevbtn">Previous Tab Panel</button>'; |
|
|
348 |
} |
|
|
349 |
|
|
|
350 |
if (listitem.next()) { |
|
|
351 |
sHTML += '<button type="button" class="yui-tabview-nextbtn">Next Tab Panel</button>'; |
|
|
352 |
} |
|
|
353 |
|
|
|
354 |
paging = Y.Node.create('<div class="paging">' + sHTML + '</div>'); |
|
|
355 |
|
|
|
356 |
panel.appendChild(paging); |
|
|
357 |
|
|
|
358 |
} |
|
|
359 |
|
|
|
360 |
}; |
|
|
361 |
|
|
|
362 |
creatingPaging(Y.Node.get(".yui-tabpanel-selected")); |
|
|
363 |
|
|
|
364 |
|
|
|
365 |
Y.on("delegate", function (event) { |
|
|
366 |
|
|
|
367 |
var node = selectedTabAnchor.get("parentNode").previous().query("a"); |
|
|
368 |
|
|
|
369 |
tabView.focusManager.focus(node); |
|
|
370 |
node.simulate("click"); |
|
|
371 |
|
|
|
372 |
}, tabView, "click", ".yui-tabview-prevbtn"); |
|
|
373 |
|
|
|
374 |
|
|
|
375 |
Y.on("delegate", function (event) { |
|
|
376 |
|
|
|
377 |
var node = selectedTabAnchor.get("parentNode").next().query("a"); |
|
|
378 |
|
|
|
379 |
tabView.focusManager.focus(node); |
|
|
380 |
node.simulate("click"); |
|
|
381 |
|
|
|
382 |
}, tabView, "click", ".yui-tabview-nextbtn"); |
|
|
383 |
|
|
|
384 |
}); |
|
|
385 |
|
|
|
386 |
</script> |
|
|
387 |
|
|
|
388 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
389 |
|
|
|
390 |
|
|
|
391 |
</div> |
|
|
392 |
</div> |
|
|
393 |
</div> |
|
|
394 |
|
|
|
395 |
<h3>Setting Up the HTML</h3> |
|
|
396 |
<p> |
|
|
397 |
The tabs in the tabview widget will be represented by a list of |
|
|
398 |
<code><a></code> elements whose <code>href</code> attribute is set to |
|
|
399 |
the id of an <code><div></code> element that contains its content. |
|
|
400 |
Therefore, without JavaScript and CSS, the tabs function as in-page links. |
|
|
401 |
</p> |
|
|
402 |
<textarea name="code" class="HTML" cols="60" rows="1"> |
|
|
403 |
<h3 id="tabview-heading">Today's News</h3> |
|
|
404 |
<div id="tabview-1" class="yui-tabview"> |
|
|
405 |
<ul> |
|
|
406 |
<li class="yui-tab yui-tab-selected"><a href="#top-stories"><em>Top Stories</em></a></li> |
|
|
407 |
<li class="yui-tab"><a href="#world-news"><em>World</em></a></li> |
|
|
408 |
<li class="yui-tab"><a href="#entertainment-news"><em>Entertainment</em></a></li> |
|
|
409 |
<li class="yui-tab"><a href="#sports-news"><em>Sports</em></a></li> |
|
|
410 |
<li class="yui-tab"><a href="#technology-news"><em>Technology</em></a></li> |
|
|
411 |
</ul> |
|
|
412 |
<div> |
|
|
413 |
<div class="yui-tabpanel yui-tabpanel-selected" id="top-stories"> |
|
|
414 |
<!-- Tab Panel Content Here --> |
|
|
415 |
</div> |
|
|
416 |
<div class="yui-tabpanel" id="world-news"> |
|
|
417 |
<!-- Tab Panel Content Here --> |
|
|
418 |
</div> |
|
|
419 |
<div class="yui-tabpanel" id="entertainment-news"> |
|
|
420 |
<!-- Tab Panel Content Here --> |
|
|
421 |
</div> |
|
|
422 |
<div class="yui-tabpanel" id="sports-news"> |
|
|
423 |
<!-- Tab Panel Content Here --> |
|
|
424 |
</div> |
|
|
425 |
<div class="yui-tabpanel" id="technology-news"> |
|
|
426 |
<!-- Tab Panel Content Here --> |
|
|
427 |
</div> |
|
|
428 |
</div> |
|
|
429 |
</div> |
|
|
430 |
</textarea> |
|
|
431 |
<p> |
|
|
432 |
For this example the content of each tab panel is created on the server using |
|
|
433 |
the <a href="http://developer.yahoo.com/yql/">YQL</a> API to fetch the title and |
|
|
434 |
URL for news stories made available from the various |
|
|
435 |
<a href="http://news.yahoo.com/rss" title="Yahoo! News - RSS">Yahoo! News RSS feeds</a>. |
|
|
436 |
Here's the PHP: |
|
|
437 |
</p> |
|
|
438 |
<textarea name="code" class="PHP" cols="60" rows="1"> |
|
|
439 |
function getFeed($sFeed) { |
|
|
440 |
|
|
|
441 |
$params = array( |
|
|
442 |
"q" => ('select title,link from rss where url="http://rss.news.yahoo.com/rss/'.$sFeed.'"'), |
|
|
443 |
"format" => "json" |
|
|
444 |
); |
|
|
445 |
|
|
|
446 |
$encoded_params = array(); |
|
|
447 |
|
|
|
448 |
foreach ($params as $k => $v) { |
|
|
449 |
$encoded_params[] = urlencode($k)."=".urlencode($v); |
|
|
450 |
} |
|
|
451 |
|
|
|
452 |
$url = "http://query.yahooapis.com/v1/public/yql?".implode("&", $encoded_params); |
|
|
453 |
|
|
|
454 |
$rsp = file_get_contents($url); |
|
|
455 |
|
|
|
456 |
if ($rsp !== false) { |
|
|
457 |
|
|
|
458 |
$rsp_obj = json_decode($rsp, true); |
|
|
459 |
|
|
|
460 |
$results = $rsp_obj["query"]["results"]["item"]; |
|
|
461 |
|
|
|
462 |
$list = ""; // HTML output |
|
|
463 |
|
|
|
464 |
$nResults = count($results); |
|
|
465 |
|
|
|
466 |
if ($nResults > 10) { |
|
|
467 |
$nResults = 9; |
|
|
468 |
} |
|
|
469 |
|
|
|
470 |
for ($i = 0; $i<= $nResults; $i++) { |
|
|
471 |
|
|
|
472 |
$result = $results[$i]; |
|
|
473 |
|
|
|
474 |
$list.= <<< END_OF_HTML |
|
|
475 |
<li> |
|
|
476 |
<a href="{$result["link"]}"><q>{$result["title"]}</q></a> |
|
|
477 |
</li> |
|
|
478 |
END_OF_HTML; |
|
|
479 |
|
|
|
480 |
} |
|
|
481 |
|
|
|
482 |
return ("<ul>" . $list . "</ul>"); |
|
|
483 |
|
|
|
484 |
} |
|
|
485 |
|
|
|
486 |
} |
|
|
487 |
</textarea> |
|
|
488 |
|
|
|
489 |
<h3>Progressive Enhancement</h3> |
|
|
490 |
<p> |
|
|
491 |
The markup above will be transformed into a tabview widget using both CSS and |
|
|
492 |
JavaScript. To account for the scenario where the user has CSS enabled in |
|
|
493 |
their browser but JavaScript is disabled, the CSS used to style the tabview |
|
|
494 |
will be loaded via JavaScript using the |
|
|
495 |
<a href="http://developer.yahoo.com/yui/3/yui/#loader">built-in loader of the YUI Global Object</a>. |
|
|
496 |
Additionally, JavaScript will be used to temporarily hide the tabview markup |
|
|
497 |
while the JavaScript and CSS are in the process of loading to prevent the user |
|
|
498 |
from seeing a flash unstyled content. |
|
|
499 |
</p> |
|
|
500 |
|
|
|
501 |
|
|
|
502 |
<h3>ARIA Support</h3> |
|
|
503 |
<p> |
|
|
504 |
Through the use of CSS and JavaScript the HTML for the tabview can be |
|
|
505 |
transformed into something that looks and behaves like a desktop tab control, |
|
|
506 |
but users of screen readers won't perceive it as an atomic widget, but rather |
|
|
507 |
simply as a set of HTML elements. However, through the application |
|
|
508 |
of the |
|
|
509 |
<a href="http://www.w3.org/TR/wai-aria/">WAI-ARIA Roles and States</a>, it is |
|
|
510 |
possible to improve the semantics of the markup such that users of screen |
|
|
511 |
readers perceive it as a tab control. |
|
|
512 |
</p> |
|
|
513 |
|
|
|
514 |
|
|
|
515 |
<h3>Keyboard Functionality</h3> |
|
|
516 |
<p> |
|
|
517 |
The keyboard functionality for the tabview widget will be provided by the |
|
|
518 |
Focus Manager Node Plugin. The Focus Manager's |
|
|
519 |
<a href="../../api/plugin.NodeFocusManager.html#config_descendants"><code>descendants</code></a> |
|
|
520 |
attribute is set to a value of ".yui-tab>a", so that only one tab in the tabview |
|
|
521 |
is in the browser's default tab flow. This allows users navigating via the |
|
|
522 |
keyboard to use the tab key to quickly move into and out of the tabview. Once |
|
|
523 |
the tabview has focus, the user can move focus among each tab using the left |
|
|
524 |
and right arrows keys, as defined by the value of the |
|
|
525 |
<a href="../../api/plugin.NodeFocusManager.html#config_keys"><code>keys</code></a> |
|
|
526 |
attribute. Lastly, the |
|
|
527 |
<a href="../../api/plugin.NodeFocusManager.html#config_focusClass"><code>focusClass</code></a> |
|
|
528 |
attribute is used to apply a class of <code>yui-tab-focus</code> to the parent |
|
|
529 |
<code><li></code> of each <code><a></code> when it is focused, |
|
|
530 |
making it easy to style the tab's focused state in each of the |
|
|
531 |
<a href="http://developer.yahoo.com/yui/articles/gbs/#gbschart">A-Grade browsers</a>. |
|
|
532 |
<textarea name="code" class="JScript" cols="60" rows="1"> |
|
|
533 |
// Add a class to the documentElement to prevent the user from seeing |
|
|
534 |
// the unstyled menu while the necessary CSS and JavaScript |
|
|
535 |
// dependancies are being fetched. |
|
|
536 |
|
|
|
537 |
document.documentElement.className = "yui-loading"; |
|
|
538 |
|
|
|
539 |
YUI({ |
|
|
540 |
|
|
|
541 |
base: "../../build/", |
|
|
542 |
modules: { |
|
|
543 |
"tabview-css": { |
|
|
544 |
type: "css", |
|
|
545 |
fullpath: "assets/tabview.css" |
|
|
546 |
} |
|
|
547 |
}, |
|
|
548 |
timeout: 10000 |
|
|
549 |
|
|
|
550 |
}).use("tabview-css", "node-focusmanager", "node-event-simulate", function(Y) { |
|
|
551 |
|
|
|
552 |
|
|
|
553 |
var tabView = Y.Node.get("#tabview-1"), |
|
|
554 |
tabList = tabView.query("ul"), |
|
|
555 |
tabHeading = Y.Node.get("#tabview-heading"), |
|
|
556 |
sInstructionalText = tabHeading.get("innerHTML"); |
|
|
557 |
selectedTabAnchor = tabView.query(".yui-tab-selected>a"), |
|
|
558 |
bGeckoIEWin = ((Y.UA.gecko || Y.UA.ie) && navigator.userAgent.indexOf("Windows") > -1), |
|
|
559 |
panelMap = {}; |
|
|
560 |
|
|
|
561 |
|
|
|
562 |
// Remove the "yui-loading" class from the documentElement |
|
|
563 |
// now that the necessary YUI dependencies are loaded. |
|
|
564 |
|
|
|
565 |
tabView.get("ownerDocument").get("documentElement").removeClass("yui-loading"); |
|
|
566 |
|
|
|
567 |
|
|
|
568 |
// Apply the ARIA roles, states and properties. |
|
|
569 |
|
|
|
570 |
// Add some instructional text to the heading that will be read by |
|
|
571 |
// the screen reader when the first tab in the tabview is focused. |
|
|
572 |
|
|
|
573 |
tabHeading.set("innerHTML", (sInstructionalText + " <em>Press the enter key to load the content of each tab.</em>")); |
|
|
574 |
tabList.set("aria-labelledby", "tabview-heading"); |
|
|
575 |
|
|
|
576 |
tabList.set("role", "tablist"); |
|
|
577 |
tabView.query("div").set("role", "presentation"); |
|
|
578 |
|
|
|
579 |
|
|
|
580 |
tabView.plug(Y.Plugin.NodeFocusManager, { |
|
|
581 |
descendants: ".yui-tab>a", |
|
|
582 |
keys: { next: "down:39", // Right arrow |
|
|
583 |
previous: "down:37" }, // Left arrow |
|
|
584 |
focusClass: { |
|
|
585 |
className: "yui-tab-focus", |
|
|
586 |
fn: function (node) { |
|
|
587 |
return node.get("parentNode"); |
|
|
588 |
} |
|
|
589 |
}, |
|
|
590 |
circular: true |
|
|
591 |
}); |
|
|
592 |
|
|
|
593 |
|
|
|
594 |
// If the list of tabs loses focus, set the activeDescendant |
|
|
595 |
// attribute to the currently selected tab. |
|
|
596 |
|
|
|
597 |
tabView.focusManager.after("focusedChange", function (event) { |
|
|
598 |
|
|
|
599 |
if (!event.newVal) { // The list of tabs has lost focus |
|
|
600 |
this.set("activeDescendant", selectedTabAnchor); |
|
|
601 |
} |
|
|
602 |
|
|
|
603 |
}); |
|
|
604 |
|
|
|
605 |
|
|
|
606 |
tabView.queryAll(".yui-tab>a").each(function (anchor) { |
|
|
607 |
|
|
|
608 |
var sHref = anchor.getAttribute("href", 2), |
|
|
609 |
sPanelID = sHref.substring(1, sHref.length), |
|
|
610 |
panel; |
|
|
611 |
|
|
|
612 |
// Apply the ARIA roles, states and properties to each tab |
|
|
613 |
|
|
|
614 |
anchor.set("role", "tab"); |
|
|
615 |
anchor.get("parentNode").set("role", "presentation"); |
|
|
616 |
|
|
|
617 |
|
|
|
618 |
// Remove the "href" attribute from the anchor element to |
|
|
619 |
// prevent JAWS and NVDA from reading the value of the "href" |
|
|
620 |
// attribute when the anchor is focused |
|
|
621 |
|
|
|
622 |
if (bGeckoIEWin) { |
|
|
623 |
anchor.removeAttribute("href"); |
|
|
624 |
} |
|
|
625 |
|
|
|
626 |
// Cache a reference to id of the tab's corresponding panel |
|
|
627 |
// element so that it can be made visible when the tab |
|
|
628 |
// is clicked. |
|
|
629 |
panelMap[anchor.get("id")] = sPanelID; |
|
|
630 |
|
|
|
631 |
|
|
|
632 |
// Apply the ARIA roles, states and properties to each panel |
|
|
633 |
|
|
|
634 |
panel = Y.Node.get(("#" + sPanelID)); |
|
|
635 |
|
|
|
636 |
panel.setAttrs({ |
|
|
637 |
role: "tabpanel", |
|
|
638 |
"aria-labelledby": anchor.get("id") |
|
|
639 |
}); |
|
|
640 |
|
|
|
641 |
}); |
|
|
642 |
|
|
|
643 |
|
|
|
644 |
// Use the "delegate" custom event to listen for the "click" event |
|
|
645 |
// of each tab's <A> element. |
|
|
646 |
|
|
|
647 |
Y.on("delegate", function (event) { |
|
|
648 |
|
|
|
649 |
var selectedPanel, |
|
|
650 |
oTarget = event.currentTarget, |
|
|
651 |
sID = oTarget.get("id"); |
|
|
652 |
|
|
|
653 |
// Deselect the currently selected tab and hide its |
|
|
654 |
// corresponding panel. |
|
|
655 |
|
|
|
656 |
if (selectedTabAnchor) { |
|
|
657 |
selectedTabAnchor.get("parentNode").removeClass("yui-tab-selected"); |
|
|
658 |
Y.Node.get(("#" + panelMap[selectedTabAnchor.get("id")])).removeClass("yui-tabpanel-selected"); |
|
|
659 |
} |
|
|
660 |
|
|
|
661 |
selectedTabAnchor = oTarget; |
|
|
662 |
selectedTabAnchor.get("parentNode").addClass("yui-tab-selected"); |
|
|
663 |
|
|
|
664 |
selectedPanel = Y.Node.get(("#" + panelMap[sID])); |
|
|
665 |
selectedPanel.addClass("yui-tabpanel-selected"); |
|
|
666 |
|
|
|
667 |
creatingPaging(selectedPanel); |
|
|
668 |
|
|
|
669 |
// Prevent the browser from following the URL specified by the |
|
|
670 |
// anchor's "href" attribute when clicked. |
|
|
671 |
|
|
|
672 |
event.preventDefault(); |
|
|
673 |
|
|
|
674 |
}, tabView, "click", ".yui-tab>a"); |
|
|
675 |
|
|
|
676 |
|
|
|
677 |
// Since the anchor's "href" attribute has been removed, the |
|
|
678 |
// element will not fire the click event in Firefox when the |
|
|
679 |
// user presses the enter key. To fix this, dispatch the |
|
|
680 |
// "click" event to the anchor when the user presses the |
|
|
681 |
// enter key. |
|
|
682 |
|
|
|
683 |
if (bGeckoIEWin) { |
|
|
684 |
|
|
|
685 |
Y.on("delegate", function (event) { |
|
|
686 |
|
|
|
687 |
if (event.charCode === 13) { |
|
|
688 |
event.currentTarget.simulate("click"); |
|
|
689 |
} |
|
|
690 |
|
|
|
691 |
}, "#tabview-1", "keydown", ">ul>li>a"); |
|
|
692 |
|
|
|
693 |
} |
|
|
694 |
|
|
|
695 |
}); |
|
|
696 |
</textarea> |
|
|
697 |
|
|
|
698 |
|
|
|
699 |
<h3>Accessibility Sugar</h3> |
|
|
700 |
<p> |
|
|
701 |
One of the challenges faced by users of screen readers is knowing when you've |
|
|
702 |
left the context of a given control. In the case of this tabview, if it |
|
|
703 |
were adjacent to another ARIA-enabled widget, the user would know they've |
|
|
704 |
left the tabview when the screen reader announces the role of the adjacent |
|
|
705 |
widget. However, if the tabview is sitting alongside standard HTML content, it |
|
|
706 |
would be really difficult for the user to know when they've left the context of |
|
|
707 |
the active panel. |
|
|
708 |
</p> |
|
|
709 |
<p> |
|
|
710 |
One solution to this problem is to add some additional navigation as the last |
|
|
711 |
child of each tab panel that allows the user to move to the previous and next |
|
|
712 |
panel in the tabview. This will not only help alert users of screen readers |
|
|
713 |
that they've reached the end of the tab's panel, but allow <em>all</em> |
|
|
714 |
keyboard users to move more quickly to the next/previous panel. Without this |
|
|
715 |
additionally navigation, keyboard users would typically have to press |
|
|
716 |
shift+tab to navigate back up to the list of tabs to move to the next/previous |
|
|
717 |
tab. |
|
|
718 |
</p> |
|
|
719 |
<textarea name="code" class="JScript" cols="60" rows="1"> |
|
|
720 |
var creatingPaging = function (panel) { |
|
|
721 |
|
|
|
722 |
var listitem, |
|
|
723 |
sHTML, |
|
|
724 |
paging; |
|
|
725 |
|
|
|
726 |
if (!panel.query(".paging")) { |
|
|
727 |
|
|
|
728 |
listitem = selectedTabAnchor.get("parentNode"); |
|
|
729 |
sHTML = ""; |
|
|
730 |
|
|
|
731 |
if (listitem.previous()) { |
|
|
732 |
sHTML += '<button type="button" class="yui-tabview-prevbtn">Previous Tab Panel</button>'; |
|
|
733 |
} |
|
|
734 |
|
|
|
735 |
if (listitem.next()) { |
|
|
736 |
sHTML += '<button type="button" class="yui-tabview-nextbtn">Next Tab Panel</button>'; |
|
|
737 |
} |
|
|
738 |
|
|
|
739 |
paging = Y.Node.create('<div class="paging">' + sHTML + '</div>'); |
|
|
740 |
|
|
|
741 |
panel.appendChild(paging); |
|
|
742 |
|
|
|
743 |
} |
|
|
744 |
|
|
|
745 |
}; |
|
|
746 |
|
|
|
747 |
creatingPaging(Y.Node.get(".yui-tabpanel-selected")); |
|
|
748 |
|
|
|
749 |
|
|
|
750 |
Y.on("delegate", function (event) { |
|
|
751 |
|
|
|
752 |
var node = selectedTabAnchor.get("parentNode").previous().query("a"); |
|
|
753 |
|
|
|
754 |
tabView.focusManager.focus(node); |
|
|
755 |
node.simulate("click"); |
|
|
756 |
|
|
|
757 |
}, tabView, "click", ".yui-tabview-prevbtn"); |
|
|
758 |
|
|
|
759 |
|
|
|
760 |
Y.on("delegate", function (event) { |
|
|
761 |
|
|
|
762 |
var node = selectedTabAnchor.get("parentNode").next().query("a"); |
|
|
763 |
|
|
|
764 |
tabView.focusManager.focus(node); |
|
|
765 |
node.simulate("click"); |
|
|
766 |
|
|
|
767 |
}, tabView, "click", ".yui-tabview-nextbtn"); |
|
|
768 |
</textarea> |
|
|
769 |
</div> |
|
|
770 |
<div class="yui-u sidebar"> |
|
|
771 |
|
|
|
772 |
|
|
|
773 |
<div id="examples" class="mod box4"> |
|
|
774 |
<div class="hd"> |
|
|
775 |
<h4> |
|
|
776 |
Focus Manager Node Plugin Examples:</h4> |
|
|
777 |
</div> |
|
|
778 |
<div class="bd"> |
|
|
779 |
<ul> |
|
|
780 |
<li><a href='../node-focusmanager/node-focusmanager-1.html'>Accessible Toolbar</a></li><li class='selected'><a href='../node-focusmanager/node-focusmanager-2.html'>Accessible TabView</a></li><li><a href='../node-focusmanager/node-focusmanager-3.html'>Accessible Menu Button</a></li> </ul> |
|
|
781 |
</div> |
|
|
782 |
</div> |
|
|
783 |
|
|
|
784 |
<div class="mod box4"> |
|
|
785 |
<div class="hd"> |
|
|
786 |
<h4>More Focus Manager Node Plugin Resources:</h4> |
|
|
787 |
</div> |
|
|
788 |
<div class="bd"> |
|
|
789 |
<ul> |
|
|
790 |
<!-- <li><a href="http://developer.yahoo.com/yui/node-focusmanager/">User's Guide</a> (external)</li> --> |
|
|
791 |
<li><a href="../../api/module_node-focusmanager.html">API Documentation</a></li> |
|
|
792 |
</ul> |
|
|
793 |
</div> |
|
|
794 |
</div> |
|
|
795 |
</div> |
|
|
796 |
</div> |
|
|
797 |
|
|
|
798 |
</div> |
|
|
799 |
</div> |
|
|
800 |
|
|
|
801 |
|
|
|
802 |
<div class="yui-b toc3" id="tocWrapper"> |
|
|
803 |
<!-- TABLE OF CONTENTS --> |
|
|
804 |
<div id="toc"> |
|
|
805 |
|
|
|
806 |
<ul> |
|
|
807 |
<li class="sect first">YUI 3.x Project</li><li class="item"><a title="The Yahoo! User Interface (YUI) Library, 3.x Branch, " href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site (external)</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="The YUI Library can be downloaded from SourceForge" href="http://sourceforge.net/projects/yui/">YUI 3 on Sourceforge (external)</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/3/license.html">YUI License (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI (Global Prerequisite) - Functional Examples" href="../../examples/yui/index.html">YUI (Global Prerequisite)</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin</a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema</a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource</a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType</a></li><li class="item"><a title="Drag & Drop - Functional Examples" href="../../examples/dd/index.html">Drag & Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="History - Functional Examples" href="../../examples/history/index.html">History</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Queue - Functional Examples" href="../../examples/queue/index.html">Queue</a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay</a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider</a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin</a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin</a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console</a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">The YUI Community</li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="item"><a title="The Yahoo! Group YDN-JavaScript hosts the YUI community forum" href="http://tech.groups.yahoo.com/group/ydn-javascript/">YUI Forum (external)</a></li><li class="item"><a title="The Yahoo! Group yui3 is dedicated to the 3.x branch of the Yahoo! User Interface (YUI) Library." href="http://tech.groups.yahoo.com/group/yui3/">YUI 3 Forum (external)</a></li><li class="item"><a title="YUI is used by Yahoo! and by hundreds of other sites, including many you know and love." href="/yui/poweredby/">YUI Sightings (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li><li class="sect">YUI Articles on the YUI Website</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Reporting Bugs and Making Feature Requests for YUI Components" href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests (external)</a></li><li class="item"><a title="Serve YUI source files from Yahoo! -- free, fast, and simple" href="http://developer.yahoo.com/yui/3/articles/hosting/">Serving YUI Files from Yahoo! (external)</a></li></ul> |
|
|
808 |
</div> |
|
|
809 |
</div> |
|
|
810 |
</div><!--closes bd--> |
|
|
811 |
|
|
|
812 |
<div id="ft"> |
|
|
813 |
<p class="first">Copyright © 2009 Yahoo! Inc. All rights reserved.</p> |
|
|
814 |
<p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - |
|
|
815 |
<a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - |
|
|
816 |
<a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - |
|
|
817 |
<a href="http://careers.yahoo.com/">Job Openings</a></p> |
|
|
818 |
</div> |
|
|
819 |
</div> |
|
|
820 |
<script src="../../assets/dpSyntaxHighlighter.js"></script> |
|
|
821 |
<script language="javascript"> |
|
|
822 |
dp.SyntaxHighlighter.HighlightAll('code'); |
|
|
823 |
</script> |
|
|
824 |
</body> |
|
|
825 |
</html> |