diff --git a/templates/2k11/admin/js/2k11.admin.js b/templates/2k11/admin/js/2k11.admin.js index dbdee966..d971a0b0 100644 --- a/templates/2k11/admin/js/2k11.admin.js +++ b/templates/2k11/admin/js/2k11.admin.js @@ -1,38 +1,96 @@ (function($) { - // https://github.com/yatil/accessifyhtml5.js - var AccessifyHTML5 = function (defaults) { - var fixes = { - 'article' : { 'role': 'article' }, - 'aside' : { 'role': 'complementary' }, - 'nav' : { 'role': 'navigation' }, - 'output' : { 'aria-live': 'polite' }, - 'section' : { 'role': 'region' }, - '[required]' : { 'aria-required': 'true' } - }; + // Source: https://github.com/yatil/accessifyhtml5.js + var AccessifyHTML5 = function (defaults, more_fixes) { + "use strict"; + + var fixes = { + 'article' : {'role': 'article' }, + 'aside' : {'role': 'complementary' }, + 'nav' : {'role': 'navigation' }, + 'main' : {'role': 'main' }, + 'output' : {'aria-live': 'polite' }, + 'section' : {'role': 'region' }, + '[required]': {'aria-required': 'true' } + }, + fix, elems, attr, value, key, obj, i, mo, by_match, el_label, + ATTR_SECURE = /aria-[a-z]+|role|tabindex|title|alt|data-[\w\-]+|lang|style|maxlength|placeholder|pattern|type/, + ID_PREFIX = "acfy-id-", + n_label = 0, + Doc = document; + + if (Doc.querySelectorAll) { if (defaults) { - if (defaults.header) { - fixes[defaults.header] = { - 'role': 'banner' - }; - } - if (defaults.footer) { - fixes[defaults.footer] = { - 'role': 'contentinfo' - } - } - if (defaults.main) { - fixes[defaults.main] = { - 'role': 'main' - } - } + if (defaults.header) { + fixes[defaults.header] = { + 'role': 'banner' + }; + } + if (defaults.footer) { + fixes[defaults.footer] = { + 'role': 'contentinfo' + }; + } + if (defaults.main) { + fixes[defaults.main] = { + 'role': 'main' + }; + fixes.main = { + 'role': '' + }; + } } - $.each(fixes, - function(index, item) { - $(index).attr(item); + for (mo in more_fixes) { + fixes[mo] = more_fixes[mo]; + } + + for (fix in fixes) { + if (fixes.hasOwnProperty(fix)) { + + elems = Doc.querySelectorAll(fix); + obj = fixes[fix]; + + for (i = 0; i < elems.length; i++) { + + for (key in obj) { + if (obj.hasOwnProperty(key)) { + + attr = key; + value = obj[key]; + + if (!attr.match(ATTR_SECURE)) { + continue; + } + if (!(typeof value).match(/string|number/)) { + continue; + } + + by_match = attr.match(/(describ|label)l?edby/); + if (by_match) { + el_label = Doc.querySelector(value); + + if (! el_label) { continue; } + + if (! el_label.id) { + el_label.id = ID_PREFIX + n_label; + } + + value = el_label.id; + attr = "aria-" + ("label" === by_match[1] ? "labelledby" : "describedby"); + + n_label++; + } + + if (!elems[i].hasAttribute(attr)) { + elems[i].setAttribute(attr, value); + } + } + } } - ); + } + } + } }; AccessifyHTML5({