@stormid/modal
Advanced tools
Comparing version 1.0.0-alpha.14 to 1.0.0-alpha.15
@@ -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=["button","a"],o=["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")},i=function(e,t){var o,a=e.getAttribute(t.toggleSelectorAttribute),i=a&&[].slice.call(document.querySelectorAll((o=a,n.map(function(e){return e+"."+o}).join(", "))));return i||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons or anchors?"),i},r=function(e){return[].slice.call(e.querySelectorAll(o.join(",")))},l=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())}},d=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),d(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),d(e),e.lastFocused.focus()}(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)}},u=function(e){return function(t){var n=t.dialog,o=t.toggles;n&&o&&(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"),o.forEach(function(t){t.addEventListener("click",function(n){n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[s()])})}))}};module.exports=function(n,o){var c=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]:[]}(n);return 0===c.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):c.map(function(n){return Object.create(function(t){var n,o=t.node,c=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:c,node:o,dialog:a(o),toggles:i(o,c),focusableChildren:r(o),keyListener:l(d),lastFocused:!1,isOpen:!1},[u(d)]),{getState:d.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,startOpen:!1,delay:0},n=["button","a"],o=["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")},i=function(e,t){var o,a=e.getAttribute(t.toggleSelectorAttribute),i=a&&[].slice.call(document.querySelectorAll((o=a,n.map(function(e){return e+"."+o}).join(", "))));return i||console.warn("Modal cannot be initialised, no modal toggle elements found. Does the modal have a "+t.toggleSelectorAttribute+" attribute that identifies toggle buttons or anchors?"),i},r=function(e){return[].slice.call(e.querySelectorAll(o.join(",")))},l=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[s(e)])),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(t){t.isOpen?function(e){return function(){var t=e.getState();t.dialog.hasAttribute("aria-hidden")&&t.dialog.removeAttribute("aria-hidden");var n=document.body.firstElementChild||null;n!==t.node&&document.body.insertBefore(t.node,n),document.addEventListener("keydown",t.keyListener),u(t);var o=function(){return t.focusableChildren.length>0&&t.focusableChildren[0].focus()};t.settings.delay?window.setTimeout(o,t.settings.delay):o()}}(e)():function(e){return function(){var t=e.getState();document.removeEventListener("keydown",t.keyListener),u(t),t.lastFocused.focus()}}(e)(t),"function"==typeof t.settings.callback&&t.settings.callback.call(t)}},d=function(e){return function(t){var n=t.dialog,o=t.toggles;n&&o&&(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"),o.forEach(function(t){t.addEventListener("click",function(t){t.preventDefault(),f(e)})}))}},f=function(e){return e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:document.activeElement},[s(e)])};module.exports=function(n,o){var c=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]:[]}(n);return 0===c.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):c.map(function(n){return Object.create(function(t){var n,o=t.node,c=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:c,node:o,dialog:a(o),toggles:i(o,c),focusableChildren:r(o),keyListener:l(u),lastFocused:!1,isOpen:!1},[d(u),function(){return c.startOpen&&f(u)}]),{getState:u.getState,open:function(){u.getState().isOpen||f(u)},close:function(){u.getState().isOpen&&f(u)}}}({settings:e({},t,n.dataset,o),node:n}))})}; | ||
//# 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=["button","a"],o=["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"),l=(e,t)=>{const o=e.getAttribute(t.toggleSelectorAttribute),n=o&&[].slice.call(document.querySelectorAll((l=o,a.map(e=>`${e}.${l}`).join(", "))));var l;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 or anchors?`),n},i=e=>[].slice.call(e.querySelectorAll(o.join(","))),r=e=>t=>{e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[c()])),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())},d=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")},c=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),d(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),d(e),e.lastFocused.focus()})(e),"function"==typeof e.settings.callback&&e.settings.callback.call(e)},u=e=>({node:t,dialog:a,toggles:o})=>{a&&o&&(t.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"),o.forEach(t=>{t.addEventListener("click",a=>{a.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[c()])})}))};var b=(a,o)=>{let s=(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]:[])(a);return 0===s.length?console.warn(`Modal not initialised, no elements found for selector '${a}'`):s.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:l(t,a),focusableChildren:i(t),keyListener:r(o),lastFocused:!1,isOpen:!1},[u(o)]),{getState:o.getState}})({settings:e({},t,a.dataset,o),node:a})))};export{b 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,startOpen:!1,delay:0};const a=["button","a"],o=["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"),l=(e,t)=>{const o=e.getAttribute(t.toggleSelectorAttribute),n=o&&[].slice.call(document.querySelectorAll((l=o,a.map(e=>`${e}.${l}`).join(", "))));var l;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 or anchors?`),n},i=e=>[].slice.call(e.querySelectorAll(o.join(","))),r=e=>t=>{e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[c(e)])),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())},d=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")},c=e=>t=>{t.isOpen?(e=>()=>{const t=e.getState();t.dialog.hasAttribute("aria-hidden")&&t.dialog.removeAttribute("aria-hidden");const a=document.body.firstElementChild||null;a!==t.node&&document.body.insertBefore(t.node,a),document.addEventListener("keydown",t.keyListener),d(t);const o=()=>t.focusableChildren.length>0&&t.focusableChildren[0].focus();t.settings.delay?window.setTimeout(o,t.settings.delay):o()})(e)():(e=>()=>{const t=e.getState();document.removeEventListener("keydown",t.keyListener),d(t),t.lastFocused.focus()})(e)(t),"function"==typeof t.settings.callback&&t.settings.callback.call(t)},u=e=>({node:t,dialog:a,toggles:o})=>{a&&o&&(t.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"),o.forEach(t=>{t.addEventListener("click",t=>{t.preventDefault(),g(e)})}))},g=e=>e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:document.activeElement},[c(e)]);var b=(a,o)=>{let s=(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]:[])(a);return 0===s.length?console.warn(`Modal not initialised, no elements found for selector '${a}'`):s.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:l(t,a),focusableChildren:i(t),keyListener:r(o),lastFocused:!1,isOpen:!1},[u(o),()=>a.startOpen&&g(o)]),{getState:o.getState,open(){o.getState().isOpen||g(o)},close(){o.getState().isOpen&&g(o)}}})({settings:e({},t,a.dataset,o),node:a})))};export{b as default}; | ||
//# 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=["button","a"],o=["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")},a=function(e,t){var o,i=e.getAttribute(t.toggleSelectorAttribute),a=i&&[].slice.call(document.querySelectorAll((o=i,n.map(function(e){return e+"."+o}).join(", "))));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 or anchors?"),a},r=function(e){return[].slice.call(e.querySelectorAll(o.join(",")))},l=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&&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())}},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)}},u=function(e){return function(t){var n=t.dialog,o=t.toggles;n&&o&&(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"),o.forEach(function(t){t.addEventListener("click",function(n){n.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:t},[s()])})}))}};return function(n,o){var d=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]:[]}(n);return 0===d.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):d.map(function(n){return Object.create(function(t){var n,o=t.node,d=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:d,node:o,dialog:i(o),toggles:a(o,d),focusableChildren:r(o),keyListener:l(c),lastFocused:!1,isOpen:!1},[u(c)]),{getState:c.getState}}({settings:e({},t,n.dataset,o),node:n}))})}}); | ||
!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,startOpen:!1,delay:0},n=["button","a"],o=["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")},a=function(e,t){var o,i=e.getAttribute(t.toggleSelectorAttribute),a=i&&[].slice.call(document.querySelectorAll((o=i,n.map(function(e){return e+"."+o}).join(", "))));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 or anchors?"),a},r=function(e){return[].slice.call(e.querySelectorAll(o.join(",")))},l=function(e){return function(t){e.getState().isOpen&&27===t.keyCode&&(t.preventDefault(),e.dispatch({isOpen:!e.getState().isOpen},[d(e)])),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")},d=function(e){return function(t){t.isOpen?function(e){return function(){var t=e.getState();t.dialog.hasAttribute("aria-hidden")&&t.dialog.removeAttribute("aria-hidden");var n=document.body.firstElementChild||null;n!==t.node&&document.body.insertBefore(t.node,n),document.addEventListener("keydown",t.keyListener),c(t);var o=function(){return t.focusableChildren.length>0&&t.focusableChildren[0].focus()};t.settings.delay?window.setTimeout(o,t.settings.delay):o()}}(e)():function(e){return function(){var t=e.getState();document.removeEventListener("keydown",t.keyListener),c(t),t.lastFocused.focus()}}(e)(t),"function"==typeof t.settings.callback&&t.settings.callback.call(t)}},s=function(e){return function(t){var n=t.dialog,o=t.toggles;n&&o&&(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"),o.forEach(function(t){t.addEventListener("click",function(t){t.preventDefault(),f(e)})}))}},f=function(e){return e.dispatch({isOpen:!e.getState().isOpen,lastFocused:e.getState().isOpen?e.getState().lastFocused:document.activeElement},[d(e)])};return function(n,o){var u=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]:[]}(n);return 0===u.length?console.warn("Modal not initialised, no elements found for selector '"+n+"'"):u.map(function(n){return Object.create(function(t){var n,o=t.node,u=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:u,node:o,dialog:i(o),toggles:a(o,u),focusableChildren:r(o),keyListener:l(c),lastFocused:!1,isOpen:!1},[s(c),function(){return u.startOpen&&f(c)}]),{getState:c.getState,open:function(){c.getState().isOpen||f(c)},close:function(){c.getState().isOpen&&f(c)}}}({settings:e({},t,n.dataset,o),node:n}))})}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@stormid/modal", | ||
"version": "1.0.0-alpha.14", | ||
"version": "1.0.0-alpha.15", | ||
"description": "Accessible modal dialog", | ||
@@ -31,3 +31,3 @@ "author": "stormid", | ||
}, | ||
"gitHead": "6e2923743422269752805b8b3af74360ed699709" | ||
"gitHead": "e20e59e71f23ebd29789d519c1b2a7cf5cfa78a7" | ||
} |
@@ -69,2 +69,3 @@ # Modal | ||
## Options | ||
Options can be set during initialising in an Object passed as the second argument to the modal function, e.g. `modal('.js-modal', { startOpen: true })`, or as data-attributes on the modal element (the element passed to the modal function), e.g. `data-start-open="true"` | ||
``` | ||
@@ -75,3 +76,4 @@ { | ||
callback: false, //optional function called after modal state change | ||
delay: 0 //ms delay before focus on first focuable element | ||
delay: 0, //ms delay before focus on first focuable element | ||
startOpen //boolean, to trigger modal to open when initialised | ||
} | ||
@@ -85,2 +87,4 @@ ``` | ||
getState, a Function that returns the current state Object | ||
open, a Function that opens the modal | ||
close a Function that closes the modal | ||
} | ||
@@ -87,0 +91,0 @@ ``` |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84722
72
96