blob: 33b6f3eb44903501a102c0d13a54ba813db748af [file] [log] [blame]
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(n,o,function(e){return t[e]}.bind(null,o));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=1)}([function(t,e,i){"use strict";function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t}).apply(this,arguments)}function o(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}i.d(e,"a",(function(){return s}));var s=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);this.config=n({backscroll:!0,linkAttributeName:"data-hystmodal",closeOnOverlay:!0,closeOnEsc:!0,closeOnButton:!0,waitTransitions:!1,catchFocus:!0,fixedSelectors:"*[data-hystfixed]",beforeOpen:function(){},afterClose:function(){}},e),this.config.linkAttributeName&&this.init(),this._closeAfterTransition=this._closeAfterTransition.bind(this)}var e,i,s;return e=t,(i=[{key:"init",value:function(){this.isOpened=!1,this.openedWindow=!1,this.starter=!1,this._nextWindows=!1,this._scrollPosition=0,this._reopenTrigger=!1,this._overlayChecker=!1,this._isMoved=!1,this._focusElements=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],this._modalBlock=!1;var t=document.querySelector(".hystmodal__shadow");t?this.shadow=t:(this.shadow=document.createElement("div"),this.shadow.classList.add("hystmodal__shadow"),document.body.appendChild(this.shadow)),this.eventsFeeler()}},{key:"eventsFeeler",value:function(){document.addEventListener("click",function(t){var e=t.target.closest("["+this.config.linkAttributeName+"]");if(!this._isMoved&&e){t.preventDefault(),this.starter=e;var i=this.starter.getAttribute(this.config.linkAttributeName);return this._nextWindows=document.querySelector(i),void this.open()}this.config.closeOnButton&&t.target.closest("[data-hystclose]")&&this.close()}.bind(this)),this.config.closeOnOverlay&&(document.addEventListener("mousedown",function(t){!this._isMoved&&t.target instanceof Element&&!t.target.classList.contains("hystmodal__wrap")||(this._overlayChecker=!0)}.bind(this)),document.addEventListener("mouseup",function(t){if(!this._isMoved&&t.target instanceof Element&&this._overlayChecker&&t.target.classList.contains("hystmodal__wrap"))return t.preventDefault(),this._overlayChecker,void this.close();this._overlayChecker=!1}.bind(this))),window.addEventListener("keydown",function(t){if(!this._isMoved&&this.config.closeOnEsc&&27==t.which&&this.isOpened)return t.preventDefault(),void this.close();!this._isMoved&&this.config.catchFocus&&9==t.which&&this.isOpened&&this.focusCatcher(t)}.bind(this))}},{key:"open",value:function(t){if(t&&(this._nextWindows="string"==typeof t?document.querySelector(t):t),this._nextWindows){if(this.isOpened)return this._reopenTrigger=!0,void this.close();this.openedWindow=this._nextWindows,this._modalBlock=this.openedWindow.querySelector(".hystmodal__window"),this.config.beforeOpen(this),this._bodyScrollControl(),this.shadow.classList.add("hystmodal__shadow--show"),this.openedWindow.classList.add("hystmodal--active"),this.openedWindow.setAttribute("aria-hidden","false"),this.config.catchFocus&&this.focusControl(),this.isOpened=!0}else console.log("Warning: hystModal selector is not found")}},{key:"close",value:function(){this.isOpened&&(this.config.waitTransitions?(this.openedWindow.classList.add("hystmodal--moved"),this._isMoved=!0,this.openedWindow.addEventListener("transitionend",this._closeAfterTransition),this.openedWindow.classList.remove("hystmodal--active")):(this.openedWindow.classList.remove("hystmodal--active"),this._closeAfterTransition()))}},{key:"_closeAfterTransition",value:function(){this.openedWindow.classList.remove("hystmodal--moved"),this.openedWindow.removeEventListener("transitionend",this._closeAfterTransition),this._isMoved=!1,this.shadow.classList.remove("hystmodal__shadow--show"),this.openedWindow.setAttribute("aria-hidden","true"),this.config.catchFocus&&this.focusControl(),this._bodyScrollControl(),this.isOpened=!1,this.openedWindow.scrollTop=0,this.config.afterClose(this),this._reopenTrigger&&(this._reopenTrigger=!1,this.open())}},{key:"focusControl",value:function(){var t=this.openedWindow.querySelectorAll(this._focusElements);this.isOpened&&this.starter?this.starter.focus():t.length&&t[0].focus()}},{key:"focusCatcher",value:function(t){var e=this.openedWindow.querySelectorAll(this._focusElements),i=Array.prototype.slice.call(e);if(this.openedWindow.contains(document.activeElement)){var n=i.indexOf(document.activeElement);console.log(n),t.shiftKey&&0===n&&(i[i.length-1].focus(),t.preventDefault()),t.shiftKey||n!==i.length-1||(i[0].focus(),t.preventDefault())}else i[0].focus(),t.preventDefault()}},{key:"_bodyScrollControl",value:function(){if(this.config.backscroll){var t=Array.prototype.slice.call(document.querySelectorAll(this.config.fixedSelectors)),e=document.documentElement;if(!0===this.isOpened)return e.classList.remove("hystmodal__opened"),e.style.marginRight="",t.map((function(t){t.style.marginRight=""})),window.scrollTo(0,this._scrollPosition),void(e.style.top="");this._scrollPosition=window.pageYOffset;var i=window.innerWidth-e.clientWidth;e.style.top=-this._scrollPosition+"px",i&&(e.style.marginRight=i+"px",t.map((function(t){t.style.marginRight=parseInt(getComputedStyle(t).marginRight)+i+"px"}))),e.classList.add("hystmodal__opened")}}}])&&o(e.prototype,i),s&&o(e,s),t}()},function(t,e,i){"use strict";i.r(e),function(t){var e=i(0);i(3),i(4);t.HystModal=e.a}.call(this,i(2))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(t){var e=this;do{if(e.matches(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null})},function(t,e,i){}]);