mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(scrollView): cancel scrollTop every time hash is set
Before it, only cancelled scrollTop the first time the hash was set. Addresses #618
This commit is contained in:
@@ -6,19 +6,17 @@ angular.module('ionic.decorator.location', [])
|
||||
|
||||
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)) {
|
||||
if (angular.isDefined(value)) {
|
||||
$timeout(function() {
|
||||
var scroll = document.querySelector('.scroll-content');
|
||||
if (scroll)
|
||||
scroll.scrollTop = 0;
|
||||
}, 0, false);
|
||||
firstHashSet = true;
|
||||
}
|
||||
return $location.__hash(value);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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) {
|
||||
@@ -13,12 +13,6 @@ describe('$location decorator', function() {
|
||||
$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);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user