diff options
| author | Jacob Thornton <[email protected]> | 2011-11-20 20:58:04 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2011-11-20 20:58:04 -0800 |
| commit | bc65b58551575c9dfb2e4d9f4f7af97009e39432 (patch) | |
| tree | cb27a6f15bfdd7650871f6f6aa5aba496201bd29 /js/bootstrap-scrollspy.js | |
| parent | 0b1d5d9189ea82cde5e848e5a8771a8f4850e21f (diff) | |
| download | bootstrap-bc65b58551575c9dfb2e4d9f4f7af97009e39432.tar.xz bootstrap-bc65b58551575c9dfb2e4d9f4f7af97009e39432.zip | |
merge in js from 1.4... start working through js docs
Diffstat (limited to 'js/bootstrap-scrollspy.js')
| -rw-r--r-- | js/bootstrap-scrollspy.js | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 1269d91ec..91c2dcb1e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -20,33 +20,34 @@ !function ( $ ) { - var $window = $(window) - function ScrollSpy() { var process = $.proxy(this.process, this) - this.$topbar = $('body') - this.selector = '[data-scrollspy] li > a' + this.selector = '.nav li > a' + + this.$body = $('body').delegate(this.selector, 'click', process) + this.$scrollElement = $('[data-spy="scroll"]').bind('scroll', process) + this.refresh() - this.$topbar.delegate(this.selector, 'click', process) - $window.scroll(process) this.process() } ScrollSpy.prototype = { refresh: function () { - this.targets = this.$topbar.find(this.selector).map(function () { - var href = $(this).attr('href') - return /^#\w/.test(href) && $(href).length ? href : null - }) + this.targets = this.$body + .find(this.selector) + .map(function () { + var href = $(this).attr('href') + return /^#\w/.test(href) && $(href).length ? href : null + }) this.offsets = $.map(this.targets, function (id) { - return $(id).offset().top + return $(id).position().top }) } , process: function () { - var scrollTop = $window.scrollTop() + 10 + var scrollTop = this.$scrollElement.scrollTop() + 10 , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget @@ -65,11 +66,11 @@ this.activeTarget = target - this.$topbar + this.$body .find(this.selector).parent('.active') .removeClass('active') - active = this.$topbar + active = this.$body .find(this.selector + '[href="' + target + '"]') .parent('li') .addClass('active') @@ -82,8 +83,6 @@ } - $(function () { - new ScrollSpy() - }) + $(function () { new ScrollSpy() }) }( window.jQuery || window.ender )
\ No newline at end of file |
