forked from yatil/accessifyhtml5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accessifyhtml5.min.js
10 lines (9 loc) · 1.77 KB
/
accessifyhtml5.min.js
1
2
3
4
5
6
7
8
9
10
/*
* Accessifyhtml5.js
*
* Source: https://github.com/yatil/accessifyhtml5.js
*/
var AccessifyHTML5=function(e,f){var c={article:{role:"article"},aside:{role:"complementary"},nav:{role:"navigation"},main:{role:"main"},output:{"aria-live":"polite"},section:{role:"region"},"[required]":{"aria-required":"true"}},g={ok:[],warn:[],fail:[]},k=g.fail,b,h,a,d,n,p,l,t,m,r=RegExp("aria-[a-z]+|role|tabindex|title|alt|data-[\\w-]+|lang|id|style|for|maxlength|placeholder|pattern|required|type|target|accesskey|longdesc"),s=0,q=document;if(q.querySelectorAll){e&&(e.header&&(c[e.header]={role:"banner"}),
e.footer&&(c[e.footer]={role:"contentinfo"}),e.main&&(c[e.main]={role:"main"},c.main={role:""}));if(f&&f._CONFIG_&&f._CONFIG_.ignore_defaults)c=f;else for(a in f)c[a]=f[a];for(b in c)if(!b.match(/^_(CONFIG|[A-Z]+)_/)&&c.hasOwnProperty(b)){try{h=q.querySelectorAll(b)}catch(u){k.push({sel:b,attr:null,val:null,msg:"Invalid syntax for `document.querySelectorAll` function",ex:u})}p=c[b];(!h||1>h.length)&&g.warn.push({sel:b,attr:null,val:null,msg:"Not found"});for(l=0;l<h.length;l++)for(n in p)if(p.hasOwnProperty(n)&&
(a=n,d=p[n],!a.match(/_?note/)))if(a.match(r))if((typeof d).match(/string|number|boolean/)){if(t=a.match(/(for|aria-labelledby|aria-describedby)$/)){try{m=q.querySelector(d)}catch(v){k.push({sel:b,attr:a,val:d,msg:"Invalid selector syntax (2) - see 'val'",ex:v})}if(!m){k.push({sel:b,attr:a,val:d,msg:"Labelledby ref not found - see 'val'"});continue}m.id||(m.id="acfy-id-"+s);d=m.id;s++}h[l].hasAttribute(a)?g.warn.push({sel:b,attr:a,val:d,msg:"Already present, skipped"}):(h[l].setAttribute(a,d),g.ok.push({sel:b,
attr:a,val:d,msg:"Added"}))}else k.push({sel:b,attr:a,val:d,msg:"Value-type not allowed"});else k.push({sel:b,attr:a,val:null,msg:"Attribute not allowed",re:r})}}g.input=c;return g};