From 565b050003da9fb4f7fa876851def5ea97f2ea74 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Fri, 1 Nov 2013 15:47:04 -0500 Subject: [PATCH] Fixed nav controller scoping and isVisible --- dist/js/ionic-angular.js | 91 +++++++++++------------- js/ext/angular/src/directive/ionicNav.js | 91 +++++++++++------------- 2 files changed, 86 insertions(+), 96 deletions(-) diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 3a798ffed3..4bc247a16c 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -642,6 +642,31 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges }) .directive('navContent', ['Gesture', '$animate', '$compile', function(Gesture, $animate, $compile) { + + var animatePushedController = function(childScope, clone, $element) { + var title = angular.element($element.parent().parent().parent()[0].querySelector('.title')); + var newTitle = angular.element(title.clone()); + + $compile(newTitle)(childScope); + title.after(newTitle); + + clone.addClass(childScope.slideAnimation); + + $animate.addClass(newTitle, childScope.slideTitleAnimation, function() { + $animate.removeClass(newTitle, childScope.slideTitleAnimation, function() { + newTitle.scope().$destroy(); + newTitle.remove(); + }); + }); + + var title = $element.parent().parent().parent()[0].querySelector('.title'); + $animate.enter(clone, $element.parent(), $element); + $animate.addClass(angular.element(title), childScope.slideTitleAnimation, function() { + $animate.removeClass(angular.element(title), childScope.slideTitleAnimation, function() { + }); + }); + }; + return { restrict: 'ECA', require: '^navs', @@ -650,6 +675,20 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges return function($scope, $element, $attr, navCtrl) { var lastParent, lastIndex, childScope, childElement; + + $scope.title = $attr.title; + $scope.slideAnimation = $attr.slideAnimation || ''; + $scope.slideTitleAnimation = $attr.slideTitleAnimation || ''; + + if($attr.navBar === "false") { + navCtrl.hideNavBar(); + } else { + navCtrl.showNavBar(); + } + + // Push this controller onto the stack + $scope.pushController($scope, $element); + $scope.$watch('isVisible', function(value) { // Taken from ngIf if(childElement) { @@ -661,58 +700,14 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges childScope = undefined; } + // Check if this is visible, and if so, create it and show it if(value) { - childScope = $scope; + childScope = $scope.$new(); + transclude(childScope, function(clone) { childElement = clone; - childScope.title = $attr.title; - childScope.slideAnimation = $attr.slideAnimation || ''; - childScope.slideTitleAnimation = $attr.slideTitleAnimation || ''; - - if($attr.navBar === "false") { - navCtrl.hideNavBar(); - } else { - navCtrl.showNavBar(); - } - - childScope.pushController(childScope, $element); - - var title = angular.element($element.parent().parent().parent()[0].querySelector('.title')); - var newTitle = angular.element(title.clone()); - - $compile(newTitle)(childScope); - - title.after(newTitle); - - console.log(newTitle); - - clone.addClass(childScope.slideAnimation); - - $animate.addClass(newTitle, childScope.slideTitleAnimation, function() { - $animate.removeClass(newTitle, childScope.slideTitleAnimation, function() { - newTitle.scope().$destroy(); - newTitle.remove(); - }); - }); - - /* - Gesture.on('drag', function(e) { - //navCtrl.handleDrag(e); - console.log('Content drag', e); - }, childElement[0]); - - Gesture.on('release', function(e) { - //navCtrl._endDrag(e); - }, childElement[0]); - */ - - var title = $element.parent().parent().parent()[0].querySelector('.title'); - $animate.enter(clone, $element.parent(), $element); - $animate.addClass(angular.element(title), childScope.slideTitleAnimation, function() { - $animate.removeClass(angular.element(title), childScope.slideTitleAnimation, function() { - }); - }); + animatePushedController(childScope, clone, $element); }); } }); diff --git a/js/ext/angular/src/directive/ionicNav.js b/js/ext/angular/src/directive/ionicNav.js index 8b13cc26a4..5f231c996c 100644 --- a/js/ext/angular/src/directive/ionicNav.js +++ b/js/ext/angular/src/directive/ionicNav.js @@ -97,6 +97,31 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges }) .directive('navContent', ['Gesture', '$animate', '$compile', function(Gesture, $animate, $compile) { + + var animatePushedController = function(childScope, clone, $element) { + var title = angular.element($element.parent().parent().parent()[0].querySelector('.title')); + var newTitle = angular.element(title.clone()); + + $compile(newTitle)(childScope); + title.after(newTitle); + + clone.addClass(childScope.slideAnimation); + + $animate.addClass(newTitle, childScope.slideTitleAnimation, function() { + $animate.removeClass(newTitle, childScope.slideTitleAnimation, function() { + newTitle.scope().$destroy(); + newTitle.remove(); + }); + }); + + var title = $element.parent().parent().parent()[0].querySelector('.title'); + $animate.enter(clone, $element.parent(), $element); + $animate.addClass(angular.element(title), childScope.slideTitleAnimation, function() { + $animate.removeClass(angular.element(title), childScope.slideTitleAnimation, function() { + }); + }); + }; + return { restrict: 'ECA', require: '^navs', @@ -105,6 +130,20 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges return function($scope, $element, $attr, navCtrl) { var lastParent, lastIndex, childScope, childElement; + + $scope.title = $attr.title; + $scope.slideAnimation = $attr.slideAnimation || ''; + $scope.slideTitleAnimation = $attr.slideTitleAnimation || ''; + + if($attr.navBar === "false") { + navCtrl.hideNavBar(); + } else { + navCtrl.showNavBar(); + } + + // Push this controller onto the stack + $scope.pushController($scope, $element); + $scope.$watch('isVisible', function(value) { // Taken from ngIf if(childElement) { @@ -116,58 +155,14 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges childScope = undefined; } + // Check if this is visible, and if so, create it and show it if(value) { - childScope = $scope; + childScope = $scope.$new(); + transclude(childScope, function(clone) { childElement = clone; - childScope.title = $attr.title; - childScope.slideAnimation = $attr.slideAnimation || ''; - childScope.slideTitleAnimation = $attr.slideTitleAnimation || ''; - - if($attr.navBar === "false") { - navCtrl.hideNavBar(); - } else { - navCtrl.showNavBar(); - } - - childScope.pushController(childScope, $element); - - var title = angular.element($element.parent().parent().parent()[0].querySelector('.title')); - var newTitle = angular.element(title.clone()); - - $compile(newTitle)(childScope); - - title.after(newTitle); - - console.log(newTitle); - - clone.addClass(childScope.slideAnimation); - - $animate.addClass(newTitle, childScope.slideTitleAnimation, function() { - $animate.removeClass(newTitle, childScope.slideTitleAnimation, function() { - newTitle.scope().$destroy(); - newTitle.remove(); - }); - }); - - /* - Gesture.on('drag', function(e) { - //navCtrl.handleDrag(e); - console.log('Content drag', e); - }, childElement[0]); - - Gesture.on('release', function(e) { - //navCtrl._endDrag(e); - }, childElement[0]); - */ - - var title = $element.parent().parent().parent()[0].querySelector('.title'); - $animate.enter(clone, $element.parent(), $element); - $animate.addClass(angular.element(title), childScope.slideTitleAnimation, function() { - $animate.removeClass(angular.element(title), childScope.slideTitleAnimation, function() { - }); - }); + animatePushedController(childScope, clone, $element); }); } });