Fixed nav controller scoping and isVisible

This commit is contained in:
Max Lynch
2013-11-01 15:47:04 -05:00
parent ced8ac3dc1
commit 565b050003
2 changed files with 86 additions and 96 deletions

View File

@ -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);
});
}
});

View File

@ -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);
});
}
});