1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-25 21:09:06 +02:00

fix scrollspy simplify stuff more - break everything.

This commit is contained in:
Jacob Thornton
2011-10-19 23:12:50 -07:00
parent 5ab84f942d
commit 523e02f7df
10 changed files with 78 additions and 57 deletions

View File

@@ -1,5 +1,5 @@
/* =============================================================
* bootstrap-scrollspy.js v1.3.0
* bootstrap-scrollspy.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html#scrollspy
* =============================================================
* Copyright 2011 Twitter, Inc.
@@ -22,14 +22,14 @@
var $window = $(window)
function ScrollSpy( topbar, selector ) {
var processScroll = $.proxy(this.processScroll, this)
this.$topbar = $(topbar)
this.selector = selector || 'li > a'
function ScrollSpy() {
var process = $.proxy(this.process, this)
this.$topbar = $('body')
this.selector = '[data-scrollspy] li > a'
this.refresh()
this.$topbar.delegate(this.selector, 'click', processScroll)
$window.scroll(processScroll)
this.processScroll()
this.$topbar.delegate(this.selector, 'click', process)
$window.scroll(process)
this.process()
}
ScrollSpy.prototype = {
@@ -45,7 +45,7 @@
})
}
, processScroll: function () {
, process: function () {
var scrollTop = $window.scrollTop() + 10
, offsets = this.offsets
, targets = this.targets
@@ -56,27 +56,34 @@
activeTarget != targets[i]
&& scrollTop >= offsets[i]
&& (!offsets[i + 1] || scrollTop <= offsets[i + 1])
&& this.activateButton( targets[i] )
&& this.activate( targets[i] )
}
}
, activateButton: function (target) {
, activate: function (target) {
var active
this.activeTarget = target
this.$topbar
.find(this.selector).parent('.active')
.removeClass('active')
this.$topbar
active = this.$topbar
.find(this.selector + '[href="' + target + '"]')
.parent('li')
.addClass('active')
if ( active.parent('.dropdown-menu') ) {
active.closest('li.dropdown').addClass('active')
}
}
}
$(function () {
$('body').scrollSpy('[data-scrollspy] li > a')
new ScrollSpy()
})
}( window.jQuery || window.ender )