-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.zillamobilemenu.min.js
5 lines (5 loc) · 3.45 KB
/
jquery.zillamobilemenu.min.js
1
2
3
4
5
/**
* jQuery zillaMobileMenu v0.1
*
* Author: Mark Southard
*/(function(e,t,n,r){$window=e(t);var i=e.event,s,u;s=i.special.debouncedresize={setup:function(){e(this).on("resize",s.handler)},teardown:function(){e(this).off("resize",s.handler)},handler:function(e,t){var n=this,r=arguments,o=function(){e.type="debouncedresize";i.dispatch.apply(n,r)};u&&clearTimeout(u);t?o():u=setTimeout(o,s.threshold)},threshold:150};e.fn.debouncedresize=function(e){return e?this.bind("debouncedresize",e):this.trigger("debouncedresize",["execAsap"])};var a={};a.defaults={breakPoint:768,hideNavParent:!1,prependTo:"body",speed:500,triggerText:"Menu",onInit:function(){},afterInit:function(){},beforeOpen:function(){},beforeClose:function(){}};e.fn.zillaMobileMenu=function(t){if(a.methods[t])return a.methods[t].apply(this,Array.prototype.slice.call(arguments,1));if(typeof t=="object"||!t)return a.methods.init.apply(this,arguments);e.error("Method "+t+" does not exist on jQuery.zillaMobileMenu")};a.methods={init:function(t){return this.each(function(){var n=e(this),r=!1;data=n.data("zillaMobileMenu"),o=e.extend({},a.defaults,t);if(!data){var i=n.clone().addClass("zilla-mobile-menu"),s=e('<a class="zilla-mobile-menu-dropdown" href="#">'+o.triggerText+"</a>");i.data("zillaMobileMenu",{nav:i,navHeight:0,totalHeight:0,trigger:s,triggerHeight:0,created:!1,options:o});data=i.data("zillaMobileMenu")}if(data.initialized){typeof console!="undefined"&&console.warn("ZillaMobileMenu already initialized on",this);return this}data.initialized=!0;o.onInit.call(null,i);if($window.width()<=o.breakPoint){a.methods.make(i);i.parent().show();o.hideNavParent?n.parent().hide():n.hide()}$window.bind("debouncedresize",function(){if($window.width()<=o.breakPoint){data.created||a.methods.make(i);i.parent().show();o.hideNavParent?n.parent().hide():n.hide()}else{o.hideNavParent?n.parent().show():n.show();data.created&&i.parent().hide()}});s.on("click",function(t){var n=e(this);n.hasClass("open")?a.methods.close(n.next(".zilla-mobile-menu")):a.methods.open(n.next(".zilla-mobile-menu"));t.preventDefault();t.stopPropagation();return!1});o.afterInit.call(null,i)})},make:function(t){if(typeof t=="undefined")var t=e(this);return t.each(function(){var e=t.data("zillaMobileMenu"),n=e.options;t.prependTo(n.prependTo).wrap('<div class="zilla-mobile-menu-wrap" />');e.trigger.insertBefore(t);e.triggerHeight=e.trigger.outerHeight();e.navHeight=t.outerHeight();e.totalHeight=e.navHeight+e.triggerHeight;t.css({display:"none",marginTop:"-"+e.totalHeight+"px",position:"absolute",visibility:"hidden"});e.created=!0})},open:function(t){if(typeof t=="undefined")var t=e(this);return t.each(function(){var e=t.data("zillaMobileMenu"),n=e.options;n.beforeOpen.call(null,t);t.prev(".zilla-mobile-menu-dropdown").addClass("open");t.css({display:"block",visibility:"visible"}).animate({marginTop:e.triggerHeight+"px"},n.speed)})},close:function(t){if(typeof t=="undefined")var t=e(this);return t.each(function(){var e=t.data("zillaMobileMenu"),n=e.options;n.beforeClose.call(null,t);t.prev(".zilla-mobile-menu-dropdown").removeClass("open");t.animate({marginTop:"-"+e.totalHeight+"px"},n.speed,function(){t.css({display:"none",visibility:"hidden"})})})},destroy:function(){return this.each(function(){if(e(this).data("zillaMobileMenu")){var t=e(this).data("zillaMobileMenu"),n=t.options;e(this).removeData("zillaMobileMenu")}else typeof console!="undefined"&&console.warn("ZillaMobileMenu not initialized on that dom element")})}}})(jQuery,window,document);