diff options
| author | Jacob Thornton <[email protected]> | 2011-10-19 23:12:50 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2011-10-19 23:12:50 -0700 |
| commit | 523e02f7df3bb706654b43cf604e61c9396212e1 (patch) | |
| tree | 5c835652ac9f49a82934227b63e79589edbe24d9 /js/bootstrap-scrollspy.js | |
| parent | 5ab84f942dadc02db57fbe9dbcc619a5eae3920a (diff) | |
| download | bootstrap-523e02f7df3bb706654b43cf604e61c9396212e1.tar.xz bootstrap-523e02f7df3bb706654b43cf604e61c9396212e1.zip | |
fix scrollspy simplify stuff more - break everything.
Diffstat (limited to 'js/bootstrap-scrollspy.js')
| -rw-r--r-- | js/bootstrap-scrollspy.js | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 23bdf59e9..1269d91ec 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -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 )
\ No newline at end of file |
