From: Maxim Andrukhovych Date: Tue, 10 Mar 2015 20:04:15 +0000 (+0000) Subject: Fixed proper navigation element selection on backward scrolling (from the bottom... X-Git-Tag: v3.3.4~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83371735fcc4ceba3c1b35d91bb3ba8c41365861;p=thirdparty%2Fbootstrap.git Fixed proper navigation element selection on backward scrolling (from the bottom to the top) --- diff --git a/js/scrollspy.js b/js/scrollspy.js index 9b29edf490..f2d9b5ab84 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -96,7 +96,7 @@ for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] - && (offsets[i + 1] === undefined || scrollTop <= offsets[i + 1]) + && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1]) && this.activate(targets[i]) } } diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index fe80e57b7f..bf5fa0bff5 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -229,4 +229,50 @@ $(function () { .scrollTop(201) }) + QUnit.test('should correctly select navigation element on backward scrolling when each target section height is 100%', function (assert) { + assert.expect(5) + var navbarHtml = + '' + var contentHtml = + '
' + + '
div 1
' + + '
div 2
' + + '
div 3
' + + '
div 4
' + + '
div 5
' + + '
' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ offset: 0, target: '.navbar' }) + + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) + var done = assert.async() + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element: ' + element) + done() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#li-100-5', '#div-100-5')) + .then(function () { return testElementIsActiveAfterScroll('#li-100-4', '#div-100-4') }) + .then(function () { return testElementIsActiveAfterScroll('#li-100-3', '#div-100-3') }) + .then(function () { return testElementIsActiveAfterScroll('#li-100-2', '#div-100-2') }) + .then(function () { return testElementIsActiveAfterScroll('#li-100-1', '#div-100-1') }) + }) + })