diff --git a/dist/jquery.bootstrap-autohidingnavbar.js b/dist/jquery.bootstrap-autohidingnavbar.js index f59d3dc..9ed9b9b 100644 --- a/dist/jquery.bootstrap-autohidingnavbar.js +++ b/dist/jquery.bootstrap-autohidingnavbar.js @@ -8,23 +8,23 @@ */ ;(function($, window, document, undefined) { var pluginName = 'autoHidingNavbar', - $window = $(window), - $document = $(document), - _scrollThrottleTimer = null, - _resizeThrottleTimer = null, - _throttleDelay = 70, - _lastScrollHandlerRun = 0, - _previousScrollTop = null, - _windowHeight = $window.height(), - _visible = true, - _hideOffset, - defaults = { - disableAutohide: false, - showOnUpscroll: true, - showOnBottom: true, - hideOffset: 'auto', // "auto" means the navbar height - animationDuration: 200 - }; + $window = $(window), + $document = $(document), + _scrollThrottleTimer = null, + _resizeThrottleTimer = null, + _throttleDelay = 70, + _lastScrollHandlerRun = 0, + _previousScrollTop = null, + _windowHeight = $window.height(), + _visible = true, + _hideOffset, + defaults = { + disableAutohide: false, + showOnUpscroll: true, + showOnBottom: true, + hideOffset: 'auto', // "auto" means the navbar height + animationDuration: 200 + }; function AutoHidingNavbar(element, options) { this.element = $(element); @@ -39,9 +39,18 @@ return; } - autoHidingNavbar.element.addClass('navbar-hidden').animate({ - top: -autoHidingNavbar.element.height() - }, { + var align = {}; + if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) { + align = { + top: -autoHidingNavbar.element.height() + }; + } else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) { + align = { + bottom: -autoHidingNavbar.element.height() + }; + } + + autoHidingNavbar.element.addClass('navbar-hidden').animate(align, { queue: false, duration: autoHidingNavbar.settings.animationDuration }); @@ -56,9 +65,18 @@ return; } - autoHidingNavbar.element.removeClass('navbar-hidden').animate({ - top: 0 - }, { + var align = {}; + if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) { + align = { + top: 0 + }; + } else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) { + align = { + bottom: 0 + }; + } + + autoHidingNavbar.element.removeClass('navbar-hidden').animate(align, { queue: false, duration: autoHidingNavbar.settings.animationDuration }); @@ -67,7 +85,7 @@ function detectState(autoHidingNavbar) { var scrollTop = $window.scrollTop(), - scrollDelta = scrollTop - _previousScrollTop; + scrollDelta = scrollTop - _previousScrollTop; _previousScrollTop = scrollTop; @@ -79,8 +97,7 @@ if (autoHidingNavbar.settings.showOnUpscroll || scrollTop <= _hideOffset) { show(autoHidingNavbar); } - } - else if (scrollDelta > 0) { + } else if (scrollDelta > 0) { if (!_visible) { if (autoHidingNavbar.settings.showOnBottom && scrollTop + _windowHeight === $document.height()) { show(autoHidingNavbar); @@ -109,8 +126,7 @@ $document.on('scroll.' + pluginName, function() { if (new Date().getTime() - _lastScrollHandlerRun > _throttleDelay) { scrollHandler(autoHidingNavbar); - } - else { + } else { clearTimeout(_scrollThrottleTimer); _scrollThrottleTimer = setTimeout(function() { scrollHandler(autoHidingNavbar); diff --git a/dist/jquery.bootstrap-autohidingnavbar.min.js b/dist/jquery.bootstrap-autohidingnavbar.min.js index dba7a79..e465c93 100644 --- a/dist/jquery.bootstrap-autohidingnavbar.min.js +++ b/dist/jquery.bootstrap-autohidingnavbar.min.js @@ -6,4 +6,4 @@ * Made by István Ujj-Mészáros * Under Apache License v2.0 License */ -!function(a,b,c,d){function e(b,c){this.element=a(b),this.settings=a.extend({},w,c),this._defaults=w,this._name=m,this.init()}function f(b){v&&(b.element.addClass("navbar-hidden").animate({top:-b.element.height()},{queue:!1,duration:b.settings.animationDuration}),a(".dropdown.open .dropdown-toggle",b.element).dropdown("toggle"),v=!1)}function g(a){v||(a.element.removeClass("navbar-hidden").animate({top:0},{queue:!1,duration:a.settings.animationDuration}),v=!0)}function h(a){var b=n.scrollTop(),c=b-t;if(t=b,0>c){if(v)return;(a.settings.showOnUpscroll||l>=b)&&g(a)}else if(c>0){if(!v)return void(a.settings.showOnBottom&&b+u===o.height()&&g(a));b>=l&&f(a)}}function i(a){a.settings.disableAutohide||(s=(new Date).getTime(),h(a))}function j(a){o.on("scroll."+m,function(){(new Date).getTime()-s>r?i(a):(clearTimeout(p),p=setTimeout(function(){i(a)},r))}),n.on("resize."+m,function(){clearTimeout(q),q=setTimeout(function(){u=n.height()},r)})}function k(){o.off("."+m),n.off("."+m)}var l,m="autoHidingNavbar",n=a(b),o=a(c),p=null,q=null,r=70,s=0,t=null,u=n.height(),v=!0,w={disableAutohide:!1,showOnUpscroll:!0,showOnBottom:!0,hideOffset:"auto",animationDuration:200};e.prototype={init:function(){return this.elements={navbar:this.element},this.setDisableAutohide(this.settings.disableAutohide),this.setShowOnUpscroll(this.settings.showOnUpscroll),this.setShowOnBottom(this.settings.showOnBottom),this.setHideOffset(this.settings.hideOffset),this.setAnimationDuration(this.settings.animationDuration),l="auto"===this.settings.hideOffset?this.element.height():this.settings.hideOffset,j(this),this.element},setDisableAutohide:function(a){return this.settings.disableAutohide=a,this.element},setShowOnUpscroll:function(a){return this.settings.showOnUpscroll=a,this.element},setShowOnBottom:function(a){return this.settings.showOnBottom=a,this.element},setHideOffset:function(a){return this.settings.hideOffset=a,this.element},setAnimationDuration:function(a){return this.settings.animationDuration=a,this.element},show:function(){return g(this),this.element},hide:function(){return f(this),this.element},destroy:function(){return k(this),g(this),a.data(this,"plugin_"+m,null),this.element}},a.fn[m]=function(b){var c=arguments;if(b===d||"object"==typeof b)return this.each(function(){a.data(this,"plugin_"+m)||a.data(this,"plugin_"+m,new e(this,b))});if("string"==typeof b&&"_"!==b[0]&&"init"!==b){var f;return this.each(function(){var d=a.data(this,"plugin_"+m);d instanceof e&&"function"==typeof d[b]&&(f=d[b].apply(d,Array.prototype.slice.call(c,1)))}),f!==d?f:this}}}(jQuery,window,document); \ No newline at end of file +!function(a,b,c,d){function e(b,c){this.element=a(b),this.settings=a.extend({},w,c),this._defaults=w,this._name=m,this.init()}function f(b){if(v){var c={};b.element.hasClass("navbar-fixed-top")?c={top:-b.element.height()}:b.element.hasClass("navbar-fixed-bottom")&&(c={bottom:-b.element.height()}),b.element.addClass("navbar-hidden").animate(c,{queue:!1,duration:b.settings.animationDuration}),a(".dropdown.open .dropdown-toggle",b.element).dropdown("toggle"),v=!1}}function g(a){if(!v){var b={};a.element.hasClass("navbar-fixed-top")?b={top:0}:a.element.hasClass("navbar-fixed-bottom")&&(b={bottom:0}),a.element.removeClass("navbar-hidden").animate(b,{queue:!1,duration:a.settings.animationDuration}),v=!0}}function h(a){var b=n.scrollTop(),c=b-t;if(t=b,0>c){if(v)return;(a.settings.showOnUpscroll||l>=b)&&g(a)}else if(c>0){if(!v)return void(a.settings.showOnBottom&&b+u===o.height()&&g(a));b>=l&&f(a)}}function i(a){a.settings.disableAutohide||(s=(new Date).getTime(),h(a))}function j(a){o.on("scroll."+m,function(){(new Date).getTime()-s>r?i(a):(clearTimeout(p),p=setTimeout(function(){i(a)},r))}),n.on("resize."+m,function(){clearTimeout(q),q=setTimeout(function(){u=n.height()},r)})}function k(){o.off("."+m),n.off("."+m)}var l,m="autoHidingNavbar",n=a(b),o=a(c),p=null,q=null,r=70,s=0,t=null,u=n.height(),v=!0,w={disableAutohide:!1,showOnUpscroll:!0,showOnBottom:!0,hideOffset:"auto",animationDuration:200};e.prototype={init:function(){return this.elements={navbar:this.element},this.setDisableAutohide(this.settings.disableAutohide),this.setShowOnUpscroll(this.settings.showOnUpscroll),this.setShowOnBottom(this.settings.showOnBottom),this.setHideOffset(this.settings.hideOffset),this.setAnimationDuration(this.settings.animationDuration),l="auto"===this.settings.hideOffset?this.element.height():this.settings.hideOffset,j(this),this.element},setDisableAutohide:function(a){return this.settings.disableAutohide=a,this.element},setShowOnUpscroll:function(a){return this.settings.showOnUpscroll=a,this.element},setShowOnBottom:function(a){return this.settings.showOnBottom=a,this.element},setHideOffset:function(a){return this.settings.hideOffset=a,this.element},setAnimationDuration:function(a){return this.settings.animationDuration=a,this.element},show:function(){return g(this),this.element},hide:function(){return f(this),this.element},destroy:function(){return k(this),g(this),a.data(this,"plugin_"+m,null),this.element}},a.fn[m]=function(b){var c=arguments;if(b===d||"object"==typeof b)return this.each(function(){a.data(this,"plugin_"+m)||a.data(this,"plugin_"+m,new e(this,b))});if("string"==typeof b&&"_"!==b[0]&&"init"!==b){var f;return this.each(function(){var d=a.data(this,"plugin_"+m);d instanceof e&&"function"==typeof d[b]&&(f=d[b].apply(d,Array.prototype.slice.call(c,1)))}),f!==d?f:this}}}(jQuery,window,document); \ No newline at end of file diff --git a/src/jquery.bootstrap-autohidingnavbar.js b/src/jquery.bootstrap-autohidingnavbar.js index cef93b8..b4600bf 100644 --- a/src/jquery.bootstrap-autohidingnavbar.js +++ b/src/jquery.bootstrap-autohidingnavbar.js @@ -1,22 +1,22 @@ ;(function($, window, document, undefined) { var pluginName = 'autoHidingNavbar', - $window = $(window), - $document = $(document), - _scrollThrottleTimer = null, - _resizeThrottleTimer = null, - _throttleDelay = 70, - _lastScrollHandlerRun = 0, - _previousScrollTop = null, - _windowHeight = $window.height(), - _visible = true, - _hideOffset, - defaults = { - disableAutohide: false, - showOnUpscroll: true, - showOnBottom: true, - hideOffset: 'auto', // "auto" means the navbar height - animationDuration: 200 - }; + $window = $(window), + $document = $(document), + _scrollThrottleTimer = null, + _resizeThrottleTimer = null, + _throttleDelay = 70, + _lastScrollHandlerRun = 0, + _previousScrollTop = null, + _windowHeight = $window.height(), + _visible = true, + _hideOffset, + defaults = { + disableAutohide: false, + showOnUpscroll: true, + showOnBottom: true, + hideOffset: 'auto', // "auto" means the navbar height + animationDuration: 200 + }; function AutoHidingNavbar(element, options) { this.element = $(element); @@ -31,9 +31,18 @@ return; } - autoHidingNavbar.element.addClass('navbar-hidden').animate({ - top: -autoHidingNavbar.element.height() - }, { + var align = {}; + if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) { + align = { + top: -autoHidingNavbar.element.height() + }; + } else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) { + align = { + bottom: -autoHidingNavbar.element.height() + }; + } + + autoHidingNavbar.element.addClass('navbar-hidden').animate(align, { queue: false, duration: autoHidingNavbar.settings.animationDuration }); @@ -48,9 +57,18 @@ return; } - autoHidingNavbar.element.removeClass('navbar-hidden').animate({ - top: 0 - }, { + var align = {}; + if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) { + align = { + top: 0 + }; + } else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) { + align = { + bottom: 0 + }; + } + + autoHidingNavbar.element.removeClass('navbar-hidden').animate(align, { queue: false, duration: autoHidingNavbar.settings.animationDuration }); @@ -59,7 +77,7 @@ function detectState(autoHidingNavbar) { var scrollTop = $window.scrollTop(), - scrollDelta = scrollTop - _previousScrollTop; + scrollDelta = scrollTop - _previousScrollTop; _previousScrollTop = scrollTop; @@ -71,8 +89,7 @@ if (autoHidingNavbar.settings.showOnUpscroll || scrollTop <= _hideOffset) { show(autoHidingNavbar); } - } - else if (scrollDelta > 0) { + } else if (scrollDelta > 0) { if (!_visible) { if (autoHidingNavbar.settings.showOnBottom && scrollTop + _windowHeight === $document.height()) { show(autoHidingNavbar); @@ -101,8 +118,7 @@ $document.on('scroll.' + pluginName, function() { if (new Date().getTime() - _lastScrollHandlerRun > _throttleDelay) { scrollHandler(autoHidingNavbar); - } - else { + } else { clearTimeout(_scrollThrottleTimer); _scrollThrottleTimer = setTimeout(function() { scrollHandler(autoHidingNavbar);