mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
A whole lotta shit
This commit is contained in:
116
js/ext/angular/src/directive/ionicNav.js
vendored
116
js/ext/angular/src/directive/ionicNav.js
vendored
@ -1,26 +1,13 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('ionic.ui.nav', ['ionic.service'])
|
||||
angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.gesture', 'ngAnimate'])
|
||||
|
||||
.controller('NavCtrl', ['$scope', '$element', '$compile', 'TemplateLoader', function($scope, $element, $compile, TemplateLoader) {
|
||||
.controller('NavCtrl', ['$scope', '$element', '$animate', '$compile', 'TemplateLoader', function($scope, $element, $animate, $compile, TemplateLoader) {
|
||||
var _this = this;
|
||||
|
||||
angular.extend(this, ionic.controllers.NavController.prototype);
|
||||
|
||||
this.pushFromTemplate = function(tmpl) {
|
||||
data = TemplateLoader.load(tmpl).then(function(data) {
|
||||
console.log('Nav loaded template', data);
|
||||
|
||||
var childScope = $scope.$new();
|
||||
childScope.isVisible = true;
|
||||
|
||||
$compile(data)(childScope, function(cloned, scope) {
|
||||
$element.append(cloned);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ionic.controllers.NavController.call(this, {
|
||||
content: {
|
||||
},
|
||||
@ -41,14 +28,39 @@ angular.module('ionic.ui.nav', ['ionic.service'])
|
||||
}
|
||||
});
|
||||
|
||||
$scope.pushController = function(scope) {
|
||||
this.handleDrag = function(e) {
|
||||
};
|
||||
|
||||
this.endDrag = function(e) {
|
||||
};
|
||||
|
||||
this.pushFromTemplate = function(templateUrl) {
|
||||
var childScope = $scope.$new();
|
||||
childScope.isVisible = true;
|
||||
|
||||
TemplateLoader.load(templateUrl).then(function(templateString) {
|
||||
var el = $compile(templateString)(childScope, function(cloned, scope) {
|
||||
angular.element($element[0].children[1].firstElementChild).append(cloned);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.pushController = function(scope, element) {
|
||||
_this.push(scope);
|
||||
|
||||
/*
|
||||
var old = angular.element($element[0].children[1]);
|
||||
$animate.enter(element, $element, $element[0].firstElementChild, function() {
|
||||
});
|
||||
$animate.leave(old, function() {
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
$scope.navController = this;
|
||||
}])
|
||||
|
||||
.directive('navCtrl', function() {
|
||||
.directive('navs', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
@ -62,7 +74,7 @@ angular.module('ionic.ui.nav', ['ionic.service'])
|
||||
.directive('navBar', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
require: '^navCtrl',
|
||||
require: '^navs',
|
||||
replace: true,
|
||||
scope: true,
|
||||
template: '<header class="bar bar-header bar-dark nav-bar" ng-class="{hidden: !navController.navBar.isVisible}">' +
|
||||
@ -71,6 +83,8 @@ angular.module('ionic.ui.nav', ['ionic.service'])
|
||||
'</header>',
|
||||
link: function(scope, element, attrs, navCtrl) {
|
||||
scope.navController = navCtrl;
|
||||
scope.$watch('navController.controllers.length', function(value) {
|
||||
});
|
||||
scope.goBack = function() {
|
||||
navCtrl.pop();
|
||||
};
|
||||
@ -78,33 +92,61 @@ angular.module('ionic.ui.nav', ['ionic.service'])
|
||||
};
|
||||
})
|
||||
|
||||
.directive('navContent', function() {
|
||||
.directive('navContent', ['Gesture', '$animate', function(Gesture, $animate) {
|
||||
return {
|
||||
restrict: 'ECA',
|
||||
require: '^navCtrl',
|
||||
require: '^navs',
|
||||
scope: true,
|
||||
link: function(scope, element, attrs, navCtrl) {
|
||||
scope.title = attrs.title;
|
||||
transclude: 'element',
|
||||
compile: function(element, attr, transclude) {
|
||||
return function($scope, $element, $attr, navCtrl) {
|
||||
var lastParent, lastIndex, childScope, childElement;
|
||||
|
||||
if(attrs.navBar === "false") {
|
||||
navCtrl.hideNavBar();
|
||||
} else {
|
||||
navCtrl.showNavBar();
|
||||
}
|
||||
$scope.title = $attr.title;
|
||||
|
||||
scope.isVisible = true;
|
||||
scope.pushController(scope);
|
||||
|
||||
scope.$watch('isVisible', function(value) {
|
||||
console.log('Visiblity changed', value);
|
||||
if(value) {
|
||||
element[0].classList.remove('hidden');
|
||||
if($attr.navBar === "false") {
|
||||
navCtrl.hideNavBar();
|
||||
} else {
|
||||
element[0].classList.add('hidden');
|
||||
navCtrl.showNavBar();
|
||||
}
|
||||
});
|
||||
|
||||
$scope.pushController($scope, $element);
|
||||
|
||||
|
||||
$scope.$watch('isVisible', function(value) {
|
||||
if(childElement) {
|
||||
$animate.leave(childElement);
|
||||
childElement = undefined;
|
||||
}
|
||||
if(childScope) {
|
||||
childScope.$destroy();
|
||||
childScope = undefined;
|
||||
}
|
||||
if(value) {
|
||||
childScope = $scope.$new();
|
||||
transclude(childScope, function(clone) {
|
||||
childElement = clone;
|
||||
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), 'slide-left-fade', function() {
|
||||
$animate.removeClass(angular.element(title), 'slide-left-fade', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user