This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($location): fix handling of hash fragment links #10190
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/e2e/fixtures/ng/location/hashFragmentScrolling/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Regression test for [#8675](https://github.com/angular/angular.js/issues/8675). | ||
|
||
Makes sure that hash fragment links actually jump to the relevant document fragment when `$location` | ||
is injected and configured to operate in hashbang mode. In order to use this fix, you need to inject | ||
the `$anchorScroll` service somewhere in your application, and also add the following config block | ||
to your application: | ||
|
||
```js | ||
function($locationProvider) { | ||
$locationProvider.fixHashFragmentLinks(true); | ||
} | ||
``` |
13 changes: 13 additions & 0 deletions
13
test/e2e/fixtures/ng/location/hashFragmentScrolling/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html ng-app="test"> | ||
<div ng-controller="TestCtrl"> | ||
<a id="click-me" href="#some-section">Click me</a> | ||
|
||
<div style="height:9999px;"></div> | ||
|
||
<h1 id="some-section" style="height:500px">Should scroll here</h1> | ||
</div> | ||
|
||
<script src="/build/angular.js"></script> | ||
<script src="script.js"></script> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
test/e2e/fixtures/ng/location/hashFragmentScrolling/script.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
angular.module("test", []) | ||
.config(function($locationProvider) { | ||
$locationProvider.fixHashFragmentLinks(true); | ||
}) | ||
.controller("TestCtrl", function($scope, $anchorScroll) { | ||
// $anchorScroll is required for handling automatic scrolling for hash fragment links | ||
}); |
18 changes: 18 additions & 0 deletions
18
test/e2e/tests/ng/location/hashFragmentScrolling/hashFragmentScrollingSpec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe('Hash Fragment Scrolling', function() { | ||
beforeEach(function() { | ||
loadFixture("ng/location/hashFragmentScrolling").andWaitForAngular(); | ||
}); | ||
|
||
it('should scroll to the element whose id appears in the hash part of the link', function() { | ||
var initialScrollTop = null; | ||
// Firefox requires window.pageYOffset (document.body.scrollTop is always 0) | ||
browser.executeScript('return document.body.scrollTop||window.pageYOffset;').then(function(scrollTop) { | ||
initialScrollTop = scrollTop; | ||
}); | ||
element(by.id('click-me')).click(); | ||
browser.executeScript('return document.body.scrollTop||window.pageYOffset;').then(function(scrollTop) { | ||
expect(scrollTop).toBeGreaterThan(initialScrollTop); | ||
}); | ||
expect(browser.executeScript('return document.location.hash;')).toBe('##some-section'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is causing an error in Travis (and looks like it's causing all subsequent tests to fail).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this reproduce? A similar line already exists in this test, so I don't see a reason why it would break here...