From ab35086f6e8d115a775035f8128a83faf41c2115 Mon Sep 17 00:00:00 2001 From: adickson Date: Mon, 6 Jun 2011 22:55:13 -0700 Subject: [PATCH 1/2] JS only version (i.e. without JQuery) with a defaults object --- accessifyhtml5.js | 112 ++++++++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 39 deletions(-) diff --git a/accessifyhtml5.js b/accessifyhtml5.js index 5feab2c..86668fd 100644 --- a/accessifyhtml5.js +++ b/accessifyhtml5.js @@ -1,39 +1,73 @@ -/* - * Accessifyhtml5.js - * Adds ARIA to new elements in browsers which don’t do it by themselves. - * Just drop into the bottom of your web page: - * - * - * Yes, it depends on jQuery. - * - * Souce: http://www.html5accessibility.com/index-aria.html - * - * Todo: Extend Script for other elements, probably even play with fallback JS for inaccessible audio/video. - * - * Acknowledgements: - * - @stevefaulkner for his work exploring html5 a11y, - * - @paddya91 for object notation & document ready - * - @ginader for reporting typo - * - @webaxe for reporting an error - */ - -$(document).ready(function() { - - var fixes = { - 'header.site' : { 'role': 'banner' }, - 'footer.site' : { 'role': 'contentinfo' }, - 'article' : { 'role': 'article' }, - 'aside' : { 'role': 'complementary' }, - 'nav' : { 'role': 'navigation' }, - 'output' : { 'aria-live': 'polite' }, - 'section' : { 'role': 'region' }, - '[required]' : { 'aria-required': 'true' } - }; - - $.each(fixes, - function(index, item) { - $(index).attr(item); - } - ); - -}); \ No newline at end of file +/* +* Accessifyhtml5.js +* Adds ARIA to new elements in browsers which don’t do it by themselves. +* Just drop into the bottom of your web page: +* +* +* Souce: http://www.html5accessibility.com/index-aria.html +* +* Todo: Extend Script for other elements, probably even play with fallback JS for inaccessible audio/video. +* +* Acknowledgements: +* - @stevefaulkner for his work exploring html5 a11y, +* - @paddya91 for object notation & document ready +* - @ginader for reporting typo +* - @webaxe for reporting an error +*/ + +/* +* JS only version by adickson +* +* You can specify an object containing default header and footer CSS selector properties when you call AccessifyHTML5 +* i.e. +* AccessifyHTML5({header:"#header", footer:"#footer"}); +* +*/ + + +var AccessifyHTML5 = function (defaults) { + + var fixes = { + 'header' : {'role': 'banner' }, + 'footer' : {'role': 'contentinfo' }, + 'article' : {'role': 'article' }, + 'aside' : {'role': 'complementary' }, + 'nav' : {'role': 'navigation' }, + 'output' : {'aria-live': 'polite' }, + 'section' : {'role': 'region' }, + '[required]': {'aria-required': 'true' } + }; + + if (defaults) { + if (defaults.header) { + delete fixes['header']; + fixes[defaults.header] = { + 'role': 'banner' + }; + } + if (defaults.footer) { + delete fixes['footer']; + fixes[defaults.footer] = { + 'role': 'contentinfo' + } + } + } + + for (fix in fixes) { + + var elems = document.querySelectorAll(fix), + obj = fixes[fix], + attr, value, i = 0; + + for (key in obj) { + attr = key; + value = obj[key]; + } + + for (i; i < elems.length; i++) { + elems[i].setAttribute(attr, value); + } + + } + + }; \ No newline at end of file From 00be8baf01e724af73b1e5829298c38695fa89e6 Mon Sep 17 00:00:00 2001 From: adickson Date: Tue, 7 Jun 2011 20:41:24 -0700 Subject: [PATCH 2/2] I've modified this from the original so that it doesn't depend on JQuery, but will only work in browsers that support querySelectorAll(); --- README.textile | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.textile b/README.textile index 8ef2bf4..27fd41c 100644 --- a/README.textile +++ b/README.textile @@ -1,25 +1,25 @@ -h1. accessifyhtml5.js - -This should probably go into modernizr or something, so see it just as a prototype. It depends on jQuery and was quickly hacked together. Please suggest improvements to @yatil. - -It adds ARIA to new elements in browsers which don’t do it by themselves. - -Just drop into the bottom of your web page: - - -Souce: http://www.html5accessibility.com/index-aria.html - -Todo: Extend Script for other elements, probably even play with fallback JS for inaccessible audio/video. - -h2. Acknowledgements: - -* @stevefaulkner for his work exploring html5 a11y, -* @paddya91 for object notation -* @ginader for reporting typo -* @webaxe for reporting an error - -h2. Known Issues: - -According to @jkiss, Window-Eyes 7.11 struggles with aria-roles and HTML5, this is nothing I can solve with this script but is a screen reader issue. See: http://ya.tl/aNH1YQ - +h1. accessifyhtml5.js + +This should probably go into modernizr or something, so see it just as a prototype. It depends on jQuery and was quickly hacked together. Please suggest improvements to @yatil. + +It adds ARIA to new elements in browsers which don’t do it by themselves. + +Just drop into the bottom of your web page: + + +Souce: http://www.html5accessibility.com/index-aria.html + +Todo: Extend Script for other elements, probably even play with fallback JS for inaccessible audio/video. + +h2. Acknowledgements: + +* @stevefaulkner for his work exploring html5 a11y, +* @paddya91 for object notation +* @ginader for reporting typo +* @webaxe for reporting an error + +h2. Known Issues: + +According to @jkiss, Window-Eyes 7.11 struggles with aria-roles and HTML5, this is nothing I can solve with this script but is a screen reader issue. See: http://ya.tl/aNH1YQ + This is Open Source and free to use. Attribution is nice to see, but no must. Just use it. \ No newline at end of file