From 9f30f557213f1e8f821414473550639f5f93f29a Mon Sep 17 00:00:00 2001 From: moodyroto Date: Mon, 11 Nov 2013 12:21:34 -0500 Subject: [PATCH 1/2] Update scrollspy.js Scrollspy target in tab content does not work properly. Calling .parents('.active') will return all parents with an active class (including the tab pane). Changing this line to .parentsUntil(this.options.target, '.active') should resolve the issue. This will scope the query to only search for active elements inside the scrollspy target. --- js/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/scrollspy.js b/js/scrollspy.js index 1d2fc78595..295c2e0758 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -96,7 +96,7 @@ this.activeTarget = target $(this.selector) - .parents('.active') + .parentsUntil(this.options.target, '.active') .removeClass('active') var selector = this.selector From 24e3a8b859aa82707c53fd22dd785195fbb45c59 Mon Sep 17 00:00:00 2001 From: Michael Rotoloni Date: Mon, 18 Nov 2013 09:29:10 -0500 Subject: [PATCH 2/2] Added unit test for removing only active class from within the scroll spy key. --- js/tests/unit/scrollspy.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 06219a1c8d..126b5c9d7e 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -34,4 +34,41 @@ $(function () { ok($topbar.find('.active', true)) }) + test("should only switch active class on current target", function () { + var + sectionHTML = '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '

Overview

' + + '

' + + 'Ad leggings keytar, brunch id art party dolor labore.' + + '

' + + '
' + + '
' + + '

Detail

' + + '

' + + 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + + '

' + + '
' + + '
' + + '
' + , $section = $(sectionHTML).appendTo("#qunit-fixture") + , $scrollSpy = $section + .show() + .find("#scrollspy-example") + .scrollspy({target: "#ss-target"}) + + $scrollSpy.scrollTop(350); + ok($section.hasClass("active"), "Active class still on root node") + }) })