-
Notifications
You must be signed in to change notification settings - Fork 0
/
site-min.js
8 lines (8 loc) · 9.91 KB
/
site-min.js
1
2
3
4
5
6
7
8
/*! responsive-nav.js 1.0.39
* https://github.com/viljamis/responsive-nav.js
* http://responsive-nav.com
*
* Copyright (c) 2015 @viljamis
* Available under the MIT license
*/
!function(e,t,n){"use strict";var o=function(o,s){!!t.getComputedStyle||(t.getComputedStyle=function(e){return this.el=e,this.getPropertyValue=function(t){var n=/(\-([a-z]){1})/g;return"float"===t&&(t="styleFloat"),n.test(t)&&(t=t.replace(n,(function(){return arguments[2].toUpperCase()}))),e.currentStyle[t]?e.currentStyle[t]:null},this});var a,i,r,l,c,u,d,p=function(e,t,n,o){if("addEventListener"in e)try{e.addEventListener(t,n,o)}catch(s){if("object"!=typeof n||!n.handleEvent)throw s;e.addEventListener(t,(function(e){n.handleEvent.call(n,e)}),o)}else"attachEvent"in e&&("object"==typeof n&&n.handleEvent?e.attachEvent("on"+t,(function(){n.handleEvent.call(n)})):e.attachEvent("on"+t,n))},h=function(e,t,n,o){if("removeEventListener"in e)try{e.removeEventListener(t,n,o)}catch(s){if("object"!=typeof n||!n.handleEvent)throw s;e.removeEventListener(t,(function(e){n.handleEvent.call(n,e)}),o)}else"detachEvent"in e&&("object"==typeof n&&n.handleEvent?e.detachEvent("on"+t,(function(){n.handleEvent.call(n)})):e.detachEvent("on"+t,n))},g=function(e,t){for(var n in t)e.setAttribute(n,t[n])},v=function(e,t){0!==e.className.indexOf(t)&&(e.className+=" "+t,e.className=e.className.replace(/(^\s*)|(\s*$)/g,""))},f=function(e,t){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ").replace(/(^\s*)|(\s*$)/g,"")},m=function(e,t,n){for(var o=0;o<e.length;o++)t.call(n,o,e[o])},y=function(e,t){return e.className&&new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className)},b=function(){for(var e=this,t=i.menuItems;-1===e.className.indexOf(t);)"li"===e.tagName.toLowerCase()&&(-1!==e.className.indexOf("focus")?e.className=e.className.replace(" focus",""):e.className+=" focus"),e=e.parentElement},w=e.createElement("style"),E=e.documentElement,x=function(t,n){var o;for(o in this.options={animate:!1,transition:284,label:"Menu",insert:"before",customToggle:"",closeOnNavClick:!0,openPos:"relative",navClass:"nav-wrapper",navActiveClass:"js-nav-active",jsClass:"js",enableFocus:!0,enableDropdown:!0,menuItems:"menu-items",subMenu:"sub-menu",openDropdown:"Open submenu",closeDropdown:"Close sub menu",init:function(){},open:function(){},close:function(){},resizeMobile:function(){},resizeDesktop:function(){}},n)this.options[o]=n[o];if(v(E,this.options.jsClass),this.wrapperEl=t.replace("#",""),e.getElementById(this.wrapperEl))this.wrapper=e.getElementById(this.wrapperEl);else{if(!e.querySelector(this.wrapperEl))throw new Error("The nav element you are trying to select doesn't exist");this.wrapper=e.querySelector(this.wrapperEl)}this.wrapper.inner=function(e){if(e.children.length<1)throw new Error("The Nav container has no containing elements");for(var t=[],n=0;n<e.children.length;n++)1===e.children[n].nodeType&&t.push(e.children[n]);return t}(this.wrapper),i=this.options,a=this.wrapper,this._init(this)};return x.prototype={destroy:function(){if(this._removeStyles(),f(a,"closed"),f(a,"opened"),f(a,i.navClass),f(a,i.navClass+"-"+this.index),f(E,i.navActiveClass),a.removeAttribute("style"),a.removeAttribute("aria-hidden"),h(t,"resize",this,!1),h(t,"focus",this,!1),h(e.body,"touchmove",this,!1),h(r,"touchstart",this,!1),h(r,"touchend",this,!1),h(r,"mouseup",this,!1),h(r,"keyup",this,!1),h(r,"click",this,!1),i.customToggle?r.removeAttribute("aria-hidden"):r.parentNode.removeChild(r),i.enableDropdown){var n=this;m(d,(function(e,t){h(t,"touchstart",n,!1),h(t,"touchend",n,!1),h(t,"mouseup",n,!1),h(t,"keyup",n,!1),h(t,"click",n,!1)}))}},toggle:function(){!0===l&&(u?this.close():this.open())},open:function(){u||(f(a,"closed"),v(a,"opened"),v(E,i.navActiveClass),v(r,"active"),a.style.position=i.openPos,g(a,{"aria-hidden":"false"}),g(a,{"aria-expanded":"true"}),g(r,{"aria-expanded":"true"}),u=!0,i.open())},close:function(){u&&(v(a,"closed"),f(a,"opened"),f(E,i.navActiveClass),f(r,"active"),g(a,{"aria-hidden":"true"}),g(a,{"aria-expanded":"false"}),g(r,{"aria-expanded":"false"}),i.animate?(l=!1,setTimeout((function(){a.style.position="absolute",l=!0,i.enableDropdown&&(f(a,"dropdown-active"),m(d,(function(e,t){f(t,"toggled"),f(t.nextSibling,"toggled")})))}),i.transition+10)):(a.style.position="absolute",i.enableDropdown&&(f(a,"dropdown-active"),m(d,(function(e,t){f(t,"toggled"),f(t.nextSibling,"toggled")})))),u=!1,i.close())},resize:function(){"none"!==t.getComputedStyle(r,null).getPropertyValue("display")?(c=!0,g(r,{"aria-hidden":"false"}),g(a,{"aria-expanded":"false"}),g(r,{"aria-expanded":"false"}),a.className.match(/(^|\s)closed(\s|$)/)&&(g(a,{"aria-hidden":"true"}),a.style.position="absolute"),a.className.match(/(^|\s)closed(\s|$)/)||(g(a,{"aria-expanded":"true"}),g(r,{"aria-expanded":"true"})),this._createStyles(),this._calcHeight(),i.resizeMobile()):(c=!1,g(r,{"aria-hidden":"true"}),g(a,{"aria-hidden":"false"}),a.removeAttribute("aria-expanded"),r.removeAttribute("aria-expanded"),a.style.position=i.openPos,this._removeStyles(),i.resizeDesktop())},handleEvent:function(e){var n=e||t.event;switch(n.type){case"touchstart":this._onTouchStart(n);break;case"touchmove":this._onTouchMove(n);break;case"touchend":case"mouseup":this._onTouchEnd(n);break;case"click":this._preventDefault(n);break;case"keyup":this._onKeyUp(n);break;case"focus":case"resize":this.resize(n)}},_init:function(){this.index=n++,v(a,i.navClass),v(a,i.navClass+"-"+this.index),v(a,"closed"),l=!0,u=!1,this._closeOnNavClick(),this._createToggle(),this._transitions(),this.resize(),this._createFocus(),this._createDropdown();var o=this;setTimeout((function(){o.resize()}),20),p(t,"resize",this,!1),p(t,"focus",this,!1),p(e.body,"touchmove",this,!1),p(r,"touchstart",this,!1),p(r,"touchend",this,!1),p(r,"mouseup",this,!1),p(r,"keyup",this,!1),p(r,"click",this,!1),i.init()},_createStyles:function(){w.parentNode||(w.type="text/css",e.getElementsByTagName("head")[0].appendChild(w))},_removeStyles:function(){w.parentNode&&w.parentNode.removeChild(w)},_createToggle:function(){if(i.customToggle){var t=i.customToggle.replace("#","");if(e.getElementById(t))r=e.getElementById(t);else{if(!e.querySelector(t))throw new Error("The custom nav toggle you are trying to select doesn't exist");r=e.querySelector(t)}}else{var n=e.createElement("a");n.innerHTML=i.label,g(n,{href:"#",class:"nav-toggle"}),"after"===i.insert?a.parentNode.insertBefore(n,a.nextSibling):a.parentNode.insertBefore(n,a),r=n}},_closeOnNavClick:function(){if(i.closeOnNavClick){var e=a.getElementsByTagName("a"),t=this;m(e,(function(n,o){p(e[n],"click",(function(){c&&t.toggle()}),!1)}))}},_preventDefault:function(e){if(e.preventDefault)return e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.preventDefault(),e.stopPropagation(),!1;e.returnValue=!1},_onTouchStart:function(e){Event.prototype.stopImmediatePropagation||this._preventDefault(e),this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY,this.touchHasMoved=!1,h(r,"mouseup",this,!1)},_onTouchMove:function(e){(Math.abs(e.touches[0].clientX-this.startX)>10||Math.abs(e.touches[0].clientY-this.startY)>10)&&(this.touchHasMoved=!0)},_onTouchEnd:function(e){if(this._preventDefault(e),c){var n=e||t.event,o=n.target||n.srcElement,s=!1;if(y(o,"dropdown-toggle")&&i.enableDropdown&&(s=!0),!this.touchHasMoved){if("touchend"===e.type)return void(s?this._toggleDropdown(o):this.toggle());var a=e||t.event;3!==a.which&&2!==a.button&&(s?this._toggleDropdown(o):this.toggle())}}},_onKeyUp:function(e){var n=e||t.event,o=e.target,s=!1;y(o,"dropdown-toggle")&&i.enableDropdown&&(s=!0),13===n.keyCode&&(s?this._toggleDropdown(o):this.toggle())},_transitions:function(){if(i.animate){var e=a.style,t="max-height "+i.transition+"ms, visibility "+i.transition+"ms linear";e.WebkitTransition=e.MozTransition=e.OTransition=e.transition=t}},_calcHeight:function(){for(var e=0,t=0;t<a.inner.length;t++)e+=a.inner[t].offsetHeight;var n="."+i.jsClass+" ."+i.navClass+"-"+this.index+".opened{max-height:"+e+"px !important} ."+i.jsClass+" ."+i.navClass+"-"+this.index+".opened.dropdown-active {max-height:9999px !important}";w.styleSheet?w.styleSheet.cssText=n:w.innerHTML=n,n=""},_createFocus:function(){if(i.enableFocus){var e,t,n=a.getElementsByTagName("ul")[0].getElementsByTagName("a");for(t=0,e=n.length;t<e;t++)n[t].addEventListener("focus",b,!0),n[t].addEventListener("blur",b,!0)}},_createDropdown:function(){if(i.enableDropdown){var e,t,n=this,o=(a.getElementsByTagName("ul")[0],a.getElementsByClassName(i.subMenu));for(v(a,"multiple-level-nav"),e=0,t=o.length;e<t;e++)o[e].parentNode.setAttribute("aria-haspopup","true"),o[e].insertAdjacentHTML("beforebegin",'<button class="dropdown-toggle" aria-expanded="false">'+i.openDropdown+"</button>");d=a.querySelectorAll(".dropdown-toggle"),m(d,(function(e,t){p(t,"touchstart",n,!1),p(t,"touchend",n,!1),p(t,"mouseup",n,!1),p(t,"keyup",n,!1),p(t,"click",n,!1)}))}},_toggleDropdown:function(e){e.innerHTML===i.openDropdown?e.innerHTML=i.closeDropdown:e.innerHTML=i.openDropdown;var t=e.parentNode;y(t.parentNode.parentNode,"dropdown");if(y(e,"toggled")){f(e,"toggled"),e.setAttribute("aria-expanded","false");n=e.nextElementSibling;f(n,"toggled"),f(a,"dropdown-active")}else{v(e,"toggled"),e.setAttribute("aria-expanded","true");var n=e.nextElementSibling;v(n,"toggled"),v(a,"dropdown-active")}}},new x(o,s)};"undefined"!=typeof module&&module.exports?module.exports=o:t.responsiveNav=o}(document,window,0);var customToggle=document.getElementById("nav-toggle"),customToggleText=document.getElementById("nav-toggle-text"),navigation=responsiveNav(".nav-wrapper",{customToggle:"#nav-toggle",customToggleText:"#nav-toggle-text",enableFocus:!0,enableDropdown:!0,openDropdown:'<span class="screen-reader-text">Open submenu</span>',closeDropdown:'<span class="screen-reader-text">Close submenu</span>',open:function(){customToggleText.innerHTML="Close menu"},close:function(){customToggleText.innerHTML="Menu"},resizeMobile:function(){customToggle.setAttribute("aria-controls","nav-wrapper")},resizeDesktop:function(){customToggle.removeAttribute("aria-controls")}});