1 line
6.5 KiB
JavaScript
1 line
6.5 KiB
JavaScript
!function(l,c,u){"use strict";var e={getInstance:function(e,t){return l.offside.factory||(l.offside.factory=n(t)),l.offside.factory.getOffsideInstance(e,t)}};function n(e){var t,h=function(e){0<T.length&&(isNaN(e)?T.forEach(function(e){k[e].close()}):k[e].close())},S=function(){L(D,i)},L=function(e,t){e.classList?e.classList.add(t):e.className=(e.className+" "+t).trim()},A=function(e,t){e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\b)"+t.split(" ").join("|")+"(\\b|$)","gi")," ")},E=function(e,t,n){e.addEventListener(t,n)},O=function(e,t,n){e.removeEventListener(t,n)},q=function(e){return e instanceof HTMLElement?[e]:Array.isArray(e)?e:"string"==typeof e&&Array.apply(null,c.querySelectorAll(e))},x=function(e,t){var n=e.indexOf(t);return-1<n&&n},n={slidingElementsSelector:".offside-sliding-element",disableCss3dTransforms:!1,debug:!1};for(t in e)n.hasOwnProperty(t)&&(n[t]=e[t]);var w="offside-js",o=w+"--init",i=w+"--interact",k=[],C=!0,s=!n.disableCss3dTransforms&&function(){if(!l.getComputedStyle)return!1;var e,t=c.createElement("p"),n={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};for(var o in c.body.insertBefore(t,null),n)t.style[o]!==u&&(t.style[o]="translate3d(1px,1px,1px)",e=l.getComputedStyle(t).getPropertyValue(n[o]));return c.body.removeChild(t),e!==u&&0<e.length&&"none"!==e}(),T=[],D=c.body,r=q(n.slidingElementsSelector),N=n.debug;function a(e,t,n){var o,i={buttonsSelector:"",slidingSide:"left",init:function(){},beforeOpen:function(){},afterOpen:function(){},beforeClose:function(){},afterClose:function(){},beforeDestroy:function(){},afterDestroy:function(){}};for(o in t)i.hasOwnProperty(o)&&(i[o]=t[o]);function s(){(!1===x(T,y)?v:p)()}function r(e){e.preventDefault(),s()}var l=e,a=q(i.buttonsSelector),c=i.slidingSide,u="offside",d=u+"--"+c,f="is-open",m=w+"--is-open",g=w+"--is-"+c,y=n||0,v=function(){i.beforeOpen(),C&&(C=!1,S()),h(),L(D,m),L(D,g),L(l,f),T.push(y),i.afterOpen()},p=function(){var e=x(T,y);!1!==e&&(i.beforeClose(),A(D,m),A(D,g),A(l,f),T.splice(e,1),i.afterClose())},b=function(){l||console.error('Offside alert: "offside" selector could not match any element'),a.length||console.error('Offside alert: "buttonsSelector" selector could not match any element')};this.toggle=function(){s()},this.open=function(){v()},this.close=function(){p()},this.closeAll=function(){h()},this.destroy=function(){i.beforeDestroy(),p(),a.forEach(function(e){O(e,"click",r)}),A(l,u),A(l,d),delete k[y],i.afterDestroy()},N&&b(),L(l,u),L(l,d),a.forEach(function(e){E(e,"click",r)}),i.init()}return r.forEach(function(e){L(e,"offside-sliding-element")}),s||L(c.documentElement,"no-csstransforms3d"),L(D,o),{closeOpenOffside:function(){h()},getOffsideInstance:function(e,t){var n,o,i,s,r=k.length||0,l=(o=t,i=r,!1!==(s=q((n=e)!==u?n:".offside"))?new a(s[0],o,i):null);if(null!==l)return k[r]=l}}}"undefined"!=typeof module&&module.exports?module.exports=e.getInstance:l.offside=e.getInstance}(window,document),document.addEventListener("DOMContentLoaded",function(){document.querySelector(".slideout-navigation").style.display=""});for(var generateOffside=offside(".slideout-navigation",{slidingElementsSelector:"#slideout-container",buttonsSelector:".slideout-mobile .main-navigation .menu-toggle, .slideout-both .main-navigation .menu-toggle, .slideout-both .slideout-toggle, .slideout-desktop .slideout-toggle",slidingSide:offSide.side,beforeOpen:function(){document.querySelector(".slideout-navigation").style.visibility="visible"},afterOpen:function(){if(document.documentElement.classList.add("slide-opened"),document.body.classList.add("slide-opened"),document.body.classList.contains("dropdown-hover"))for(var e=document.querySelector(".slideout-navigation").querySelectorAll("li.menu-item-has-children"),t=0;t<e.length;t++){var n=e[t].querySelector("span.dropdown-menu-toggle");n&&(n.setAttribute("tabindex",0),n.setAttribute("role","button"),n.setAttribute("aria-expanded",!0))}document.querySelector(".slideout-navigation").removeAttribute("aria-hidden");var o=document.querySelector(".slideout-navigation").querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');o&&setTimeout(function(){o[0].focus()},200)},afterClose:function(){for(var e=document.body,t=document.querySelectorAll(".main-navigation"),n=0;n<t.length;n++)t[n].classList.contains("toggled")&&t[n].classList.remove("toggled");if(document.documentElement.classList.remove("slide-opened"),e.classList.remove("slide-opened"),"true"===document.querySelector(".main-navigation .menu-toggle").getAttribute("aria-expanded")&&document.querySelector(".main-navigation .menu-toggle").setAttribute("aria-expanded",!1),e.classList.contains("dropdown-hover"))for(var o=document.querySelector(".main-navigation:not(.slideout-navigation):not(.mobile-menu-control-wrapper)").querySelectorAll("li.menu-item-has-children"),n=0;n<o.length;n++){var i=o[n].querySelector("span.dropdown-menu-toggle");i&&(i.removeAttribute("tabindex"),i.setAttribute("role","presentation"),i.removeAttribute("aria-expanded"))}setTimeout(function(){document.querySelector(".slideout-navigation:not(.is-open)").style.visibility="",document.querySelector(".slideout-navigation:not(.is-open)").setAttribute("aria-hidden","true")},500),window.document.documentElement.clientWidth<=768?(e.classList.contains("slideout-mobile")||e.classList.contains("slideout-both"))&&document.querySelectorAll(".main-navigation:not(.slideout-navigation)").forEach(function(e){e&&"none"!==e.style.display&&e.querySelector(".menu-toggle").focus()}):(e.classList.contains("slideout-desktop")||e.classList.contains("slideout-both"))&&document.querySelectorAll(".main-navigation:not(.slideout-navigation)").forEach(function(e){e&&"none"!==e.style.display&&e.querySelector(".slideout-toggle a").focus()})}}),closeElements=document.querySelectorAll(".slideout-overlay, .slideout-exit, .slider-exit a"),i=0;i<closeElements.length;i++)closeElements[i].addEventListener("click",function(e){e.preventDefault(),generateOffside.close()});for(var slideoutLinks=document.querySelectorAll(".slideout-navigation ul a"),closeOffsideOnAction=function(){var e=this.getAttribute("href");"#"===e||""===e||navigator.userAgent.match(/iemobile/i)||setTimeout(function(){generateOffside.close()},200)},i=0;i<slideoutLinks.length;i++)slideoutLinks[i].addEventListener("click",closeOffsideOnAction,!1);document.addEventListener("keyup",function(e){document.body.classList.contains("slide-opened")&&27==(e=e||window.event).keyCode&&generateOffside.close()}); |