summaryrefslogtreecommitdiff
path: root/assets/js/bootstrap-scrollspy.js
diff options
context:
space:
mode:
authorThomas Park <thomas@thomaspark.me>2012-05-03 13:48:57 -0400
committerThomas Park <thomas@thomaspark.me>2012-05-03 13:48:57 -0400
commit0f0a0f9f8a57dc9e22839b2706ced578755518ef (patch)
tree9f6f2a702f46602a438a280ace67b268a0ed1911 /assets/js/bootstrap-scrollspy.js
parent1e104e46ac4ac608705cc4b81fa092d178de3b91 (diff)
index: updated site itself to 2.0.3
Diffstat (limited to 'assets/js/bootstrap-scrollspy.js')
-rwxr-xr-xassets/js/bootstrap-scrollspy.js62
1 files changed, 44 insertions, 18 deletions
diff --git a/assets/js/bootstrap-scrollspy.js b/assets/js/bootstrap-scrollspy.js
index ea29f2f8..4946ee93 100755
--- a/assets/js/bootstrap-scrollspy.js
+++ b/assets/js/bootstrap-scrollspy.js
@@ -1,5 +1,5 @@
/* =============================================================
- * bootstrap-scrollspy.js v2.0.2
+ * bootstrap-scrollspy.js v2.0.3
* http://twitter.github.com/bootstrap/javascript.html#scrollspy
* =============================================================
* Copyright 2012 Twitter, Inc.
@@ -17,9 +17,11 @@
* limitations under the License.
* ============================================================== */
-!function ( $ ) {
- "use strict"
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
/* SCROLLSPY CLASS DEFINITION
* ========================== */
@@ -33,7 +35,7 @@
this.selector = (this.options.target
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|| '') + ' .nav li > a'
- this.$body = $('body').on('click.scroll.data-api', this.selector, process)
+ this.$body = $('body')
this.refresh()
this.process()
}
@@ -43,25 +45,43 @@
constructor: ScrollSpy
, refresh: function () {
- this.targets = this.$body
+ var self = this
+ , $targets
+
+ this.offsets = $([])
+ this.targets = $([])
+
+ $targets = this.$body
.find(this.selector)
.map(function () {
- var href = $(this).attr('href')
- return /^#\w/.test(href) && $(href).length ? href : null
+ var $el = $(this)
+ , href = $el.data('target') || $el.attr('href')
+ , $href = /^#\w/.test(href) && $(href)
+ return ( $href
+ && href.length
+ && [[ $href.position().top, href ]] ) || null
+ })
+ .sort(function (a, b) { return a[0] - b[0] })
+ .each(function () {
+ self.offsets.push(this[0])
+ self.targets.push(this[1])
})
-
- this.offsets = $.map(this.targets, function (id) {
- return $(id).position().top
- })
}
, process: function () {
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
+ , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
+ , maxScroll = scrollHeight - this.$scrollElement.height()
, offsets = this.offsets
, targets = this.targets
, activeTarget = this.activeTarget
, i
+ if (scrollTop >= maxScroll) {
+ return activeTarget != (i = targets.last()[0])
+ && this.activate ( i )
+ }
+
for (i = offsets.length; i--;) {
activeTarget != targets[i]
&& scrollTop >= offsets[i]
@@ -72,21 +92,27 @@
, activate: function (target) {
var active
+ , selector
this.activeTarget = target
- this.$body
- .find(this.selector).parent('.active')
+ $(this.selector)
+ .parent('.active')
.removeClass('active')
- active = this.$body
- .find(this.selector + '[href="' + target + '"]')
+ selector = this.selector
+ + '[data-target="' + target + '"],'
+ + this.selector + '[href="' + target + '"]'
+
+ active = $(selector)
.parent('li')
.addClass('active')
- if ( active.parent('.dropdown-menu') ) {
- active.closest('li.dropdown').addClass('active')
+ if (active.parent('.dropdown-menu')) {
+ active = active.closest('li.dropdown').addClass('active')
}
+
+ active.trigger('activate')
}
}
@@ -122,4 +148,4 @@
})
})
-}( window.jQuery ); \ No newline at end of file
+}(window.jQuery); \ No newline at end of file