Merge pull request #38 from alex3305/keep-scroll-fix

Keep scroll fix
This commit is contained in:
Matt 2014-10-22 09:49:24 -04:00
commit 4dd3257e1f
5 changed files with 37 additions and 4 deletions

View File

@ -58,5 +58,6 @@
<script src="js/directives/clickToEdit.js"></script>
<script src="js/directives/onLoadCallback.js"></script>
<script src="js/directives/fileUpload.js"></script>
<script src="js/directives/keepScrollPos.js"></script>
</body>
</html>

View File

@ -83,7 +83,7 @@ function ($scope, $routeParams, $location, $interval, $window,
if ($scope.boardId) {
$interval.cancel($scope.interval);
}
if ($scope.boardsLoaded && !$scope.boardId && parseInt($scope.currentUser.defaultBoard)) {
if ($scope.boardsLoaded && !$scope.boardId && $scope.currentUser && parseInt($scope.currentUser.defaultBoard)) {
$interval.cancel($scope.interval);
$location.path('boards/' + $scope.currentUser.defaultBoard);
}

View File

@ -33,7 +33,9 @@ function ($scope, $window, $location, UserService, AuthenticationService, AlertS
$scope.display.smallText = ' - File Viewer';
}
$.noty.closeAll(); // Clear any alerts on page load.
try {
$.noty.closeAll(); // Clear any alerts on page load.
} catch(e) {}
$scope.logout = function() {
UserService.logOut()

View File

@ -0,0 +1,30 @@
// Source: http://stackoverflow.com/a/25073496/1110183
taskBoardDirectives.directive("keepScrollPos", 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() {
// store scroll position for the current view
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 get previous scroll position; if none, scroll to the top of the page
} else {
var prevScrollPos = scrollPosCache[$route.current.loadedTemplateUrl] || [ 0, 0 ];
$timeout(function() {
$window.scrollTo(prevScrollPos[0], prevScrollPos[1]);
}, 0);
}
});
}
});

View File

@ -37,7 +37,7 @@
</div>
<div class="boardColumn" data-ng-repeat="lane in currentBoard.ownLane | orderBy:'position':false"
data-ng-class="{'collapsed': lane.collapsed}" data-lane-id="{{ lane.id }}"
data-context-menu="onContextMenu(lane.id)" data-target="laneMenu">
data-context-menu="onContextMenu(lane.id)" data-target="laneMenu" data-keep-scroll-pos>
<h3>{{ lane.name }}
<span class="badge" title="Column Items" data-ng-if="lane.collapsed">
{{ lane.ownItem.length || 0 }}
@ -59,7 +59,7 @@
<h4>{{ item.title }}</h4>
<span class="badge" title="Points">{{ item.points }}</span>
</div>
<div class="description" data-ng-bind-html="marked(item.description)"></div>
<div class="description" data-ng-bind-html="marked(item.description)" data-keep-scroll-pos></div>
<p class="assignee">
<span data-ng-if="userNames[item.assignee]">Assigned To: </span>
{{ userNames[item.assignee] }}