From 45b476bdbff7ac38518deb7898529bb9510f648f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 1 Mar 2014 18:19:50 +0200 Subject: JS: remove unused variables. --- js/scrollspy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 137bd373f..c77a9fbed 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -43,7 +43,8 @@ this.targets = $([]) var self = this - var $targets = this.$body + + this.$body .find(this.selector) .map(function () { var $el = $(this) -- cgit v1.2.3 From a9f2b6ce0fb2ac059e30da259f7ae25282803c09 Mon Sep 17 00:00:00 2001 From: Collin Donahue-Oponski Date: Mon, 21 Apr 2014 23:03:33 -0600 Subject: #11464 - Fix JS noConflict mode - Refactor all plugins to use an internal reference to the jQuery plugin, because in noConflict mode you can never expect to be defined on the jQuery object --- js/scrollspy.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index c77a9fbed..1f9153552 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -116,9 +116,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') @@ -129,6 +127,9 @@ }) } + var old = $.fn.scrollspy + + $.fn.scrollspy = Plugin $.fn.scrollspy.Constructor = ScrollSpy @@ -147,7 +148,7 @@ $(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()) }) }) -- cgit v1.2.3 From 9900771aa7f1b3ddcee49aec84082104776ace70 Mon Sep 17 00:00:00 2001 From: fat Date: Mon, 12 May 2014 19:15:23 -0700 Subject: fixes #12211: Scrollspy: Navs in different tabs can interfere with each othe --- js/scrollspy.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 1f9153552..4ba733e78 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -46,6 +46,7 @@ this.$body .find(this.selector) + .filter(':visible') .map(function () { var $el = $(this) var href = $el.data('target') || $el.attr('href') -- cgit v1.2.3 From f219fee07b14ea1d37e197b1d80f5c7a8e3bc186 Mon Sep 17 00:00:00 2001 From: fat Date: Mon, 12 May 2014 21:15:16 -0700 Subject: versions --- js/scrollspy.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 4ba733e78..74e016dc9 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -32,6 +32,8 @@ this.process() } + ScrollSpy.VERSION = '3.1.1' + ScrollSpy.DEFAULTS = { offset: 10 } -- cgit v1.2.3 From e84b0c0433509bde0b42354754372595db523e1f Mon Sep 17 00:00:00 2001 From: Mike Robinet Date: Tue, 13 May 2014 09:57:04 -0500 Subject: Adjust for Scrollspy offset when calculating maxScroll. --- js/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 74e016dc9..53e1c48ba 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -69,7 +69,7 @@ ScrollSpy.prototype.process = function () { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset var scrollHeight = this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) - var maxScroll = scrollHeight - this.$scrollElement.height() + var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height() var offsets = this.offsets var targets = this.targets var activeTarget = this.activeTarget -- cgit v1.2.3 From 7b0acf14d8a7c7c6089035a848cba540ed963f36 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 17 Mar 2014 09:12:55 +0200 Subject: Comply to the new style. --- js/scrollspy.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 53e1c48ba..cddde45ad 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -43,7 +43,6 @@ this.offsets = $([]) this.targets = $([]) - var self = this this.$body @@ -57,7 +56,7 @@ return ($href && $href.length && $href.is(':visible') - && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null + && [[$href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href]]) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { @@ -87,7 +86,7 @@ activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate( targets[i] ) + && this.activate(targets[i]) } } -- cgit v1.2.3 From 0be41096888201831c151864c0ab05cf0b5ca734 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 29 May 2014 02:24:41 -0500 Subject: there is no need for this.offsets and this.targets to be jQuery objects --- js/scrollspy.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index cddde45ad..de4f98707 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -24,8 +24,8 @@ this.selector = (this.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 || '') + ' .nav li > a' - this.offsets = $([]) - this.targets = $([]) + this.offsets = [] + this.targets = [] this.activeTarget = null this.refresh() @@ -41,8 +41,9 @@ ScrollSpy.prototype.refresh = function () { var offsetMethod = this.$element[0] == window ? 'offset' : 'position' - this.offsets = $([]) - this.targets = $([]) + this.offsets = [] + this.targets = [] + var self = this this.$body @@ -75,7 +76,7 @@ var i 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]) { -- cgit v1.2.3 From 632313d631b51d96557bb6576c0b41e33cbfb009 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 29 May 2014 02:30:18 -0500 Subject: no need to check for href attribute on the scrollable element --- js/scrollspy.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index de4f98707..db493d7ed 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -14,16 +14,13 @@ // ========================== 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.scrollspy', process) 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.selector = (this.options.target || '') + ' .nav li > a' this.offsets = [] this.targets = [] this.activeTarget = null -- cgit v1.2.3 From bc8e6ffb7d702895296050d2fd8847fb5eed2381 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 29 May 2014 02:36:53 -0500 Subject: removing this.$element as it is a superfluous copy of this.$scrollElement --- js/scrollspy.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index db493d7ed..94171bb1b 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -16,15 +16,15 @@ function ScrollSpy(element, options) { var process = $.proxy(this.process, this) - this.$element = $(element).is('body') ? $(window) : $(element) this.$body = $('body') - this.$scrollElement = this.$element.on('scroll.bs.scrollspy', process) + 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.$scrollElement.on('scroll.bs.scrollspy', process) this.refresh() this.process() } @@ -36,7 +36,7 @@ } ScrollSpy.prototype.refresh = function () { - var offsetMethod = this.$element[0] == window ? 'offset' : 'position' + var offsetMethod = this.$scrollElement[0] == window ? 'offset' : 'position' this.offsets = [] this.targets = [] -- cgit v1.2.3 From 1cfa902e313e848732976ac6e538f3f72c135d90 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 29 May 2014 02:51:49 -0500 Subject: refactor scrollspy refresh method Closes #13702 by merging a rebased version of it. --- js/scrollspy.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 94171bb1b..644c65f94 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -36,7 +36,13 @@ } ScrollSpy.prototype.refresh = function () { - var offsetMethod = this.$scrollElement[0] == window ? 'offset' : 'position' + var offsetMethod = 'offset' + var offsetBase = 0 + + if (!$.isWindow(this.$scrollElement[0])) { + offsetMethod = 'position' + offsetBase = this.$scrollElement.scrollTop() + } this.offsets = [] this.targets = [] @@ -54,7 +60,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 () { -- cgit v1.2.3 From 91103e6d1f750bc53dce7b4720cf78a50e1baa54 Mon Sep 17 00:00:00 2001 From: fat Date: Sat, 7 Jun 2014 19:11:44 -0700 Subject: Adds isolated visual tests for javascript plugins (decoupled from docs). This makes it faster and easier to test/develop js functionality not represented in unit tests, and gives us a playground for interactions, etc. It also makes it so developing javascript is now decoupled form jekyll, which should make everything faster and less painful. This commit also reverts my filter commit https://github.com/twbs/bootstrap/commit/9900771aa7f1b3ddcee49aec84082104776ace70 which broke scrollspy for dropdowns. --- js/scrollspy.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index cddde45ad..edc9bbd00 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -47,7 +47,6 @@ this.$body .find(this.selector) - .filter(':visible') .map(function () { var $el = $(this) var href = $el.data('target') || $el.attr('href') -- cgit v1.2.3 From 1c6fa9010daf0d0c21de9e20fe6ac4dba1788d90 Mon Sep 17 00:00:00 2001 From: Katie Zhu Date: Mon, 9 Jun 2014 22:18:05 -0700 Subject: MD/CommonJS/Globals #12909 --- js/scrollspy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index d527e9c2d..78858680e 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -7,7 +7,11 @@ * ======================================================================== */ -+function ($) { +(function (o_o) { + typeof define === 'function' && define.amd ? define(['jquery'], o_o) : + typeof exports === 'object' ? o_o(require('jquery')) : o_o(this.jQuery) +})(function ($) { + 'use strict'; // SCROLLSPY CLASS DEFINITION @@ -157,4 +161,4 @@ }) }) -}(jQuery); +}); -- cgit v1.2.3 From 571fd32bcee3d069d5f30167a887b47efd492f01 Mon Sep 17 00:00:00 2001 From: fat Date: Tue, 10 Jun 2014 17:37:40 -0700 Subject: fix #13220 Scrollspy generates wrong offsets for a page-- recalculate offsets if `scrollheight` changes --- js/scrollspy.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 78858680e..fe8fbc682 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -27,6 +27,7 @@ this.offsets = [] this.targets = [] this.activeTarget = null + this.scrollHeight = 0 this.$scrollElement.on('scroll.bs.scrollspy', process) this.refresh() @@ -39,6 +40,10 @@ 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 = 'offset' var offsetBase = 0 @@ -50,6 +55,7 @@ this.offsets = [] this.targets = [] + this.scrollHeight = this.getScrollHeight() var self = this @@ -74,13 +80,17 @@ ScrollSpy.prototype.process = function () { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - var scrollHeight = this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) + 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[targets.length - 1]) && this.activate(i) } -- cgit v1.2.3 From e9d6756a1ac76a9db31a41e8e03f663bedc41b70 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Thu, 12 Jun 2014 06:00:02 +0200 Subject: Fix regression of #10038 introduced by #13772 --- js/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index fe8fbc682..83b333841 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -9,7 +9,7 @@ (function (o_o) { typeof define === 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports === 'object' ? o_o(require('jquery')) : o_o(this.jQuery) + typeof exports === 'object' ? o_o(require('jquery')) : o_o(jQuery) })(function ($) { 'use strict'; -- cgit v1.2.3 From 2b302f69eea416bc85e7827b7d7a74d49f879662 Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 12 Jun 2014 11:11:04 -0700 Subject: some changes from #13801 - add strict mode back and == --- js/scrollspy.js | 264 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 133 insertions(+), 131 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index 83b333841..ac0244391 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -7,168 +7,170 @@ * ======================================================================== */ -(function (o_o) { - typeof define === 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports === 'object' ? o_o(require('jquery')) : o_o(jQuery) -})(function ($) { - - 'use strict'; - - // SCROLLSPY CLASS DEFINITION - // ========================== - - function ScrollSpy(element, options) { - 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', process) - this.refresh() - this.process() - } - - ScrollSpy.VERSION = '3.1.1' - - 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 = 'offset' - var offsetBase = 0 - - if (!$.isWindow(this.$scrollElement[0])) { - offsetMethod = 'position' - offsetBase = this.$scrollElement.scrollTop() - } ++function () { 'use strict'; - this.offsets = [] - this.targets = [] - this.scrollHeight = this.getScrollHeight() + (function (o_o) { + typeof define == 'function' && define.amd ? define(['jquery'], o_o) : + typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) + })(function ($) { - var self = this + // SCROLLSPY CLASS DEFINITION + // ========================== - this.$body - .find(this.selector) - .map(function () { - var $el = $(this) - var href = $el.data('target') || $el.attr('href') - var $href = /^#./.test(href) && $(href) + function ScrollSpy(element, options) { + var process = $.proxy(this.process, this) - return ($href - && $href.length - && $href.is(':visible') - && [[$href[offsetMethod]().top + offsetBase, href]]) || null - }) - .sort(function (a, b) { return a[0] - b[0] }) - .each(function () { - self.offsets.push(this[0]) - self.targets.push(this[1]) - }) - } - - ScrollSpy.prototype.process = function () { - var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - 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.$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', process) this.refresh() + this.process() } - if (scrollTop >= maxScroll) { - return activeTarget != (i = targets[targets.length - 1]) && this.activate(i) + ScrollSpy.VERSION = '3.1.1' + + ScrollSpy.DEFAULTS = { + offset: 10 } - if (activeTarget && scrollTop <= offsets[0]) { - return activeTarget != (i = targets[0]) && this.activate(i) + ScrollSpy.prototype.getScrollHeight = function () { + return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) } - for (i = offsets.length; i--;) { - activeTarget != targets[i] - && scrollTop >= offsets[i] - && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate(targets[i]) + ScrollSpy.prototype.refresh = function () { + var offsetMethod = 'offset' + var offsetBase = 0 + + 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') + var $href = /^#./.test(href) && $(href) + + return ($href + && $href.length + && $href.is(':visible') + && [[$href[offsetMethod]().top + offsetBase, href]]) || null + }) + .sort(function (a, b) { return a[0] - b[0] }) + .each(function () { + self.offsets.push(this[0]) + self.targets.push(this[1]) + }) } - } - ScrollSpy.prototype.activate = function (target) { - this.activeTarget = target + ScrollSpy.prototype.process = function () { + var scrollTop = this.$scrollElement.scrollTop() + this.options.offset + 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[targets.length - 1]) && this.activate(i) + } + + if (activeTarget && scrollTop <= offsets[0]) { + return activeTarget != (i = targets[0]) && this.activate(i) + } + + for (i = offsets.length; i--;) { + activeTarget != targets[i] + && scrollTop >= offsets[i] + && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) + && this.activate(targets[i]) + } + } - $(this.selector) - .parentsUntil(this.options.target, '.active') - .removeClass('active') + ScrollSpy.prototype.activate = function (target) { + this.activeTarget = target - var selector = this.selector + - '[data-target="' + target + '"],' + - this.selector + '[href="' + target + '"]' + $(this.selector) + .parentsUntil(this.options.target, '.active') + .removeClass('active') - var active = $(selector) - .parents('li') - .addClass('active') + var selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' - if (active.parent('.dropdown-menu').length) { - active = active - .closest('li.dropdown') + var active = $(selector) + .parents('li') .addClass('active') - } - active.trigger('activate.bs.scrollspy') - } + if (active.parent('.dropdown-menu').length) { + active = active + .closest('li.dropdown') + .addClass('active') + } + active.trigger('activate.bs.scrollspy') + } - // SCROLLSPY PLUGIN DEFINITION - // =========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.scrollspy') - var options = typeof option == 'object' && option + // SCROLLSPY PLUGIN DEFINITION + // =========================== - if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) - if (typeof option == 'string') data[option]() - }) - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.scrollspy') + var options = typeof option == 'object' && option - var old = $.fn.scrollspy + if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) + if (typeof option == 'string') data[option]() + }) + } - $.fn.scrollspy = Plugin - $.fn.scrollspy.Constructor = ScrollSpy + var old = $.fn.scrollspy + $.fn.scrollspy = Plugin + $.fn.scrollspy.Constructor = ScrollSpy - // SCROLLSPY NO CONFLICT - // ===================== - $.fn.scrollspy.noConflict = function () { - $.fn.scrollspy = old - return this - } + // SCROLLSPY NO CONFLICT + // ===================== + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } - // SCROLLSPY DATA-API - // ================== - $(window).on('load.bs.scrollspy.data-api', function () { - $('[data-spy="scroll"]').each(function () { - var $spy = $(this) - Plugin.call($spy, $spy.data()) + // SCROLLSPY DATA-API + // ================== + + $(window).on('load.bs.scrollspy.data-api', function () { + $('[data-spy="scroll"]').each(function () { + var $spy = $(this) + Plugin.call($spy, $spy.data()) + }) }) + }) -}); +}(); -- cgit v1.2.3 From c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 23 Jun 2014 11:07:18 -0700 Subject: Revert UMD (#13772 & friends) for now, due to #13812. Will hopefully revert this reversion and land a fully-working version of UMD in v3.3.0. Revert "some changes from #13801 - add strict mode back and ==" This reverts commit 2b302f69eea416bc85e7827b7d7a74d49f879662. Revert "Fix regression of #10038 introduced by #13772" This reverts commit e9d6756a1ac76a9db31a41e8e03f663bedc41b70. Revert "MD/CommonJS/Globals #12909" This reverts commit 1c6fa9010daf0d0c21de9e20fe6ac4dba1788d90. Revert "address #13811" This reverts commit f347d7d955bbb17234b8e12c68efae7d516ce62c. Conflicts: js/carousel.js js/collapse.js js/dropdown.js js/modal.js js/tab.js js/tooltip.js --- js/scrollspy.js | 260 +++++++++++++++++++++++++++----------------------------- 1 file changed, 127 insertions(+), 133 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index ac0244391..e7d3a8b87 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -7,170 +7,164 @@ * ======================================================================== */ -+function () { 'use strict'; - - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { ++function ($) { + 'use strict'; + + // SCROLLSPY CLASS DEFINITION + // ========================== + + function ScrollSpy(element, options) { + 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', process) + this.refresh() + this.process() + } + + ScrollSpy.VERSION = '3.1.1' + + 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 = 'offset' + var offsetBase = 0 + + if (!$.isWindow(this.$scrollElement[0])) { + offsetMethod = 'position' + offsetBase = this.$scrollElement.scrollTop() + } - // SCROLLSPY CLASS DEFINITION - // ========================== + this.offsets = [] + this.targets = [] + this.scrollHeight = this.getScrollHeight() - function ScrollSpy(element, options) { - var process = $.proxy(this.process, this) + var self = 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.$body + .find(this.selector) + .map(function () { + var $el = $(this) + var href = $el.data('target') || $el.attr('href') + var $href = /^#./.test(href) && $(href) - this.$scrollElement.on('scroll.bs.scrollspy', process) + return ($href + && $href.length + && $href.is(':visible') + && [[$href[offsetMethod]().top + offsetBase, href]]) || null + }) + .sort(function (a, b) { return a[0] - b[0] }) + .each(function () { + self.offsets.push(this[0]) + self.targets.push(this[1]) + }) + } + + ScrollSpy.prototype.process = function () { + var scrollTop = this.$scrollElement.scrollTop() + this.options.offset + 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() - this.process() } - ScrollSpy.VERSION = '3.1.1' - - ScrollSpy.DEFAULTS = { - offset: 10 + if (scrollTop >= maxScroll) { + return activeTarget != (i = targets[targets.length - 1]) && this.activate(i) } - ScrollSpy.prototype.getScrollHeight = function () { - return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) + if (activeTarget && scrollTop <= offsets[0]) { + return activeTarget != (i = targets[0]) && this.activate(i) } - ScrollSpy.prototype.refresh = function () { - var offsetMethod = 'offset' - var offsetBase = 0 - - 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') - var $href = /^#./.test(href) && $(href) - - return ($href - && $href.length - && $href.is(':visible') - && [[$href[offsetMethod]().top + offsetBase, href]]) || null - }) - .sort(function (a, b) { return a[0] - b[0] }) - .each(function () { - self.offsets.push(this[0]) - self.targets.push(this[1]) - }) + for (i = offsets.length; i--;) { + activeTarget != targets[i] + && scrollTop >= offsets[i] + && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) + && this.activate(targets[i]) } + } - ScrollSpy.prototype.process = function () { - var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - 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[targets.length - 1]) && this.activate(i) - } - - if (activeTarget && scrollTop <= offsets[0]) { - return activeTarget != (i = targets[0]) && this.activate(i) - } - - for (i = offsets.length; i--;) { - activeTarget != targets[i] - && scrollTop >= offsets[i] - && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate(targets[i]) - } - } + ScrollSpy.prototype.activate = function (target) { + this.activeTarget = target - ScrollSpy.prototype.activate = function (target) { - this.activeTarget = target + $(this.selector) + .parentsUntil(this.options.target, '.active') + .removeClass('active') - $(this.selector) - .parentsUntil(this.options.target, '.active') - .removeClass('active') + var selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' - var selector = this.selector + - '[data-target="' + target + '"],' + - this.selector + '[href="' + target + '"]' + var active = $(selector) + .parents('li') + .addClass('active') - var active = $(selector) - .parents('li') + if (active.parent('.dropdown-menu').length) { + active = active + .closest('li.dropdown') .addClass('active') - - if (active.parent('.dropdown-menu').length) { - active = active - .closest('li.dropdown') - .addClass('active') - } - - active.trigger('activate.bs.scrollspy') } + active.trigger('activate.bs.scrollspy') + } - // SCROLLSPY PLUGIN DEFINITION - // =========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.scrollspy') - var options = typeof option == 'object' && option + // SCROLLSPY PLUGIN DEFINITION + // =========================== - if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) - if (typeof option == 'string') data[option]() - }) - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.scrollspy') + var options = typeof option == 'object' && option - var old = $.fn.scrollspy + if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) + if (typeof option == 'string') data[option]() + }) + } - $.fn.scrollspy = Plugin - $.fn.scrollspy.Constructor = ScrollSpy + var old = $.fn.scrollspy + $.fn.scrollspy = Plugin + $.fn.scrollspy.Constructor = ScrollSpy - // SCROLLSPY NO CONFLICT - // ===================== - $.fn.scrollspy.noConflict = function () { - $.fn.scrollspy = old - return this - } + // SCROLLSPY NO CONFLICT + // ===================== + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } - // SCROLLSPY DATA-API - // ================== - $(window).on('load.bs.scrollspy.data-api', function () { - $('[data-spy="scroll"]').each(function () { - var $spy = $(this) - Plugin.call($spy, $spy.data()) - }) - }) + // SCROLLSPY DATA-API + // ================== + $(window).on('load.bs.scrollspy.data-api', function () { + $('[data-spy="scroll"]').each(function () { + var $spy = $(this) + Plugin.call($spy, $spy.data()) + }) }) -}(); +}(jQuery); -- cgit v1.2.3 From ff6b279b3cd37e7e4e6bd93535afd016f6957afc Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Thu, 26 Jun 2014 09:13:24 -0700 Subject: bump to v3.2.0 --- js/scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index e7d3a8b87..db2378787 100644 --- a/js/scrollspy.js +++ b/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. @@ -30,7 +30,7 @@ this.process() } - ScrollSpy.VERSION = '3.1.1' + ScrollSpy.VERSION = '3.2.0' ScrollSpy.DEFAULTS = { offset: 10 -- cgit v1.2.3