forked from KittyGiraudel/a11y-dialog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha11y-dialog.min.js
1 lines (1 loc) · 1.49 KB
/
a11y-dialog.min.js
1
!function(e){"use strict";function t(e){var t=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'];return n(t.join(","),e).filter(function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)})}function n(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function i(e,n){var i=t(e),o=i.indexOf(document.activeElement);n.shiftKey&&0===o?(i[i.length-1].focus(),n.preventDefault()):n.shiftKey||o!==i.length-1||(i[0].focus(),n.preventDefault())}function o(e){var n=t(e);n.length&&n[0].focus()}var r,a=function(e,t){function a(t){s.shown&&!e.contains(t.target)&&o(e)}function c(){s.shown=!0,e.removeAttribute("aria-hidden"),t.setAttribute("aria-hidden","true"),r=document.activeElement,o(e),document.body.addEventListener("focus",a,!0)}function d(){s.shown=!1,e.setAttribute("aria-hidden","true"),t.removeAttribute("aria-hidden"),r&&r.focus(),document.body.removeEventListener("focus",a,!0)}var u="data-a11y-dialog",s=this;t=t||document.querySelector("#main"),this.shown=!1,this.show=c,this.hide=d,n("["+u+'-show="'+e.id+'"]').forEach(function(e){e.addEventListener("click",c)}),n("["+u+"-hide]",e).concat(n("["+u+'-hide="'+e.id+'"]')).forEach(function(e){e.addEventListener("click",d)}),document.addEventListener("keydown",function(t){s.shown&&27===t.which&&(t.preventDefault(),d()),s.shown&&9===t.which&&i(e,t)})};e.A11yDialog=a}(window);