@stormid/modal
Advanced tools
Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.11
@@ -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)},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],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}))})}; | ||
//# 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)},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],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}; | ||
//# 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")},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(",")))},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)},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:r(o,i),focusableChildren:l(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?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}))})}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@stormid/modal", | ||
"version": "1.0.0-alpha.10", | ||
"version": "1.0.0-alpha.11", | ||
"description": "Accessible modal dialog", | ||
@@ -31,3 +31,3 @@ "author": "stormid", | ||
}, | ||
"gitHead": "9042db4005411c4360ba3e8188e03333c10098f2" | ||
"gitHead": "c3705f7499d2f5503f914c61ee860a1ba6d4a069" | ||
} |
@@ -13,3 +13,3 @@ # Modal | ||
<div id="modal-1" class="js-modal modal" data-modal-toggle="js-modal-toggle" hidden> | ||
<div class="modal__inner" role="dialog" aria-modal="true" aria-labelledby="modal-label"> | ||
<div class="modal__inner" role="dialog" aria-labelledby="modal-label"> | ||
<h2 id="modal-label">Modal title</h2> | ||
@@ -39,2 +39,11 @@ ... | ||
CSS | ||
The className 'is--modal' added to the document.body when the modal is open. This can be used to prevent the body from scrolling | ||
``` | ||
.is--modal { | ||
overflow: hidden; | ||
} | ||
``` | ||
## Options | ||
@@ -41,0 +50,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
77105
11
68
71