Missed the directive file.

This commit is contained in:
kiswa 2014-10-25 14:36:14 -04:00
parent 3683795300
commit 1eee8d2ef7

View File

@ -0,0 +1,28 @@
// Source: http://stackoverflow.com/a/25073496/1110183
taskBoardDirectives.directive("keepScrollPos",
['$route', '$window', '$timeout', '$location', '$anchorScroll',
function($route, $window, $timeout, $location, $anchorScroll) {
// Cache scroll position of each route's templateUrl.
var scrollPosCache = {};
// Compile function
return function(scope, element, attrs) {
scope.$on('$routeChangeStart', function() {
if ($route.current) {
scrollPosCache[$route.current.loadedTemplateUrl] = [$window.pageXOffset, $window.pageYOffset];
}
});
scope.$on('$routeChangeSuccess', function() {
// If hash is specified explicitly, it trumps previously stored scroll position.
if ($location.hash()) {
$anchorScroll();
} else {
var prevScrollPos = scrollPosCache[$route.current.loadedTemplateUrl] || [0, 0];
$timeout(function() {
$window.scrollTo(prevScrollPos[0], prevScrollPos[1]);
}, 0);
}
});
}
}]);