From 5a2c7eb50abae8d07cebb6b0e984f7e63843cf75 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 15:18:00 -0700 Subject: select last item in scrollspy if you've reached the bottom of the document or element --- js/bootstrap-scrollspy.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index ea29f2f86..47b485785 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -57,11 +57,18 @@ , 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] -- cgit v1.2.3 From bf59220b87a3b5960381f500dbc6a310a8aef60b Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 15:19:01 -0700 Subject: ;) --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 47b485785..b7ff907f7 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -66,7 +66,7 @@ if (scrollTop >= maxScroll) { return activeTarget != (i = targets.last()[0]) - && this.activate ( i ); + && this.activate ( i ) } for (i = offsets.length; i--;) { -- cgit v1.2.3 From 05e0d5f3d931e84f3bc86a5c1153e710237cb53a Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 16:09:08 -0700 Subject: fire active event on active --- js/bootstrap-scrollspy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index b7ff907f7..dea6e95f0 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -92,8 +92,10 @@ .addClass('active') if ( active.parent('.dropdown-menu') ) { - active.closest('li.dropdown').addClass('active') + active = active.closest('li.dropdown').addClass('active') } + + active.trigger('active') } } -- cgit v1.2.3 From 384a082e8d220115d0eb94b0c57d837b625ad2ab Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 20:24:46 -0700 Subject: active - onActivate --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index dea6e95f0..e0c74539e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -95,7 +95,7 @@ active = active.closest('li.dropdown').addClass('active') } - active.trigger('active') + active.trigger('activate') } } -- cgit v1.2.3 From 706ee46b73b58059230b24589160da784778aad2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 21 Mar 2012 23:45:58 -0700 Subject: sort scrollspy to prevent flicker for unordered nav --- js/bootstrap-scrollspy.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index e0c74539e..5008b0fe9 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -43,16 +43,25 @@ 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 + return /^#\w/.test(href) + && $(href).length + && [[ $(href).position().top, href ]] + }) + .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 () { -- cgit v1.2.3 From 20e085723b3f55fdc1db7f1687d535af7d127319 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 21 Mar 2012 23:51:32 -0700 Subject: cache $(href) lookup --- js/bootstrap-scrollspy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 5008b0fe9..487e6818b 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -53,9 +53,10 @@ .find(this.selector) .map(function () { var href = $(this).attr('href') - return /^#\w/.test(href) - && $(href).length - && [[ $(href).position().top, href ]] + , $href = /^#\w/.test(href) && $(href) + return $href + && href.length + && [[ $href.position().top, href ]] }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { -- cgit v1.2.3 From b3bf223617754e658eb62ef0f068732e719a2c82 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 21 Mar 2012 23:59:27 -0700 Subject: filter out non matches in map --- js/bootstrap-scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 487e6818b..bd3f10604 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -54,9 +54,9 @@ .map(function () { var href = $(this).attr('href') , $href = /^#\w/.test(href) && $(href) - return $href + return ( $href && href.length - && [[ $href.position().top, href ]] + && [[ $href.position().top, href ]] ) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { -- cgit v1.2.3 From bccc2cb7191eb54a4d67563625a748d7ecd381d4 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 24 Mar 2012 18:20:09 -0700 Subject: add preventDefault support for all inital event types (show, close, hide, etc.) + fix small bug with scrollspy.last --- js/bootstrap-scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index bd3f10604..c02e263b0 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -46,8 +46,8 @@ var self = this , $targets - this.offsets = [] - this.targets = [] + this.offsets = $([]) + this.targets = $([]) $targets = this.$body .find(this.selector) -- cgit v1.2.3 From f02d017ffa2f63609db034410979f62fde328816 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 24 Mar 2012 18:59:04 -0700 Subject: return matcher value directly + cleanup first lines of files --- js/bootstrap-scrollspy.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index c02e263b0..518ccafb2 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -17,6 +17,7 @@ * limitations under the License. * ============================================================== */ + !function ( $ ) { "use strict" -- cgit v1.2.3 From 575f18aaf49abb0289185f6409bee031947ccf69 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 14 Apr 2012 16:29:53 -0700 Subject: add jshint support + a few minor stylistic changes --- js/bootstrap-scrollspy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 518ccafb2..3dee609c7 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -18,9 +18,10 @@ * ============================================================== */ -!function ( $ ) { +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* SCROLLSPY CLASS DEFINITION * ========================== */ @@ -142,4 +143,4 @@ }) }) -}( window.jQuery ); \ No newline at end of file +}(window.jQuery); \ No newline at end of file -- cgit v1.2.3 From 1ca1ef94ee80b8c5fa5f2a1e908a8d00fdfdf268 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 14 Apr 2012 23:24:19 -0700 Subject: fix opera bug \o/ !!!! #1776 --- js/bootstrap-scrollspy.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 3dee609c7..f0400813f 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -94,12 +94,11 @@ this.activeTarget = target - this.$body - .find(this.selector).parent('.active') + $(this.selector) + .parent('.active') .removeClass('active') - active = this.$body - .find(this.selector + '[href="' + target + '"]') + active = $(this.selector + '[href="' + target + '"]') .parent('li') .addClass('active') -- cgit v1.2.3 From be0efcfcfca603bc65484464e0aeaf7b2fc145c2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 14 Apr 2012 23:38:11 -0700 Subject: whitespace --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index f0400813f..c67f1c8aa 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -102,7 +102,7 @@ .parent('li') .addClass('active') - if ( active.parent('.dropdown-menu') ) { + if (active.parent('.dropdown-menu')) { active = active.closest('li.dropdown').addClass('active') } -- cgit v1.2.3 From bc07e2adae7bc61795d54681915d791aee41c49a Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 18 Apr 2012 13:35:14 -0700 Subject: allow for pushstate in scrollspy --- js/bootstrap-scrollspy.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index c67f1c8aa..5c19ae382 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -54,7 +54,8 @@ $targets = this.$body .find(this.selector) .map(function () { - var href = $(this).attr('href') + var $el = $(this) + , href = $el.data('target') || $el.attr('href') , $href = /^#\w/.test(href) && $(href) return ( $href && href.length @@ -91,6 +92,7 @@ , activate: function (target) { var active + , selector this.activeTarget = target @@ -98,7 +100,11 @@ .parent('.active') .removeClass('active') - active = $(this.selector + '[href="' + target + '"]') + selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' + + active = $(selector) .parent('li') .addClass('active') -- cgit v1.2.3 From 839ef3a030b355d0f0c35d6c9e42ecba8b072036 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 24 Apr 2012 02:19:02 -0700 Subject: 2.0.2 -> 2.0.3 --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 5c19ae382..f6a24b003 100644 --- a/js/bootstrap-scrollspy.js +++ b/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. -- cgit v1.2.3