UNPKG

accesskey

Version:

accesskey for chrome or edge

3 lines (2 loc) 1.51 kB
!function(){"use strict";function e(e,t,c){return(e+="+"==c?1:-1)>=t&&(e=0),e<0&&(e=t-1),e}function t(e){let t=e.tagName.toLowerCase();(["div","p","span","h1","h2","h3","h4","h5","h6","ul","ol","li","form","img","nav","header","main","footer","section","aside"].includes(t)||"a"==t&&!e.hasAttribute("href"))&&(e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1")),e.focus()}function c(c,s){let n=[...document.body.querySelectorAll("*")],i=n.length,a=Math.max(0,n.indexOf(document.activeElement)),o=0==a?0:e(a,i,s);do{if(n[o].matches(c)&&(!(u=n[o]).hasAttribute("disabled")&&"true"!==u.getAttribute("aria-hidden")&&null!==u.offsetParent)){t(n[o]);break}o=e(o,i,s)}while(o!=a);var u}function s(){document.querySelectorAll("[accesskey]").forEach((function(e){let t=e.getAttribute("accesskey").toLowerCase();e.removeAttribute("accesskey"),e.classList.add("accesskey-"+t),window.accjsAccesskeys.includes(t)||window.accjsAccesskeys.push(t)}))}window.ActiveXObject||"ActiveXObject"in window||(window.accjsAccesskeys=[],s(),document.addEventListener("keydown",(function(e){let t=e.key.toLowerCase(),s=window.accjsAccesskeys.includes(t);e.altKey&&e.shiftKey&&s?(e.preventDefault(),c(".accesskey-"+t,"-")):e.altKey&&s&&(e.preventDefault(),function(e){c(e,"+")}(".accesskey-"+t))}),null),document.querySelectorAll("script[data-accjs-mutation-observer]").length>0&&function(e,t){let c=new MutationObserver(t=>{e()});c.observe(t,{childList:!0,subtree:!0})}(s,document.body))}(); //# sourceMappingURL=accesskey.min.js.map