@accede-web/overlay
Advanced tools
Comparing version
/** | ||
* @accede-web/overlay - WAI-ARIA overlay plugin based on AcceDe Web instructions | ||
* @version v1.0.1 | ||
* @version v1.0.2 | ||
* @link http://a11y.switch.paris/ | ||
@@ -604,3 +604,4 @@ * @license ISC | ||
// store the current focused element before focusing the layer | ||
this.options.opener = this.options.opener || activeElement; | ||
this.options.opener = this.options.opener || activeElement || document.activeElement; | ||
// IE can't focus a svg element | ||
@@ -607,0 +608,0 @@ if (this.options.opener.nodeName === 'svg') { |
/** | ||
* @accede-web/overlay - WAI-ARIA overlay plugin based on AcceDe Web instructions | ||
* @version v1.0.1 | ||
* @version v1.0.2 | ||
* @link http://a11y.switch.paris/ | ||
* @license ISC | ||
**/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Overlay=t()}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t="a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, [tabindex], [contentEditable]",i={set:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,i=arguments[1];if(!e.disabledElements){var n=[],l=[];Array.prototype.forEach.call(e.querySelectorAll(t),function(e){if(!(i&&i.contains(e)||e.closest("[hidden]"))){var t=parseInt(e.getAttribute("tabindex"),10);if(t){if(t<0)return;e.defaultTabindex=t}n.push(e),e.setAttribute("tabindex","-1")}}),e.disabledElements=n.length?n:null,i?Array.prototype.forEach.call(i.parentNode.children,function(e){if("SCRIPT"!==e.nodeName&&e!==i){var t=e.getAttribute("aria-hidden");if(t){if("true"===t)return;e.defaultAriaHidden=t}e.setAttribute("aria-hidden","true"),l.push(e)}}):(e.setAttribute("aria-hidden","true"),l.push(e)),e.hiddenElements=l.length?l:null}},unset:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,i=e.disabledElements||Array.prototype.slice.call(e.querySelectorAll(t)),n=e.hiddenElements||[e];i.forEach(function(e){var t=e.defaultTabindex;t?(e.setAttribute("tabindex",t),e.defaultTabindex=null):e.removeAttribute("tabindex")}),e.disabledElements=null,n.forEach(function(e){var t=e.defaultAriaHidden;t?(e.setAttribute("aria-hidden",t),e.defaultAriaHidden=null):e.removeAttribute("aria-hidden")}),e.hiddenElements=null},focusables:t},n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),o=0,s=[],a=void 0,r=function(){function t(i,l){if(e(this,t),this._handleCancel=this._handleCancel.bind(this),this._handleClick=this._handleClick.bind(this),this._handleClose=this._handleClose.bind(this),this.callbacks={},l=arguments[1]||("object"===n(arguments[0])?arguments[0]:{}),"string"==typeof(i=l!==arguments[0]?arguments[0]:void 0)){var o=document.createElement("div");o.innerHTML=i,i=o.firstChild}if(!i&&!l)throw new Error("No parameter passed.");void 0===l.modal&&(l.modal=!0),l.closeOnCancel||(l.closeOnCancel=!0),this.options=l,this._init(i)}return l(t,[{key:"addEventListener",value:function(){this.el.addEventListener.apply(this.el,arguments)}},{key:"returnValue",get:function(){return this.el.returnValue},set:function(e){"object"!==(void 0===e?"undefined":n(e))?this.el.returnValue=e.toString():this.el.returnValue=JSON.stringify(e)}}],[{key:"layerIndex",get:function(){return o},set:function(e){o=e}},{key:"stack",get:function(){return s.slice()}}]),l(t,[{key:"_bind",value:function(){var e=this;this.el.addEventListener("click",this._handleClick),this.el.addEventListener("cancel",this._handleCancel),this.el.closeBtns&&this.el.closeBtns.forEach(function(t){t.addEventListener("click",e._handleClose)})}},{key:"_createDom",value:function(){var e=document.createElement(this.options.tagName||"div");if(this.options.className&&(e.className+=this.options.className),e.setAttribute("aria-hidden","true"),this.options.modal&&e.setAttribute("aria-modal","true"),this.options.content&&("string"==typeof this.options.content?e.innerHTML=this.options.content:e.appendChild(this.options.content)),this.options.label&&e.setAttribute("aria-label",this.options.label),this.options.role){e.setAttribute("role",this.options.role);var i=t.layerIndex;if(!this.options.label&&!e.hasAttribute("aria-labelledby")&&!e.hasAttribute("aria-label")){var n=e.querySelector(this.options.titleSelector||"[data-label]"),l=void 0;n&&(l=n.id||"layerTitle"+i,n.id=l,e.setAttribute("aria-labelledby",l))}if(!e.hasAttribute("aria-describedby")){var o=e.querySelector("[data-description]"),s=void 0;o&&(s=o.id||"layerDescription"+i,o.id=s,e.setAttribute("aria-describedby",s))}}return e}},{key:"_disableDocument",value:function(){this.documentDisabled=!0,i.set(document.body,this.el)}},{key:"_dispatchEvent",value:function(e){var t={cancelable:"cancel"===e},i=new window.CustomEvent(e,t);this.el.dispatchEvent(i)}},{key:"_enableDocument",value:function(){i.unset(document.body),this.documentDisabled=!1}},{key:"_enableLayer",value:function(){i.unset(this.el)}},{key:"_setInteractiveElement",value:function(){var e=this;if(this.el.firstInteractiveElement=this.el.querySelector("[autofocus]"),!this.el.firstInteractiveElement){var t=window.innerHeight;Array.prototype.some.call(this.el.querySelectorAll(i.focusables),function(i){var n=i.offsetHeight;return!!(i.offsetTop+n<=t&&(i.offsetWidth||i.offsetHeight))&&(e.el.firstInteractiveElement=i,!0)}),this.el.firstInteractiveElement||Array.prototype.some.call(this.el.querySelectorAll("h1, h2, h3, h4, h5, h6, p, ul, dl, figure, img, table, canvas, detail"),function(t){return!(!t.offsetWidth&&!t.offsetHeight)&&(t.setAttribute("tabindex","-1"),e.el.firstInteractiveElement=t,!0)})}}},{key:"_focus",value:function(){var e=this;this.el.firstInteractiveElement||this._setInteractiveElement(),window.requestAnimationFrame(function(){e.el.firstInteractiveElement.focus()})}},{key:"_handleCancel",value:function(e){e.defaultPrevented||"alertdialog"===this.options.role||this._handleClose(e)}},{key:"_handleClick",value:function(e){!1!==this.options.closeOnCancel&&e.target===this.el&&(e.target===this.el&&"alertdialog"===this.options.role||this._dispatchEvent("cancel"))}},{key:"_handleClose",value:function(){this._unbind(),this._dispatchEvent("close"),this.el.setAttribute("aria-hidden","true"),this.options.modal&&1===s.length&&this._enableDocument(),s.splice(s.indexOf(this.el),1),this.options.opener.focus()}},{key:"close",value:function(e){e&&(this.el.returnValue=e),this._handleClose()}},{key:"_init",value:function(e){return t.layerIndex++,this.el=e?this._initDom(e):this._createDom(),this.el.layer=this,this.el.returnValue="",this.el.close=this.close,this.options.closeSelector&&(this.el.closeBtns=Array.prototype.slice.call(this.el.querySelectorAll(this.options.closeSelector)),this.el.closeBtns.length||delete this.el.closeBtns),this.options.role&&this._validateModal(),this.el.parentNode!==document.body&&document.body.appendChild(this.el),this}},{key:"_initDom",value:function(e){return this.options.role=e.getAttribute("role"),this.options.modal&&e.setAttribute("aria-modal","true"),e}},{key:"removeEventListener",value:function(){this.el.removeEventListener.apply(this.el,arguments)}},{key:"show",value:function(){s.unshift(this.el),this.returnValue="",this._bind(),this.options.opener=this.options.opener||a,"svg"===this.options.opener.nodeName&&(this.options.opener=this.options.opener.parentNode),"false"!==this.el.getAttribute("aria-hidden")&&this.el.setAttribute("aria-hidden","false"),this._focus(),1===s.length&&this.options.modal&&!this.documentDisabled?this._disableDocument():this.documentDisabled&&this.options.content&&this._enableLayer()}},{key:"_unbind",value:function(){var e=this;this.el.removeEventListener("click",this._handleClick),this.el.removeEventListener("click",this._handleCancel),this.el.closeBtns&&this.el.closeBtns.forEach(function(t){t.removeEventListener("click",e._handleClose)})}},{key:"_validateModal",value:function(){var e=this.el.getAttribute("aria-label"),t=this.el.getAttribute("aria-describedby"),i=void 0;if((!e||e&&e.trim().length<0)&&(!(i=this.el.querySelector("#"+this.el.getAttribute("aria-labelledby")))||!this.el.contains(i)))throw new Error('No title is present in the layer. Use the "data-label" attribute on the visible title or pass the label using the "label" key when creating the layer.');if("alertdialog"===this.options.role&&!t)throw new Error('"alertdialog" layer needs a description, use the "data-description" attribute on the text content of the layer to validate the layer.')}}]),t}();return document.body.addEventListener("keydown",function(e){s.length&&27===e.keyCode&&s[0].layer._dispatchEvent("cancel")}),document.body.addEventListener("focus",function(e){e.target!==document.body&&(a=e.target)},!0),r}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Overlay=t()}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t="a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, [tabindex], [contentEditable]",i={set:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,i=arguments[1];if(!e.disabledElements){var n=[],l=[];Array.prototype.forEach.call(e.querySelectorAll(t),function(e){if(!(i&&i.contains(e)||e.closest("[hidden]"))){var t=parseInt(e.getAttribute("tabindex"),10);if(t){if(t<0)return;e.defaultTabindex=t}n.push(e),e.setAttribute("tabindex","-1")}}),e.disabledElements=n.length?n:null,i?Array.prototype.forEach.call(i.parentNode.children,function(e){if("SCRIPT"!==e.nodeName&&e!==i){var t=e.getAttribute("aria-hidden");if(t){if("true"===t)return;e.defaultAriaHidden=t}e.setAttribute("aria-hidden","true"),l.push(e)}}):(e.setAttribute("aria-hidden","true"),l.push(e)),e.hiddenElements=l.length?l:null}},unset:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,i=e.disabledElements||Array.prototype.slice.call(e.querySelectorAll(t)),n=e.hiddenElements||[e];i.forEach(function(e){var t=e.defaultTabindex;t?(e.setAttribute("tabindex",t),e.defaultTabindex=null):e.removeAttribute("tabindex")}),e.disabledElements=null,n.forEach(function(e){var t=e.defaultAriaHidden;t?(e.setAttribute("aria-hidden",t),e.defaultAriaHidden=null):e.removeAttribute("aria-hidden")}),e.hiddenElements=null},focusables:t},n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),o=0,s=[],a=void 0,r=function(){function t(i,l){if(e(this,t),this._handleCancel=this._handleCancel.bind(this),this._handleClick=this._handleClick.bind(this),this._handleClose=this._handleClose.bind(this),this.callbacks={},l=arguments[1]||("object"===n(arguments[0])?arguments[0]:{}),"string"==typeof(i=l!==arguments[0]?arguments[0]:void 0)){var o=document.createElement("div");o.innerHTML=i,i=o.firstChild}if(!i&&!l)throw new Error("No parameter passed.");void 0===l.modal&&(l.modal=!0),l.closeOnCancel||(l.closeOnCancel=!0),this.options=l,this._init(i)}return l(t,[{key:"addEventListener",value:function(){this.el.addEventListener.apply(this.el,arguments)}},{key:"returnValue",get:function(){return this.el.returnValue},set:function(e){"object"!==(void 0===e?"undefined":n(e))?this.el.returnValue=e.toString():this.el.returnValue=JSON.stringify(e)}}],[{key:"layerIndex",get:function(){return o},set:function(e){o=e}},{key:"stack",get:function(){return s.slice()}}]),l(t,[{key:"_bind",value:function(){var e=this;this.el.addEventListener("click",this._handleClick),this.el.addEventListener("cancel",this._handleCancel),this.el.closeBtns&&this.el.closeBtns.forEach(function(t){t.addEventListener("click",e._handleClose)})}},{key:"_createDom",value:function(){var e=document.createElement(this.options.tagName||"div");if(this.options.className&&(e.className+=this.options.className),e.setAttribute("aria-hidden","true"),this.options.modal&&e.setAttribute("aria-modal","true"),this.options.content&&("string"==typeof this.options.content?e.innerHTML=this.options.content:e.appendChild(this.options.content)),this.options.label&&e.setAttribute("aria-label",this.options.label),this.options.role){e.setAttribute("role",this.options.role);var i=t.layerIndex;if(!this.options.label&&!e.hasAttribute("aria-labelledby")&&!e.hasAttribute("aria-label")){var n=e.querySelector(this.options.titleSelector||"[data-label]"),l=void 0;n&&(l=n.id||"layerTitle"+i,n.id=l,e.setAttribute("aria-labelledby",l))}if(!e.hasAttribute("aria-describedby")){var o=e.querySelector("[data-description]"),s=void 0;o&&(s=o.id||"layerDescription"+i,o.id=s,e.setAttribute("aria-describedby",s))}}return e}},{key:"_disableDocument",value:function(){this.documentDisabled=!0,i.set(document.body,this.el)}},{key:"_dispatchEvent",value:function(e){var t={cancelable:"cancel"===e},i=new window.CustomEvent(e,t);this.el.dispatchEvent(i)}},{key:"_enableDocument",value:function(){i.unset(document.body),this.documentDisabled=!1}},{key:"_enableLayer",value:function(){i.unset(this.el)}},{key:"_setInteractiveElement",value:function(){var e=this;if(this.el.firstInteractiveElement=this.el.querySelector("[autofocus]"),!this.el.firstInteractiveElement){var t=window.innerHeight;Array.prototype.some.call(this.el.querySelectorAll(i.focusables),function(i){var n=i.offsetHeight;return!!(i.offsetTop+n<=t&&(i.offsetWidth||i.offsetHeight))&&(e.el.firstInteractiveElement=i,!0)}),this.el.firstInteractiveElement||Array.prototype.some.call(this.el.querySelectorAll("h1, h2, h3, h4, h5, h6, p, ul, dl, figure, img, table, canvas, detail"),function(t){return!(!t.offsetWidth&&!t.offsetHeight)&&(t.setAttribute("tabindex","-1"),e.el.firstInteractiveElement=t,!0)})}}},{key:"_focus",value:function(){var e=this;this.el.firstInteractiveElement||this._setInteractiveElement(),window.requestAnimationFrame(function(){e.el.firstInteractiveElement.focus()})}},{key:"_handleCancel",value:function(e){e.defaultPrevented||"alertdialog"===this.options.role||this._handleClose(e)}},{key:"_handleClick",value:function(e){!1!==this.options.closeOnCancel&&e.target===this.el&&(e.target===this.el&&"alertdialog"===this.options.role||this._dispatchEvent("cancel"))}},{key:"_handleClose",value:function(){this._unbind(),this._dispatchEvent("close"),this.el.setAttribute("aria-hidden","true"),this.options.modal&&1===s.length&&this._enableDocument(),s.splice(s.indexOf(this.el),1),this.options.opener.focus()}},{key:"close",value:function(e){e&&(this.el.returnValue=e),this._handleClose()}},{key:"_init",value:function(e){return t.layerIndex++,this.el=e?this._initDom(e):this._createDom(),this.el.layer=this,this.el.returnValue="",this.el.close=this.close,this.options.closeSelector&&(this.el.closeBtns=Array.prototype.slice.call(this.el.querySelectorAll(this.options.closeSelector)),this.el.closeBtns.length||delete this.el.closeBtns),this.options.role&&this._validateModal(),this.el.parentNode!==document.body&&document.body.appendChild(this.el),this}},{key:"_initDom",value:function(e){return this.options.role=e.getAttribute("role"),this.options.modal&&e.setAttribute("aria-modal","true"),e}},{key:"removeEventListener",value:function(){this.el.removeEventListener.apply(this.el,arguments)}},{key:"show",value:function(){s.unshift(this.el),this.returnValue="",this._bind(),this.options.opener=this.options.opener||a||document.activeElement,"svg"===this.options.opener.nodeName&&(this.options.opener=this.options.opener.parentNode),"false"!==this.el.getAttribute("aria-hidden")&&this.el.setAttribute("aria-hidden","false"),this._focus(),1===s.length&&this.options.modal&&!this.documentDisabled?this._disableDocument():this.documentDisabled&&this.options.content&&this._enableLayer()}},{key:"_unbind",value:function(){var e=this;this.el.removeEventListener("click",this._handleClick),this.el.removeEventListener("click",this._handleCancel),this.el.closeBtns&&this.el.closeBtns.forEach(function(t){t.removeEventListener("click",e._handleClose)})}},{key:"_validateModal",value:function(){var e=this.el.getAttribute("aria-label"),t=this.el.getAttribute("aria-describedby"),i=void 0;if((!e||e&&e.trim().length<0)&&(!(i=this.el.querySelector("#"+this.el.getAttribute("aria-labelledby")))||!this.el.contains(i)))throw new Error('No title is present in the layer. Use the "data-label" attribute on the visible title or pass the label using the "label" key when creating the layer.');if("alertdialog"===this.options.role&&!t)throw new Error('"alertdialog" layer needs a description, use the "data-description" attribute on the text content of the layer to validate the layer.')}}]),t}();return document.body.addEventListener("keydown",function(e){s.length&&27===e.keyCode&&s[0].layer._dispatchEvent("cancel")}),document.body.addEventListener("focus",function(e){e.target!==document.body&&(a=e.target)},!0),r}); |
@@ -415,3 +415,4 @@ import inert from './inert'; | ||
// store the current focused element before focusing the layer | ||
this.options.opener = this.options.opener || activeElement; | ||
this.options.opener = this.options.opener || activeElement || document.activeElement; | ||
// IE can't focus a svg element | ||
@@ -418,0 +419,0 @@ if( this.options.opener.nodeName === 'svg' ){ |
{ | ||
"title": "AcceDe Web - overlay", | ||
"name": "@accede-web/overlay", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "WAI-ARIA overlay plugin based on AcceDe Web instructions", | ||
@@ -6,0 +6,0 @@ "main": "dist/overlay.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95488
0.08%0
-100%