vendor/assets/javascripts/scrollspy.js in active_frontend-2.0.10 vs vendor/assets/javascripts/scrollspy.js in active_frontend-2.0.11

- old
+ new

@@ -3,48 +3,51 @@ // SCROLLSPY CLASS DEFINITION // ========================== function ScrollSpy(element, options) { - this.$body = $(document.body) - this.$scrollElement = $(element).is(document.body) ? $(window) : $(element) + var process = $.proxy(this.process, this) + + this.$body = $('body') + this.$scrollElement = $(element).is('body') ? $(window) : $(element) this.options = $.extend({}, ScrollSpy.DEFAULTS, options) this.selector = (this.options.target || '') + ' .nav li > a' this.offsets = [] this.targets = [] this.activeTarget = null this.scrollHeight = 0 - this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this)) + this.$scrollElement.on('scroll.bs.scrollspy', process) this.refresh() this.process() } - ScrollSpy.VERSION = '3.3.4' + ScrollSpy.VERSION = '3.3.2' 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 that = this - var offsetMethod = 'offset' - var offsetBase = 0 + var offsetMethod = 'offset' + var offsetBase = 0 - this.offsets = [] - this.targets = [] - this.scrollHeight = this.getScrollHeight() - if (!$.isWindow(this.$scrollElement[0])) { offsetMethod = 'position' offsetBase = this.$scrollElement.scrollTop() } + this.offsets = [] + this.targets = [] + this.scrollHeight = this.getScrollHeight() + + var self = this + this.$body .find(this.selector) .map(function () { var $el = $(this) var href = $el.data('target') || $el.attr('href') @@ -55,12 +58,12 @@ && $href.is(':visible') && [[$href[offsetMethod]().top + offsetBase, href]]) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { - that.offsets.push(this[0]) - that.targets.push(this[1]) + self.offsets.push(this[0]) + self.targets.push(this[1]) }) } ScrollSpy.prototype.process = function () { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset @@ -85,22 +88,22 @@ } for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] - && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1]) + && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) && this.activate(targets[i]) } } ScrollSpy.prototype.activate = function (target) { this.activeTarget = target this.clear() var selector = this.selector + - '[data-target="' + target + '"],' + - this.selector + '[href="' + target + '"]' + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' var active = $(selector) .parents('li') .addClass('active') \ No newline at end of file