Skip to content

Commit e1b6fd4

Browse files
committed
fix(scrollView): cancel scrollTop every time hash is set
Before it, only cancelled scrollTop the first time the hash was set. Addresses #618
1 parent 3901b74 commit e1b6fd4

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

js/ext/angular/src/service/decorators/location.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ angular.module('ionic.decorator.location', [])
66

77
function $LocationDecorator($location, $timeout) {
88

9-
var firstHashSet = false;
109
$location.__hash = $location.hash;
1110
//Fix: first time window.location.hash is set, the scrollable area
1211
//found nearest to body's scrollTop is set to scroll to an element
1312
//with that ID.
1413
$location.hash = function(value) {
15-
if (!firstHashSet && angular.isDefined(value)) {
14+
if (angular.isDefined(value)) {
1615
$timeout(function() {
1716
var scroll = document.querySelector('.scroll-content');
1817
if (scroll)
1918
scroll.scrollTop = 0;
2019
}, 0, false);
21-
firstHashSet = true;
2220
}
2321
return $location.__hash(value);
2422
};

js/ext/angular/test/service/decorators/location.unit.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('$location decorator', function() {
22

33
beforeEach(module('ionic.decorator.location'));
4-
4+
55
describe('.hash()', function() {
66

77
it('should find .scroll-content and set scrollTop=0', inject(function($location, $timeout, $rootScope) {
@@ -13,12 +13,6 @@ describe('$location decorator', function() {
1313
$location.hash('123');
1414
$timeout.flush();
1515
expect(scroll.scrollTop).toBe(0);
16-
17-
//Second time? shouldnt try to set things
18-
scroll.scrollTop = 4;
19-
$location.hash('456');
20-
$timeout.verifyNoPendingTasks();
21-
expect(scroll.scrollTop).toBe(4);
2216
}));
2317

2418
});

0 commit comments

Comments
 (0)