Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ angular.module('ajoslin.mobile-navigate')
.directive('mobileView', ['$rootScope', '$compile', '$controller', '$route', '$change', '$q',
function($rootScope, $compile, $controller, $route, $change, $q) {

var pageStack = [];

function link(scope, viewElement, attrs) {
//Insert page into dom
function insertPage(page) {
Expand Down Expand Up @@ -34,7 +36,11 @@ function($rootScope, $compile, $controller, $route, $change, $q) {
var current = $route.current && $route.current.$$route || {};
var transition = reverse ? source.transition() : dest.transition();

insertPage(dest);
if (reverse) { //pop
} else { //push
pageStack.push(dest);
insertPage(dest);
}

//If the page is marked as reverse, reverse the direction
if (dest.reverse() || current.reverse) {
Expand All @@ -49,8 +55,11 @@ function($rootScope, $compile, $controller, $route, $change, $q) {
promise.then(function() {
if (source) {
$rootScope.$broadcast('$pageTransitionSuccess', dest, source);
source.scope.$destroy();
source.element.remove();
if (reverse) {
var src = pageStack.pop();
src.scope.$destroy();
src.element.remove();
}
source = undefined;
}
});
Expand Down