Skip to content

Commit

Permalink
fix(scrollView): cancel scrollTop every time hash is set
Browse files Browse the repository at this point in the history
Before it, only cancelled scrollTop the first time the hash was set.

Addresses #618
  • Loading branch information
ajoslin committed Feb 17, 2014
1 parent 3901b74 commit e1b6fd4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 1 addition & 3 deletions js/ext/angular/src/service/decorators/location.js
Expand Up @@ -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);
};
Expand Down
8 changes: 1 addition & 7 deletions js/ext/angular/test/service/decorators/location.unit.js
@@ -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) {
Expand All @@ -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);
}));

});
Expand Down

0 comments on commit e1b6fd4

Please sign in to comment.