UNPKG

@hydrogen-design-system/component-dialog

Version:
1 lines 6.59 kB
!function r(i,l,c){function s(t,e){if(!l[t]){if(!i[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(u)return u(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var a=l[t]={exports:{}};i[t][0].call(a.exports,function(e){return s(i[t][1][e]||e)},a,a.exports,r,i,l,c)}return l[t].exports}for(var u="function"==typeof require&&require,e=0;e<c.length;e++)s(c[e]);return s}({1:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.h2CoreDocumentReady=function(e){"loading"!=document.readyState?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent("onreadystatechange",function(){"complete"==document.readyState&&e()})}},{}],2:[function(e,t,o){"use strict";var n=e("./core"),a=e("./module");(0,n.h2CoreDocumentReady)(function(){(0,a.h2DialogResizeOnViewport0022)("all"),(0,a.h2DialogTrigger0022)("all"),(0,a.h2DialogEnableOpenDialogs0022)("all")})},{"./core":1,"./module":3}],3:[function(e,t,o){"use strict";function a(t,e,o,n,a){var r=[];if("all"!=e)return null==e||0==e||""==e?(console.log("Hydrogen ("+a+'): no target has been specified. Please pass an HTMLelement object, a NodeList of elements, or "all".'),!1):e.nodeType==Node.ELEMENT_NODE?(null!=n?r.push(e.querySelector(n)):r.push(e),r):1==NodeList.prototype.isPrototypeOf(e)?(e.forEach(function(e){null!=n?r.push(e.querySelector(n)):r.push(e)}),r):(console.log("Hydrogen ("+a+"): you've passed an invalid target format. Targets must be a valid HTMLelement object or NodeList of elements."),!1);if("latest"==t)return r=null!=n?document.querySelectorAll(o+" "+n):document.querySelectorAll(o);if(null==t||0==t||""==t)return console.log("Hydrogen ("+a+'): no version value has been specified. Please specify "latest" or a version number.'),!1;return(null!=n?document.querySelectorAll(o+" "+n):document.querySelectorAll(o)).forEach(function(e){e.closest("[data-h2-system]").getAttribute("data-h2-system")==t&&r.push(e)}),0==r.length?(console.log("Hydrogen ("+a+"): no components were found within the system version you've specified. Please double check the version value being passed matches the version of the system installation on your project."),!1):r}function r(e){var t=document.querySelector("[data-h2-dialog-overlay-0022]");document.querySelector("body").style.overflow="hidden",t.classList.add("h2-active"),l(e),e.querySelectorAll("[data-h2-accordion-trigger]").forEach(function(e){e.removeEventListener("click",u),e.addEventListener("click",u)}),e.setAttribute("aria-hidden","false"),e.setAttribute("tabindex",0);var o="";(o=null!=e.querySelector("[data-h2-focus]")?e.querySelector("[data-h2-focus]"):e.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")[0]).setAttribute("tabindex","0");var n=e.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");n.forEach(function(e){e.setAttribute("tabindex",0)}),null!=o&&o.focus(),c(n),document.removeEventListener("keyup",s),document.addEventListener("keyup",s)}function i(e){var t=document.querySelector("[data-h2-dialog-overlay-0022]");document.querySelector("body").style.overflow="visible",t.classList.remove("h2-active"),e.querySelectorAll("[data-h2-accordion-trigger]").forEach(function(e){e.removeEventListener("click",u)}),e.classList.remove("h2-dialog-overflowing"),e.classList.remove("h2-dialog-contained"),e.classList.remove("h2-active"),e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex",-1),e.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])").forEach(function(e){e.setAttribute("tabindex",-1)}),document.removeEventListener("keyup",s);var o=document.querySelector("[data-h2-dialog-ancestor]");0==o||null==o?document.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")[0].focus():o.focus()}function l(e){e.classList.add("h2-dialog-height"),window.innerHeight<e.querySelector("[data-h2-dialog-wrapper]").offsetHeight+50?(e.classList.remove("h2-dialog-contained"),e.classList.add("h2-active"),e.classList.add("h2-dialog-overflowing")):(e.classList.remove("h2-dialog-overflowing"),e.classList.add("h2-active"),e.classList.add("h2-dialog-contained"))}function c(e){e.forEach(function(e){e.removeEventListener("keydown",n),e.addEventListener("keydown",n)})}function s(e){27==(e.keyCode||e.which)&&document.querySelectorAll("[data-h2-dialog-0022]").forEach(function(e){i(e)})}function u(e){e.preventDefault(),l(e.target.closest("[data-h2-dialog-0022]"))}function n(e){var t=e.keyCode||e.which,o=e.currentTarget.closest("[data-h2-dialog-0022]").querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])"),n=o[0],a=o[o.length-1];9!=t||e.shiftKey?9==t&&e.shiftKey&&n==document.activeElement&&(e.preventDefault(),a.focus()):a==document.activeElement&&(e.preventDefault(),n.focus())}function d(e){e.preventDefault();var t=e.currentTarget,o=t.getAttribute("data-h2-dialog-trigger-0022"),n=document.querySelector("[data-h2-dialog-0022*='"+o+"']");n.classList.contains("h2-active")?0==n.hasAttribute("data-h2-no-js")&&i(n):0==n.hasAttribute("data-h2-no-js")&&(r(n),document.querySelectorAll("[data-h2-dialog-ancestor]").forEach(function(e){e.removeAttribute("data-h2-dialog-ancestor")}),t.setAttribute("data-h2-dialog-ancestor",""))}Object.defineProperty(o,"__esModule",{value:!0}),o.h2DialogOpenHandler0022=r,o.h2DialogCloseHandler0022=i,o.h2DialogSizeCheckHandler0022=l,o.h2DialogEscapeKeyEvent0022=s,o.h2DialogResizeOnClickEvent0022=u,o.h2DialogTabEvent0022=n,o.h2DialogTabLoopHandler0022=c,o.h2DialogToggleEvent0022=d,o.h2DialogResizeOnViewport0022=function(o){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"latest";window.onresize=function(e){e.preventDefault();var t=a(n,o,"[data-h2-dialog-0022]",null,"Dialog / Check Dialog Size on Viewport Change");0<t.length&&0!=t&&t.forEach(function(e){e.classList.contains("h2-active")&&0==e.hasAttribute("data-h2-no-js")&&l(e)})}},o.h2DialogTrigger0022=function(e){var t=a(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"latest",e,"[data-h2-dialog-trigger-0022]",null,"Dialog / Enable Dialog Buttons");0<t.length&&0!=t&&t.forEach(function(e){e.removeEventListener("click",d),e.addEventListener("click",d)})},o.h2DialogEnableOpenDialogs0022=function(e){var t=a(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"latest",e,"[data-h2-dialog-0022]",null,"Dialog / Enable Open Dialogs");0<t.length&&0!=t&&t.forEach(function(e){e.classList.contains("h2-active")&&r(e)})}},{}]},{},[2]);