diff options
| author | Maxim Andrukhovych <[email protected]> | 2015-03-10 20:04:15 +0000 |
|---|---|---|
| committer | Maxim Andrukhovych <[email protected]> | 2015-03-10 20:04:15 +0000 |
| commit | 83371735fcc4ceba3c1b35d91bb3ba8c41365861 (patch) | |
| tree | ebda3b8885baf30a7b4eff271f48468ba5d6d996 | |
| parent | 9d0259d8d142b6b1ae19436507155e46359cd7c5 (diff) | |
| download | bootstrap-83371735fcc4ceba3c1b35d91bb3ba8c41365861.tar.xz bootstrap-83371735fcc4ceba3c1b35d91bb3ba8c41365861.zip | |
Fixed proper navigation element selection on backward scrolling (from the bottom to the top)
| -rw-r--r-- | js/scrollspy.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/scrollspy.js | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js index 9b29edf49..f2d9b5ab8 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 fe80e57b7..bf5fa0bff 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 = + '<nav class="navbar">' + + '<ul class="nav">' + + '<li id="li-100-1"><a href="#div-100-1">div 1</a></li>' + + '<li id="li-100-2"><a href="#div-100-2">div 2</a></li>' + + '<li id="li-100-3"><a href="#div-100-3">div 3</a></li>' + + '<li id="li-100-4"><a href="#div-100-4">div 4</a></li>' + + '<li id="li-100-5"><a href="#div-100-5">div 5</a></li>' + + '</ul>' + + '</nav>' + var contentHtml = + '<div class="content" style="position: relative; overflow: auto; height: 100px">' + + '<div id="div-100-1" style="position: relative; height: 100%; padding: 0; margin: 0">div 1</div>' + + '<div id="div-100-2" style="position: relative; height: 100%; padding: 0; margin: 0">div 2</div>' + + '<div id="div-100-3" style="position: relative; height: 100%; padding: 0; margin: 0">div 3</div>' + + '<div id="div-100-4" style="position: relative; height: 100%; padding: 0; margin: 0">div 4</div>' + + '<div id="div-100-5" style="position: relative; height: 100%; padding: 0; margin: 0">div 5</div>' + + '</div>' + + $(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') }) + }) + }) |
