forked from arielsalminen/responsive-nav.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
responsive-nav.min.js
11 lines (11 loc) · 4.48 KB
/
responsive-nav.min.js
1
2
3
4
5
6
7
8
9
10
11
/*! responsive-nav.js v1.06 by @viljamis, http://responsive-nav.com, MIT license */
/* Note: debug option isn't included in this minified production version */
var responsiveNav=function(g,h){var t=!!g.getComputedStyle;g.getComputedStyle||(g.getComputedStyle=function(a){this.el=a;this.getPropertyValue=function(d){var c=/(\-([a-z]){1})/g;"float"===d&&(d="styleFloat");c.test(d)&&(d=d.replace(c,function(a,c,d){return d.toUpperCase()}));return a.currentStyle[d]?a.currentStyle[d]:null};return this});var b,f,e,r=h.documentElement,u=h.getElementsByTagName("head")[0],j=h.createElement("style"),q=!1,l=function(a,d,c,b){if("addEventListener"in a)try{a.addEventListener(d,
c,b)}catch(e){if("object"===typeof c&&c.handleEvent)a.addEventListener(d,function(a){c.handleEvent.call(c,a)},b);else throw e;}else"attachEvent"in a&&("object"===typeof c&&c.handleEvent?a.attachEvent("on"+d,function(){c.handleEvent.call(c)}):a.attachEvent("on"+d,c))},m=function(a,d,c,b){if("removeEventListener"in a)try{a.removeEventListener(d,c,b)}catch(e){if("object"===typeof c&&c.handleEvent)a.removeEventListener(d,function(a){c.handleEvent.call(c,a)},b);else throw e;}else"detachEvent"in a&&("object"===
typeof c&&c.handleEvent?a.detachEvent("on"+d,function(){c.handleEvent.call(c)}):a.detachEvent("on"+d,c))},k=function(a,b){for(var c in b)a.setAttribute(c,b[c])},n=function(a,b){a.className=a.className.replace(RegExp("(\\s|^)"+b+"(\\s|$)")," ")},s=function(a,d){var c;this.options={animate:!0,transition:400,label:"Menu",insert:"after",customToggle:"",tabIndex:1,openPos:"relative",jsClass:"js",init:function(){},open:function(){},close:function(){}};for(c in d)this.options[c]=d[c];r.className+=" "+this.options.jsClass;
this.wrapperEl=a.replace("#","");if(h.getElementById(this.wrapperEl)){c=this.wrapper=h.getElementById(this.wrapperEl);for(var e=this.wrapper.firstChild;null!==e&&1!==e.nodeType;)e=e.nextSibling;c.inner=e;f=this.options;b=this.wrapper;this._init(this)}};s.prototype={destroy:function(){n(b,"closed");n(b,"opened");b.removeAttribute("style");b.removeAttribute("aria-hidden");p=b=null;m(g,"load",this,!1);m(g,"resize",this,!1);m(e,"mousedown",this,!1);m(e,"touchstart",this,!1);m(e,"keyup",this,!1);m(e,"click",
this,!1);f.customToggle?e.removeAttribute("aria-hidden"):e.parentNode.removeChild(e);j.parentNode&&j.parentNode.removeChild(j)},toggle:function(){q?(n(b,"opened"),b.className+=" closed",k(b,{aria:"true"}),f.animate?setTimeout(function(){b.style.position="absolute"},f.transition+10):b.style.position="absolute",q=!1,f.close()):(n(b,"closed"),b.className+=" opened",b.style.position=f.openPos,k(b,{aria:"false"}),q=!0,f.open())},handleEvent:function(a){a=a||g.event;switch(a.type){case "mousedown":this._onmousedown(a);
break;case "touchstart":this._ontouchstart(a);break;case "keyup":this._onkeyup(a);break;case "click":this._onclick(a);break;case "load":case "resize":this._resize(a)}},_init:function(){b.className+=" closed";this._createToggle();l(g,"load",this,!1);l(g,"resize",this,!1);l(e,"mousedown",this,!1);l(e,"touchstart",this,!1);l(e,"keyup",this,!1);l(e,"click",this,!1)},_createStyles:function(){j.parentNode||u.appendChild(j)},_removeStyles:function(){j.parentNode&&j.parentNode.removeChild(j)},_createToggle:function(){if(f.customToggle){var a=
f.customToggle.replace("#","");h.getElementById(a)&&(e=h.getElementById(a))}else a=h.createElement("a"),a.innerHTML=f.label,k(a,{href:"#",id:"nav-toggle",tabindex:f.tabIndex}),"after"===f.insert?b.parentNode.insertBefore(a,b.nextSibling):b.parentNode.insertBefore(a,b),e=h.getElementById("nav-toggle")},_preventDefault:function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},_onmousedown:function(a){this._preventDefault(a);this.toggle(a)},_ontouchstart:function(a){e.onmousedown=null;this._preventDefault(a);
this.toggle(a)},_onkeyup:function(a){13===(a||g.event).keyCode&&this.toggle(a)},_onclick:function(a){this._preventDefault(a)},_transitions:function(){if(f.animate){var a=b.style,d="max-height "+f.transition+"ms";a.WebkitTransition=d;a.MozTransition=d;a.OTransition=d;a.transition=d}},_resize:function(){f.init();if("none"!==g.getComputedStyle(e,null).getPropertyValue("display")){k(e,{aria:"false"});b.className.match(/(^|\s)closed(\s|$)/)&&(k(b,{aria:"true"}),b.style.position="absolute");this._createStyles();
this._transitions();var a="#"+this.wrapperEl+".opened{max-height:"+b.inner.offsetHeight+"px}";t&&(j.innerHTML=a)}else k(e,{aria:"true"}),k(b,{aria:"false"}),b.style.position=f.openPos,this._removeStyles()}};var p;return function(a,b){p||(p=new s(a,b));return p}}(window,document);