-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-collapse.min.js
executable file
·7 lines (7 loc) · 2.71 KB
/
auto-collapse.min.js
1
2
3
4
5
6
7
/*! auto-collapse v1.0.1 | ©2012-2018 GestiXi | Licensed under the MIT license */
!function(a){a.fn.autoCollapse=function(c){return this.each(function(){var b=a(this),e=b.data("autoCollapse");if(!e){if(b.hasClass("auto-collapse-clone"))return;var d=a.extend({},a.fn.autoCollapse.defaults,"object"==typeof c&&c);b.data("autoCollapse",e=new g(this,d));d.updateOnResize&&a(window).resize(function(b){e.scheduleUpdate()})}e.update()})};a.fn.autoCollapse.defaults={normalClass:"navbar-normal",responsiveClass:"navbar-responsive",dropdownLinkSelector:".dropdown > a",shouldCollapseDelegate:function(c){var b=
this,a=c.find("ul");c=a.height();a=a.find("li").outerHeight(!0);c=c>a;b.r||(b.r=0);9>b.r&&(setTimeout(function(){b.update()},50*b.r*b.r),b.r++);return c},updateOnResize:!0};var g=function(c,b){this.options=b;var e=this.$element=a(c),d=this.$clone=e.clone();(this.$links=e.find(b.dropdownLinkSelector)).each(function(){a.data(this,"href",a(this).attr("href"));a.data(this,"hasDropDownClass",a(this).hasClass("dropdown-toggle"));a.data(this,"hasDropDownData","dropdown"===a(this).attr("data-toggle"))});
d.css({opacity:0,display:"none","pointer-events":"none"});d.addClass("auto-collapse-clone");d.appendTo(e.parent());this.isNormal=e.hasClass(b.normalClass)};a.fn.autoCollapse.Constructor=g;g.prototype={constructor:g,isNormal:null,update:function(){this._didScheduleUpdate=!1;var a=this.options,b=this.$clone;b.css({display:"block"});a=a.shouldCollapseDelegate.call(this,b);b.css({display:"none"});(a?this.makeResponsive():this.makeNormal())&&this.updateMargin()},makeResponsive:function(){if(!1===this.isNormal)return!1;
this.isNormal=!1;var c=this.options;this.$element.removeClass(c.normalClass).addClass(c.responsiveClass);this.$links.each(function(){a(this).attr("href","#").addClass("dropdown-toggle").attr("data-toggle","dropdown")});return!0},makeNormal:function(){if(!0===this.isNormal)return!1;this.isNormal=!0;var c=this.options;this.$element.removeClass(c.responsiveClass).addClass(c.normalClass);this.$links.each(function(){a(this).attr("href",a.data(this,"href"));a.data(this,"hasDropDownClass")||a(this).removeClass("dropdown-toggle");
a.data(this,"hasDropDownData")||a(this).removeAttr("data-toggle")});return!0},updateMargin:function(){var c=this.isNormal,b=this.$element,e=b.find(".collapse"),d=this._initialMargin;null==d&&(d=this._initialMargin={left:e.css("margin-left"),right:e.css("margin-right")});var f=d.left;d=d.right;c||(f=b.offset().left,b=a(window).width()-(f+b.outerWidth()),f=-f,d=-b);e.css({"margin-left":f,"margin-right":d})},scheduleUpdate:function(){if(!this._didScheduleUpdate)if(window.requestAnimationFrame){var a=
this;this._didScheduleUpdate=!0;requestAnimationFrame(function(){a.update()})}else this.update()}}}(window.jQuery);