Socket
Socket
Sign inDemoInstall

@stormid/modal

Package Overview
Dependencies
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stormid/modal - npm Package Compare versions

Comparing version 1.0.0-alpha.11 to 1.0.0-alpha.12

2

dist/index.js

@@ -1,2 +0,2 @@

function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},e.apply(this,arguments)}var t={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0},n=["click","keydown"],o=[32,13],a=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],i=function(e){return e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node")},r=function(e,t){var n=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return n||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons?"),n},l=function(e){return[].slice.call(e.querySelectorAll(a.join(",")))},d=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[s()])),e.getState().isOpen&&9===t.keyCode&&c(e.getState())(t)}},c=function(e){return function(t){var n=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===n?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||n!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())}},u=function(e){e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(function(t){return t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")}),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},s=function(e){return function(e){e.isOpen?function(e){e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");var t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),u(e);var n=function(){return e.focusableChildren.length>0&&e.focusableChildren[0].focus()};e.settings.delay?window.setTimeout(n,e.settings.delay):n()}(e):function(e){document.removeEventListener("keydown",e.keyListener),u(e),e.lastFocused.focus()}(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)}},f=function(e){return function(t){var a=t.dialog,i=t.toggles;a&&i&&(t.node.setAttribute("hidden","hidden"),a.getAttribute("aria-label")||a.getAttribute("aria-labelledby")&&document.querySelector("#"+a.getAttribute("aria-labelledby"))||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==a.getAttribute("role")||a.getAttribute("aria-describedby")&&document.querySelector("#"+a.getAttribute("aria-describedby"))||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),i.forEach(function(t){n.forEach(function(n){t.addEventListener(n,function(n){n.keyCode&&!~o.indexOf(n.keyCode)||n.which&&3===n.which||(n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[s()]))})})}))}};module.exports=function(n,o){var a=[].slice.call(document.querySelectorAll(n));return 0===a.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):a.map(function(n){return Object.create(function(t){var n,o=t.node,a=t.settings,c=(n={},{dispatch:function(t,o){n=t?e({},n,t):n,o&&o.forEach(function(e){return e(n)})},getState:function(){return n}});return c.dispatch({settings:a,node:o,dialog:i(o),toggles:r(o,a),focusableChildren:l(o),keyListener:d(c),lastFocused:!1,isOpen:!1},[f(c)]),{getState:c.getState}}({settings:e({},t,n.dataset,o),node:n}))})};
function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},e.apply(this,arguments)}var t={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0},n=["click","keydown"],o=[32,13],i=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],a=function(e){return e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node")},r=function(e,t){var n=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return n||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons?"),n},l=function(e){return[].slice.call(e.querySelectorAll(i.join(",")))},c=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[u()])),e.getState().isOpen&&9===t.keyCode&&d(e.getState())(t)}},d=function(e){return function(t){var n=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===n?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||n!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())}},s=function(e){e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(function(t){return t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")}),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},u=function(e){return function(e){e.isOpen?function(e){e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");var t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),s(e);var n=function(){return e.focusableChildren.length>0&&e.focusableChildren[0].focus()};e.settings.delay?window.setTimeout(n,e.settings.delay):n()}(e):function(e){document.removeEventListener("keydown",e.keyListener),s(e),e.lastFocused.focus()}(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)}},f=function(e){return function(t){var i=t.dialog,a=t.toggles;i&&a&&(t.node.setAttribute("hidden","hidden"),i.getAttribute("aria-label")||i.getAttribute("aria-labelledby")&&document.querySelector("#"+i.getAttribute("aria-labelledby"))||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==i.getAttribute("role")||i.getAttribute("aria-describedby")&&document.querySelector("#"+i.getAttribute("aria-describedby"))||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),a.forEach(function(t){n.forEach(function(n){t.addEventListener(n,function(n){n.keyCode&&!~o.indexOf(n.keyCode)||n.which&&3===n.which||(n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[u()]))})})}))}},b=function(e){return"string"==typeof e?[].slice.call(document.querySelectorAll(e)):e instanceof Array?e:Object.prototype.isPrototypeOf.call(NodeList.prototype,e)?[].slice.call(e):e instanceof HTMLElement?[e]:[]};exports.default=function(n,o){var i=b(n);return 0===i.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):i.map(function(n){return Object.create(function(t){var n,o=t.node,i=t.settings,d=(n={},{dispatch:function(t,o){n=t?e({},n,t):n,o&&o.forEach(function(e){return e(n)})},getState:function(){return n}});return d.dispatch({settings:i,node:o,dialog:a(o),toggles:r(o,i),focusableChildren:l(o),keyListener:c(d),lastFocused:!1,isOpen:!1},[f(d)]),{getState:d.getState}}({settings:e({},t,n.dataset,o),node:n}))})},exports.getSelection=b;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var o in a)Object.prototype.hasOwnProperty.call(a,o)&&(e[o]=a[o])}return e},e.apply(this,arguments)}var t={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0};const a=["click","keydown"],o=[32,13],n=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],l=e=>e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node"),i=(e,t)=>{const a=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return a||console.warn(`Modal cannot be initialised, no modal toggle elements found. Does the modal have a ${t.toggleSelectorAttribute} attribute that identifies toggle buttons?`),a},r=e=>[].slice.call(e.querySelectorAll(n.join(","))),d=e=>t=>{e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[u()])),e.getState().isOpen&&9===t.keyCode&&s(e.getState())(t)},s=e=>t=>{const a=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===a?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||a!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())},c=e=>{e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(t=>t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},u=e=>e=>{e.isOpen?(e=>{e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");const t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),c(e);const a=()=>e.focusableChildren.length>0&&e.focusableChildren[0].focus();e.settings.delay?window.setTimeout(a,e.settings.delay):a()})(e):(e=>{document.removeEventListener("keydown",e.keyListener),c(e),e.lastFocused.focus()})(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)},b=e=>({node:t,dialog:n,toggles:l})=>{n&&l&&(t.setAttribute("hidden","hidden"),n.getAttribute("aria-label")||n.getAttribute("aria-labelledby")&&document.querySelector(`#${n.getAttribute("aria-labelledby")}`)||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==n.getAttribute("role")||n.getAttribute("aria-describedby")&&document.querySelector(`#${n.getAttribute("aria-describedby")}`)||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),l.forEach(t=>{a.forEach(a=>{t.addEventListener(a,a=>{a.keyCode&&!~o.indexOf(a.keyCode)||a.which&&3===a.which||(a.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[u()]))})})}))};var g=(a,o)=>{const n=[].slice.call(document.querySelectorAll(a));return 0===n.length?console.warn(`Modal not initialised, no elements found for selector '${a}'`):n.map(a=>Object.create((({node:t,settings:a})=>{const o=(()=>{let t={};return{dispatch:(a,o)=>{t=a?e({},t,a):t,o&&o.forEach(e=>e(t))},getState:()=>t}})();return o.dispatch({settings:a,node:t,dialog:l(t),toggles:i(t,a),focusableChildren:r(t),keyListener:d(o),lastFocused:!1,isOpen:!1},[b(o)]),{getState:o.getState}})({settings:e({},t,a.dataset,o),node:a})))};export{g as default};
function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var o in a)Object.prototype.hasOwnProperty.call(a,o)&&(e[o]=a[o])}return e},e.apply(this,arguments)}var t={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0};const a=["click","keydown"],o=[32,13],l=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],n=e=>e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node"),i=(e,t)=>{const a=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return a||console.warn(`Modal cannot be initialised, no modal toggle elements found. Does the modal have a ${t.toggleSelectorAttribute} attribute that identifies toggle buttons?`),a},r=e=>[].slice.call(e.querySelectorAll(l.join(","))),d=e=>t=>{e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[u()])),e.getState().isOpen&&9===t.keyCode&&s(e.getState())(t)},s=e=>t=>{const a=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===a?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||a!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())},c=e=>{e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(t=>t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},u=e=>e=>{e.isOpen?(e=>{e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");const t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),c(e);const a=()=>e.focusableChildren.length>0&&e.focusableChildren[0].focus();e.settings.delay?window.setTimeout(a,e.settings.delay):a()})(e):(e=>{document.removeEventListener("keydown",e.keyListener),c(e),e.lastFocused.focus()})(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)},b=e=>({node:t,dialog:l,toggles:n})=>{l&&n&&(t.setAttribute("hidden","hidden"),l.getAttribute("aria-label")||l.getAttribute("aria-labelledby")&&document.querySelector(`#${l.getAttribute("aria-labelledby")}`)||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==l.getAttribute("role")||l.getAttribute("aria-describedby")&&document.querySelector(`#${l.getAttribute("aria-describedby")}`)||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),n.forEach(t=>{a.forEach(a=>{t.addEventListener(a,a=>{a.keyCode&&!~o.indexOf(a.keyCode)||a.which&&3===a.which||(a.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[u()]))})})}))},g=e=>"string"==typeof e?[].slice.call(document.querySelectorAll(e)):e instanceof Array?e:Object.prototype.isPrototypeOf.call(NodeList.prototype,e)?[].slice.call(e):e instanceof HTMLElement?[e]:[];var h=(a,o)=>{let l=g(a);return 0===l.length?console.warn(`Modal not initialised, no elements found for selector '${a}'`):l.map(a=>Object.create((({node:t,settings:a})=>{const o=(()=>{let t={};return{dispatch:(a,o)=>{t=a?e({},t,a):t,o&&o.forEach(e=>e(t))},getState:()=>t}})();return o.dispatch({settings:a,node:t,dialog:n(t),toggles:i(t,a),focusableChildren:r(t),keyListener:d(o),lastFocused:!1,isOpen:!1},[b(o)]),{getState:o.getState}})({settings:e({},t,a.dataset,o),node:a})))};export{h as default,g as getSelection};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).Modal=t()}(this,function(){function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},e.apply(this,arguments)}var t={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0},n=["click","keydown"],o=[32,13],i=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],a=function(e){return e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node")},l=function(e,t){var n=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return n||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons?"),n},r=function(e){return[].slice.call(e.querySelectorAll(i.join(",")))},d=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[s()])),e.getState().isOpen&&9===t.keyCode&&u(e.getState())(t)}},u=function(e){return function(t){var n=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===n?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||n!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())}},c=function(e){e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(function(t){return t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")}),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},s=function(e){return function(e){e.isOpen?function(e){e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");var t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),c(e);var n=function(){return e.focusableChildren.length>0&&e.focusableChildren[0].focus()};e.settings.delay?window.setTimeout(n,e.settings.delay):n()}(e):function(e){document.removeEventListener("keydown",e.keyListener),c(e),e.lastFocused.focus()}(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)}},f=function(e){return function(t){var i=t.dialog,a=t.toggles;i&&a&&(t.node.setAttribute("hidden","hidden"),i.getAttribute("aria-label")||i.getAttribute("aria-labelledby")&&document.querySelector("#"+i.getAttribute("aria-labelledby"))||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==i.getAttribute("role")||i.getAttribute("aria-describedby")&&document.querySelector("#"+i.getAttribute("aria-describedby"))||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),a.forEach(function(t){n.forEach(function(n){t.addEventListener(n,function(n){n.keyCode&&!~o.indexOf(n.keyCode)||n.which&&3===n.which||(n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[s()]))})})}))}};return function(n,o){var i=[].slice.call(document.querySelectorAll(n));return 0===i.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):i.map(function(n){return Object.create(function(t){var n,o=t.node,i=t.settings,u=(n={},{dispatch:function(t,o){n=t?e({},n,t):n,o&&o.forEach(function(e){return e(n)})},getState:function(){return n}});return u.dispatch({settings:i,node:o,dialog:a(o),toggles:l(o,i),focusableChildren:r(o),keyListener:d(u),lastFocused:!1,isOpen:!1},[f(u)]),{getState:u.getState}}({settings:e({},t,n.dataset,o),node:n}))})}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).Modal={})}(this,function(e){function t(){return t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},t.apply(this,arguments)}var n={onClassName:"is--active",toggleSelectorAttribute:"data-modal-toggle",callback:!1,delay:0},o=["click","keydown"],i=[32,13],a=["a[href]","area[href]","input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex="-1"])'],l=function(e){return e.querySelector("[role=dialog]")||e.querySelector("[role=alertdialog]")||console.warn("No dialog or alertdialog found in modal node")},r=function(e,t){var n=e.getAttribute(t.toggleSelectorAttribute)&&[].slice.call(document.querySelectorAll("."+e.getAttribute(t.toggleSelectorAttribute)));return n||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons?"),n},d=function(e){return[].slice.call(e.querySelectorAll(a.join(",")))},c=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[f()])),e.getState().isOpen&&9===t.keyCode&&s(e.getState())(t)}},s=function(e){return function(t){var n=e.focusableChildren.indexOf(document.activeElement);t.shiftKey&&0===n?(t.preventDefault(),e.focusableChildren[e.focusableChildren.length-1].focus()):t.shiftKey||n!==e.focusableChildren.length-1||(t.preventDefault(),e.focusableChildren[0].focus())}},u=function(e){e.node[e.isOpen?"removeAttribute":"setAttribute"]("hidden","hidden"),[].slice.call(document.querySelectorAll("body > *")).forEach(function(t){return t!==e.node&&t[e.isOpen?"setAttribute":"removeAttribute"]("aria-hidden","true")}),e.node.classList.toggle(e.settings.onClassName),document.documentElement.classList.toggle("is--modal")},f=function(e){return function(e){e.isOpen?function(e){e.dialog.hasAttribute("aria-hidden")&&e.dialog.removeAttribute("aria-hidden");var t=document.body.firstElementChild||null;t!==e.node&&document.body.insertBefore(e.node,t),document.addEventListener("keydown",e.keyListener),u(e);var n=function(){return e.focusableChildren.length>0&&e.focusableChildren[0].focus()};e.settings.delay?window.setTimeout(n,e.settings.delay):n()}(e):function(e){document.removeEventListener("keydown",e.keyListener),u(e),e.lastFocused.focus()}(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)}},b=function(e){return function(t){var n=t.dialog,a=t.toggles;n&&a&&(t.node.setAttribute("hidden","hidden"),n.getAttribute("aria-label")||n.getAttribute("aria-labelledby")&&document.querySelector("#"+n.getAttribute("aria-labelledby"))||console.warn("The modal dialog should have an aria-labelledby attribute that matches the id of an element that contains text, or an aria-label attribute."),"alertdialog"!==n.getAttribute("role")||n.getAttribute("aria-describedby")&&document.querySelector("#"+n.getAttribute("aria-describedby"))||console.warn("The alertdialog should have an aria-describedby attribute that matches the id of an element that contains text"),a.forEach(function(t){o.forEach(function(n){t.addEventListener(n,function(n){n.keyCode&&!~i.indexOf(n.keyCode)||n.which&&3===n.which||(n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[f()]))})})}))}},g=function(e){return"string"==typeof e?[].slice.call(document.querySelectorAll(e)):e instanceof Array?e:Object.prototype.isPrototypeOf.call(NodeList.prototype,e)?[].slice.call(e):e instanceof HTMLElement?[e]:[]};e.default=function(e,o){var i=g(e);return 0===i.length?console.warn("Modal not initialised, no elements found for selector '"+e+"'"):i.map(function(e){return Object.create(function(e){var n,o=e.node,i=e.settings,a=(n={},{dispatch:function(e,o){n=e?t({},n,e):n,o&&o.forEach(function(e){return e(n)})},getState:function(){return n}});return a.dispatch({settings:i,node:o,dialog:l(o),toggles:r(o,i),focusableChildren:d(o),keyListener:c(a),lastFocused:!1,isOpen:!1},[b(a)]),{getState:a.getState}}({settings:t({},n,e.dataset,o),node:e}))})},e.getSelection=g});
//# sourceMappingURL=index.umd.js.map
{
"name": "@stormid/modal",
"version": "1.0.0-alpha.11",
"version": "1.0.0-alpha.12",
"description": "Accessible modal dialog",

@@ -31,3 +31,3 @@ "author": "stormid",

},
"gitHead": "c3705f7499d2f5503f914c61ee860a1ba6d4a069"
"gitHead": "5a78d93bb9f509d1af5dcf4d3b3f30bb2cd1583f"
}

@@ -31,9 +31,30 @@ # Modal

Inititialise the module
Import the module
```
import modal from '@stormid/modal';
```
Initialise the module via selector string
```
const [ instance ] = modal('.js-modal');
```
Initialise with a DOM element
```
const element = document.querySelector('.js-modal');
const [ instance ] = modal(element);
```
Initialise with a Node list
```
const elements = document.querySelectorAll('.js-modal');
const [ instance ] = modal(elements);
```
Initialise with an Array of elements
```
const elements = [].slice.call(document.querySelectorAll('.js-modal'));
const [ instance ] = modal(elements);
```
CSS

@@ -40,0 +61,0 @@ The className 'is--modal' added to the document.body when the modal is open. This can be used to prevent the body from scrolling

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc