diff options
| author | Mark Otto <[email protected]> | 2014-06-08 13:57:44 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2014-06-08 13:57:44 -0700 |
| commit | d1872b4c98f26b1bfcd7e007133b97e6602dd0d0 (patch) | |
| tree | ccc12bda1d6df512fbc9c4023b296f46a6f05e3f /js/scrollspy.js | |
| parent | 5872a7e0aca5e2b5b8e0be5df8b2a7cdf987d805 (diff) | |
| parent | 5cd72ce23058b47a739c7e2005ab5c3d4e28ff30 (diff) | |
| download | bootstrap-d1872b4c98f26b1bfcd7e007133b97e6602dd0d0.tar.xz bootstrap-d1872b4c98f26b1bfcd7e007133b97e6602dd0d0.zip | |
Merge branch 'master' into pr/13736
Conflicts:
dist/css/bootstrap.css.map
dist/css/bootstrap.min.css
Diffstat (limited to 'js/scrollspy.js')
| -rw-r--r-- | js/scrollspy.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js index 53e1c48ba..644c65f94 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -14,20 +14,17 @@ // ========================== 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.$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.$scrollElement.on('scroll.bs.scrollspy', process) this.refresh() this.process() } @@ -39,10 +36,16 @@ } 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 = [] var self = this @@ -57,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 () { @@ -76,7 +79,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]) { @@ -87,7 +90,7 @@ activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate( targets[i] ) + && this.activate(targets[i]) } } |
