mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-08 17:22:31 +03:00
change hella js... broke all the tests. i <3 wip
This commit is contained in:
Vendored
+30
-13
@@ -22,21 +22,20 @@
|
||||
|
||||
var $window = $(window)
|
||||
|
||||
function ScrollSpy( topbar ) {
|
||||
function ScrollSpy( topbar, selector ) {
|
||||
var processScroll = $.proxy(this.processScroll, this)
|
||||
this.$topbar = $(topbar)
|
||||
this.setup()
|
||||
this.$topbar
|
||||
.delegate('li > a', 'click', processScroll)
|
||||
.bind('topbar:refresh', $.proxy(this.setup, this))
|
||||
this.selector = selector || 'li > a'
|
||||
this.refresh()
|
||||
this.$topbar.delegate(this.selector, 'click', processScroll)
|
||||
$window.scroll(processScroll)
|
||||
this.processScroll()
|
||||
}
|
||||
|
||||
ScrollSpy.prototype = {
|
||||
|
||||
setup: function () {
|
||||
this.targets = this.$topbar.find('li > a').map(function () {
|
||||
refresh: function () {
|
||||
this.targets = this.$topbar.find(this.selector).map(function () {
|
||||
var href = $(this).attr('href')
|
||||
return /^#\w/.test(href) && $(href).length ? href : null
|
||||
})
|
||||
@@ -65,11 +64,11 @@
|
||||
this.activeTarget = target
|
||||
|
||||
this.$topbar
|
||||
.find('.active')
|
||||
.find(this.selector).parent('.active')
|
||||
.removeClass('active')
|
||||
|
||||
this.$topbar
|
||||
.find('a[href=' + target + ']')
|
||||
.find(this.selector + '[href="' + target + '"]')
|
||||
.parent('li')
|
||||
.addClass('active')
|
||||
}
|
||||
@@ -79,10 +78,28 @@
|
||||
/* SCROLLSPY PLUGIN DEFINITION
|
||||
* =========================== */
|
||||
|
||||
$.fn.scrollSpy = function() {
|
||||
return this.each(function () {
|
||||
new ScrollSpy(this)
|
||||
})
|
||||
$.fn.scrollSpy = function( options ) {
|
||||
var scrollspy = this.data('scrollspy')
|
||||
|
||||
if (!scrollspy) {
|
||||
return this.each(function () {
|
||||
$(this).data('scrollspy', new ScrollSpy( this, options ))
|
||||
})
|
||||
}
|
||||
|
||||
if ( options === true ) {
|
||||
return scrollspy
|
||||
}
|
||||
|
||||
if ( typeof options == 'string' ) {
|
||||
scrollspy[options]()
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('body').scrollSpy('[data-scrollspy] li > a')
|
||||
})
|
||||
|
||||
}( jQuery || ender )
|
||||
Reference in New Issue
Block a user