mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 14:19:17 +08:00
Working NavController and Angular extensions!
This commit is contained in:
@ -5,15 +5,17 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
transclude: true,
|
transclude: true,
|
||||||
scope: {
|
scope: true,
|
||||||
hasHeader: '@',
|
template: '<div class="content" ng-class="{\'has-header\': hasHeader, \'has-tabs\': hasTabs}"></div>',
|
||||||
hasTabs: '@'
|
compile: function(element, attr, transclude, navCtrl) {
|
||||||
},
|
return function($scope, $element, $attr) {
|
||||||
template: '<div class="content" ng-class="{\'has-header\': hasHeader, \'has-tabs\': hasTabs}" ng-transclude></div>'
|
$scope.hasHeader = attr.hasHeader;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('NavCtrl', function($scope) {
|
.controller('NavCtrl', function($scope, $element, $compile) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
|
||||||
@ -39,14 +41,18 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
return $scope.controllers[$scope.controllers.length-1];
|
return $scope.controllers[$scope.controllers.length-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.push = this.push;
|
$scope.pushController = function(controller) {
|
||||||
|
//console.log('PUSHING OCNTROLLER', controller);
|
||||||
|
_this.push(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.navController = this;
|
||||||
})
|
})
|
||||||
|
|
||||||
.directive('navController', function() {
|
.directive('navController', function() {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {},
|
|
||||||
transclude: true,
|
transclude: true,
|
||||||
controller: 'NavCtrl',
|
controller: 'NavCtrl',
|
||||||
//templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html',
|
//templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html',
|
||||||
@ -64,23 +70,27 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
require: '^navController',
|
require: '^navController',
|
||||||
transclude: true,
|
transclude: true,
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {
|
template: '<header class="bar bar-header bar-dark nav-bar">' +
|
||||||
},
|
'<a href="#" ng-click="goBack()" class="button" ng-if="controllers.length > 1">Back</a>' +
|
||||||
template: '<header id="nav-bar" class="bar bar-header bar-dark">' +
|
'<h1 class="title">{{getTopController().title}}</h1>' +
|
||||||
'<h1 class="title">{{title}}</h1>' +
|
'</header>',
|
||||||
'</header>'
|
link: function(scope, element, attrs, navCtrl) {
|
||||||
|
scope.goBack = function() {
|
||||||
|
pageNumber--;
|
||||||
|
navCtrl.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
.directive('navContent', function() {
|
.directive('navContent', function() {
|
||||||
return {
|
return {
|
||||||
restrict: 'C',
|
restrict: 'ECA',
|
||||||
require: '^navController',
|
scope: true,
|
||||||
transclude: true,
|
link: function(scope, element, attrs) {
|
||||||
replace: true,
|
scope.title = attrs.title;
|
||||||
template: '<div ng-transclude></div>',
|
scope.isVisible = true;
|
||||||
link: function(scope, element, attrs, navCtrl) {
|
scope.pushController(scope);
|
||||||
navCtrl.push(scope);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,8 +2,6 @@
|
|||||||
NavController = function(opts) {
|
NavController = function(opts) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
console.log('CONSTRUCTOR', this);
|
|
||||||
|
|
||||||
this.navBar = opts.navBar;
|
this.navBar = opts.navBar;
|
||||||
this.content = opts.content;
|
this.content = opts.content;
|
||||||
this.controllers = opts.controllers || [];
|
this.controllers = opts.controllers || [];
|
||||||
@ -24,8 +22,6 @@
|
|||||||
return this.controllers[this.controllers.length-1];
|
return this.controllers[this.controllers.length-1];
|
||||||
},
|
},
|
||||||
push: function(controller) {
|
push: function(controller) {
|
||||||
console.log('PUSHING');
|
|
||||||
|
|
||||||
var last = this.controllers[this.controllers.length - 1];
|
var last = this.controllers[this.controllers.length - 1];
|
||||||
|
|
||||||
this.controllers.push(controller);
|
this.controllers.push(controller);
|
||||||
@ -51,7 +47,8 @@
|
|||||||
|
|
||||||
// TODO: No DOM stuff here
|
// TODO: No DOM stuff here
|
||||||
//this.content.el.appendChild(next.el);
|
//this.content.el.appendChild(next.el);
|
||||||
console.log('Top controller modified', this.topController);
|
next.isVisible = true;
|
||||||
|
next.visibilityChanged && next.visibilityChanged();
|
||||||
|
|
||||||
this._updateNavBar();
|
this._updateNavBar();
|
||||||
|
|
||||||
@ -68,6 +65,10 @@
|
|||||||
|
|
||||||
// Grab the controller behind the top one on the stack
|
// Grab the controller behind the top one on the stack
|
||||||
last = this.controllers.pop();
|
last = this.controllers.pop();
|
||||||
|
if(last) {
|
||||||
|
last.isVisible = false;
|
||||||
|
last.visibilityChanged && last.visibilityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the old one
|
// Remove the old one
|
||||||
//last && last.detach();
|
//last && last.detach();
|
||||||
@ -76,10 +77,10 @@
|
|||||||
|
|
||||||
// TODO: No DOM stuff here
|
// TODO: No DOM stuff here
|
||||||
//this.content.el.appendChild(next.el);
|
//this.content.el.appendChild(next.el);
|
||||||
|
next.isVisible = true;
|
||||||
|
next.visibilityChanged && next.visibilityChanged();
|
||||||
|
|
||||||
// Switch to it (TODO: Animate or such things here)
|
// Switch to it (TODO: Animate or such things here)
|
||||||
this.topController = next;
|
|
||||||
console.log('Top controller modified', this.topController);
|
|
||||||
|
|
||||||
this._updateNavBar();
|
this._updateNavBar();
|
||||||
|
|
||||||
@ -87,11 +88,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateNavBar: function() {
|
_updateNavBar: function() {
|
||||||
if(!this.topController) {
|
if(!this.getTopController()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.navBar.setTitle(this.topController.title);
|
this.navBar.setTitle(this.getTopController().title);
|
||||||
|
|
||||||
if(this.controllers.length > 1) {
|
if(this.controllers.length > 1) {
|
||||||
this.navBar.showBackButton(true);
|
this.navBar.showBackButton(true);
|
||||||
|
|||||||
@ -7,33 +7,50 @@
|
|||||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
|
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||||
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
|
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../dist/ionic.css">
|
<link rel="stylesheet" href="../dist/ionic.css">
|
||||||
<script src="/vendor/angular/1.2.0rc2/angular-1.2.0rc2.min.js"></script>
|
<script src="/vendor/angular/1.2.0rc2/angular.js"></script>
|
||||||
<script src="/vendor/angular/1.2.0rc2/angular-touch.js"></script>
|
<script src="/vendor/angular/1.2.0rc2/angular-touch.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<nav-controller>
|
<nav-controller>
|
||||||
<header id="nav-bar" class="bar bar-header bar-dark">
|
<nav-bar></nav-bar>
|
||||||
<h1 class="title">{{getTopController().title}}</h1>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<content has-header="true">
|
<content has-header="true" ng-controller="AppCtrl">
|
||||||
<div class="nav-content" title="Home" ng-controller="CatsCtrl">
|
|
||||||
<h1>Cats cradle</h2>
|
|
||||||
<a href="#" class="button button-success" ng-click="goNext()">Next</a>
|
|
||||||
</div>
|
|
||||||
</content>
|
</content>
|
||||||
</nav-controller>
|
</nav-controller>
|
||||||
|
|
||||||
<script src="NavController.js"></script>
|
<script src="NavController.js"></script>
|
||||||
<script src="NavAngular.js"></script>
|
<script src="NavAngular.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
var pageNumber = 0;
|
||||||
|
|
||||||
|
var pushIt = function($scope, $compile, $element, cb) {
|
||||||
|
var childScope = $scope.$new();
|
||||||
|
childScope.isVisible = true;
|
||||||
|
|
||||||
|
pageNumber++;
|
||||||
|
|
||||||
|
var el = $compile('<div title="Home: ' + pageNumber + '" ng-controller="CatsCtrl" nav-content has-header="true" ng-show="isVisible">' +
|
||||||
|
'<h1>' + pageNumber + '</h1>' +
|
||||||
|
'<a href="#" class="button button-success" ng-click="goNext()">Next</a>' +
|
||||||
|
'</div>')(childScope, cb);
|
||||||
|
}
|
||||||
|
|
||||||
angular.module('navTest', ['ionic.ui'])
|
angular.module('navTest', ['ionic.ui'])
|
||||||
|
|
||||||
.controller('CatsCtrl', function($scope) {
|
.controller('AppCtrl', function($scope, $compile, $element) {
|
||||||
|
pushIt($scope, $compile, $element, function(cloned, scope) {
|
||||||
|
$element.append(cloned);
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
.controller('CatsCtrl', function($scope, $compile, $element) {
|
||||||
|
console.log('Cats', $element);
|
||||||
$scope.goNext = function() {
|
$scope.goNext = function() {
|
||||||
console.log('Going next', $scope);
|
pushIt($scope, $compile, $element, function(cloned, scope) {
|
||||||
|
$element.parent().append(cloned);
|
||||||
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
18020
vendor/angular/1.2.0rc2/angular.js
vendored
Normal file
18020
vendor/angular/1.2.0rc2/angular.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user