Skip to content

Commit

Permalink
fix scrollspy for window *and* children
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Jul 27, 2013
1 parent 2cf1851 commit cfa4ab9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,10 +1569,10 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
function ScrollSpy(element, options) {
var href
var process = $.proxy(this.process, this)
var $element = $(element).is('body') ? $(window) : $(element)

this.$element = $(element).is('body') ? $(window) : $(element)
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.selector = (this.options.target
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
Expand All @@ -1590,6 +1590,8 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
}

ScrollSpy.prototype.refresh = function () {
var offsetMethod = this.$element[0] == window ? 'offset' : 'position'

this.offsets = $([])
this.targets = $([])

Expand All @@ -1603,7 +1605,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }

return ($href
&& $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] })
.each(function () {
Expand Down
Loading

0 comments on commit cfa4ab9

Please sign in to comment.