-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): on first hash-set, dont set scrollTop
- Loading branch information
Showing
6 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,27 @@ | ||
angular.module('ionic.decorator.location', []) | ||
|
||
.config(['$provide', function($provide) { | ||
$provide.decorator('$location', ['$delegate', '$timeout', $LocationDecorator]); | ||
}]); | ||
|
||
function $LocationDecorator($location, $timeout) { | ||
|
||
var firstHashSet = false; | ||
$location.__hash = $location.hash; | ||
//Fix: first time window.location.hash is set, the scrollable area | ||
//found nearest to body's scrollTop is set to scroll to an element | ||
//with that ID. | ||
$location.hash = function(value) { | ||
if (!firstHashSet && angular.isDefined(value)) { | ||
$timeout(function() { | ||
var scroll = document.querySelector('.scroll-content'); | ||
if (scroll) | ||
scroll.scrollTop = 0; | ||
}, 0, false); | ||
firstHashSet = true; | ||
} | ||
return $location.__hash(value); | ||
}; | ||
|
||
return $location; | ||
} |
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
describe('$location decorator', function() { | ||
|
||
beforeEach(module('ionic.decorator.location')); | ||
|
||
describe('.hash()', function() { | ||
|
||
it('should find .scroll-content and set scrollTop=0', inject(function($location, $timeout, $rootScope) { | ||
var scroll = { scrollTop: 5 }; | ||
spyOn(document, 'querySelector').andCallFake(function() { | ||
return scroll; | ||
}); | ||
|
||
$location.hash('123'); | ||
$timeout.flush(); | ||
expect(scroll.scrollTop).toBe(0); | ||
|
||
//Second time? shouldnt try to set things | ||
scroll.scrollTop = 4; | ||
$location.hash('456'); | ||
$timeout.verifyNoPendingTasks(); | ||
expect(scroll.scrollTop).toBe(4); | ||
})); | ||
|
||
}); | ||
}); |
This file contains 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