mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 06:36:33 +02:00
fix scrollspy for window *and* children
This commit is contained in:
8
dist/js/bootstrap.js
vendored
8
dist/js/bootstrap.js
vendored
@@ -1569,10 +1569,10 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
|
|||||||
function ScrollSpy(element, options) {
|
function ScrollSpy(element, options) {
|
||||||
var href
|
var href
|
||||||
var process = $.proxy(this.process, this)
|
var process = $.proxy(this.process, this)
|
||||||
var $element = $(element).is('body') ? $(window) : $(element)
|
|
||||||
|
|
||||||
|
this.$element = $(element).is('body') ? $(window) : $(element)
|
||||||
this.$body = $('body')
|
this.$body = $('body')
|
||||||
this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process)
|
this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process)
|
||||||
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
||||||
this.selector = (this.options.target
|
this.selector = (this.options.target
|
||||||
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
||||||
@@ -1590,6 +1590,8 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScrollSpy.prototype.refresh = function () {
|
ScrollSpy.prototype.refresh = function () {
|
||||||
|
var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
|
||||||
|
|
||||||
this.offsets = $([])
|
this.offsets = $([])
|
||||||
this.targets = $([])
|
this.targets = $([])
|
||||||
|
|
||||||
@@ -1603,7 +1605,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
|
|||||||
|
|
||||||
return ($href
|
return ($href
|
||||||
&& $href.length
|
&& $href.length
|
||||||
&& [[ $href.offset().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] })
|
.sort(function (a, b) { return a[0] - b[0] })
|
||||||
.each(function () {
|
.each(function () {
|
||||||
|
2
dist/js/bootstrap.min.js
vendored
2
dist/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -26,10 +26,10 @@
|
|||||||
function ScrollSpy(element, options) {
|
function ScrollSpy(element, options) {
|
||||||
var href
|
var href
|
||||||
var process = $.proxy(this.process, this)
|
var process = $.proxy(this.process, this)
|
||||||
var $element = $(element).is('body') ? $(window) : $(element)
|
|
||||||
|
|
||||||
|
this.$element = $(element).is('body') ? $(window) : $(element)
|
||||||
this.$body = $('body')
|
this.$body = $('body')
|
||||||
this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process)
|
this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process)
|
||||||
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
||||||
this.selector = (this.options.target
|
this.selector = (this.options.target
|
||||||
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
||||||
@@ -47,6 +47,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScrollSpy.prototype.refresh = function () {
|
ScrollSpy.prototype.refresh = function () {
|
||||||
|
var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
|
||||||
|
|
||||||
this.offsets = $([])
|
this.offsets = $([])
|
||||||
this.targets = $([])
|
this.targets = $([])
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@
|
|||||||
|
|
||||||
return ($href
|
return ($href
|
||||||
&& $href.length
|
&& $href.length
|
||||||
&& [[ $href.offset().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] })
|
.sort(function (a, b) { return a[0] - b[0] })
|
||||||
.each(function () {
|
.each(function () {
|
||||||
|
Reference in New Issue
Block a user