AccessifyHTML5 - improved
Some improvements to AccessifyHTML5
Original: http://jsfiddle.net/rodneyrehm/SaNmp/
by Jens Grochtdreis
HTML
<button id="add-output">add output</button>
JavaScript
/*
* Accessifyhtml5.js
*
* Source: https://github.com/yatil/accessifyhtml5.js
*/
(function($, undefined){
$.accessifyHtml5 = function(options) {
var selectors = $.accessifyHtml5.defaults;
// import special selectors (if they're known to $.accessifyHtml5.special)
if (options) {
// "clone" default map for we don't want it mutated
selectors = $.extend(true, {}, $.accessifyHtml5.defaults);
$.each(options, function(key, selector) {
if ($.accessifyHtml5.special[key]) {
// replace key by the given selector, import attributes from .special
selectors[selector] = $.accessifyHtml5.special[key];
}
});
}
// apply attributes
$.each(selectors, function(selector, attrs){
$(selector).attr(attrs);
});
return this;
};
// list of elements to be replaced by a given selector in options to $.accessifyHtml5()
$.accessifyHtml5.special = {
'header' : { 'role': 'banner' },
'footer' : { 'role': 'contentinfo' },
'main' : { 'role': 'main' }
};
// selector to update upon dom node creation
$.accessifyHtml5.selector = 'article, aside, nav, output, section, [required]';
// default selectors
$.accessifyHtml5.defaults = {
'article' : { 'role': 'article' },
'aside' : { 'role': 'complementary' },
'nav' : { 'role': 'navigation' },
'output' : { 'aria-live': 'polite' },
'section' : { 'role': 'region' },
'[required]' : { 'aria-required': 'true' }
};
// register DOMNodeInserted listener at onDomReady so you have a chance to disable it
$(function(){
if (!$.accessifyHtml5.selector)...