diff options
Diffstat (limited to 'bower_components/bootstrap/js/scrollspy.js')
| -rw-r--r-- | bower_components/bootstrap/js/scrollspy.js | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/bower_components/bootstrap/js/scrollspy.js b/bower_components/bootstrap/js/scrollspy.js index 4346c86..db23787 100644 --- a/bower_components/bootstrap/js/scrollspy.js +++ b/bower_components/bootstrap/js/scrollspy.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: scrollspy.js v3.1.1 + * Bootstrap: scrollspy.js v3.2.0 * http://getbootstrap.com/javascript/#scrollspy * ======================================================================== * Copyright 2011-2014 Twitter, Inc. @@ -14,36 +14,48 @@ // ========================== function ScrollSpy(element, options) { - var href var process = $.proxy(this.process, this) - this.$element = $(element).is('body') ? $(window) : $(element) this.$body = $('body') - this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process) + this.$scrollElement = $(element).is('body') ? $(window) : $(element) this.options = $.extend({}, ScrollSpy.DEFAULTS, options) - this.selector = (this.options.target - || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 - || '') + ' .nav li > a' - this.offsets = $([]) - this.targets = $([]) + this.selector = (this.options.target || '') + ' .nav li > a' + this.offsets = [] + this.targets = [] this.activeTarget = null + this.scrollHeight = 0 + this.$scrollElement.on('scroll.bs.scrollspy', process) this.refresh() this.process() } + ScrollSpy.VERSION = '3.2.0' + ScrollSpy.DEFAULTS = { offset: 10 } + ScrollSpy.prototype.getScrollHeight = function () { + return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) + } + ScrollSpy.prototype.refresh = function () { - var offsetMethod = this.$element[0] == window ? 'offset' : 'position' + var offsetMethod = 'offset' + var offsetBase = 0 - this.offsets = $([]) - this.targets = $([]) + if (!$.isWindow(this.$scrollElement[0])) { + offsetMethod = 'position' + offsetBase = this.$scrollElement.scrollTop() + } + + this.offsets = [] + this.targets = [] + this.scrollHeight = this.getScrollHeight() var self = this - var $targets = this.$body + + this.$body .find(this.selector) .map(function () { var $el = $(this) @@ -53,7 +65,7 @@ return ($href && $href.length && $href.is(':visible') - && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null + && [[$href[offsetMethod]().top + offsetBase, href]]) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { @@ -64,15 +76,19 @@ ScrollSpy.prototype.process = function () { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - var scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight - var maxScroll = scrollHeight - this.$scrollElement.height() + var scrollHeight = this.getScrollHeight() + var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height() var offsets = this.offsets var targets = this.targets var activeTarget = this.activeTarget var i + if (this.scrollHeight != scrollHeight) { + this.refresh() + } + if (scrollTop >= maxScroll) { - return activeTarget != (i = targets.last()[0]) && this.activate(i) + return activeTarget != (i = targets[targets.length - 1]) && this.activate(i) } if (activeTarget && scrollTop <= offsets[0]) { @@ -83,7 +99,7 @@ activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate( targets[i] ) + && this.activate(targets[i]) } } @@ -115,9 +131,7 @@ // SCROLLSPY PLUGIN DEFINITION // =========================== - var old = $.fn.scrollspy - - $.fn.scrollspy = function (option) { + function Plugin(option) { return this.each(function () { var $this = $(this) var data = $this.data('bs.scrollspy') @@ -128,6 +142,9 @@ }) } + var old = $.fn.scrollspy + + $.fn.scrollspy = Plugin $.fn.scrollspy.Constructor = ScrollSpy @@ -143,10 +160,10 @@ // SCROLLSPY DATA-API // ================== - $(window).on('load', function () { + $(window).on('load.bs.scrollspy.data-api', function () { $('[data-spy="scroll"]').each(function () { var $spy = $(this) - $spy.scrollspy($spy.data()) + Plugin.call($spy, $spy.data()) }) }) |
