Skip to content

Commit

Permalink
don't throw exceptions if the view is destroyed before the view is re…
Browse files Browse the repository at this point in the history
…sized

`resize()` is a promise, and the `$destroy` event can fire before it finishes, nulling out `scrollView` which subsequently throws an exception because we are trying to call methods on `null`.
  • Loading branch information
ptarjan committed Sep 15, 2015
1 parent 2c706c7 commit e6fa075
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,64 @@ function($scope,

self.scrollTop = function(shouldAnimate) {
self.resize().then(function() {
if (!scrollView) {
return;
}
scrollView.scrollTo(0, 0, !!shouldAnimate);
});
};

self.scrollBottom = function(shouldAnimate) {
self.resize().then(function() {
if (!scrollView) {
return;
}
var max = scrollView.getScrollMax();
scrollView.scrollTo(max.left, max.top, !!shouldAnimate);
});
};

self.scrollTo = function(left, top, shouldAnimate) {
self.resize().then(function() {
if (!scrollView) {
return;
}
scrollView.scrollTo(left, top, !!shouldAnimate);
});
};

self.zoomTo = function(zoom, shouldAnimate, originLeft, originTop) {
self.resize().then(function() {
if (!scrollView) {
return;
}
scrollView.zoomTo(zoom, !!shouldAnimate, originLeft, originTop);
});
};

self.zoomBy = function(zoom, shouldAnimate, originLeft, originTop) {
self.resize().then(function() {
if (!scrollView) {
return;
}
scrollView.zoomBy(zoom, !!shouldAnimate, originLeft, originTop);
});
};

self.scrollBy = function(left, top, shouldAnimate) {
self.resize().then(function() {
if (!scrollView) {
return;
}
scrollView.scrollBy(left, top, !!shouldAnimate);
});
};

self.anchorScroll = function(shouldAnimate) {
self.resize().then(function() {
if (!scrollView) {
return;
}
var hash = $location.hash();
var elm = hash && $document[0].getElementById(hash);
if (!(hash && elm)) {
Expand Down

0 comments on commit e6fa075

Please sign in to comment.