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:
Andy Joslin
2014-02-17 09:09:56 -05:00
parent 3901b746bc
commit e1b6fd4f84
2 changed files with 2 additions and 10 deletions

View File

@@ -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);
};

View File

@@ -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);
}));
});