mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
Working angular tabs!
This commit is contained in:
@ -18,12 +18,16 @@ angular.module('ionic.ui', [])
|
|||||||
|
|
||||||
angular.extend(this, TabBarController.prototype);
|
angular.extend(this, TabBarController.prototype);
|
||||||
|
|
||||||
// TODO: This dom thing is a temporary hack
|
|
||||||
var tab = document.createElement('div');
|
|
||||||
tab.className = 'tabs';
|
|
||||||
|
|
||||||
TabBarController.call(this, {
|
TabBarController.call(this, {
|
||||||
tabBar: new TabBar({el: tab})
|
tabBar: {
|
||||||
|
tryTabSelect: function() {},
|
||||||
|
setSelectedItem: function(index) {
|
||||||
|
console.log('TAB BAR SET SELECTED INDEX', index);
|
||||||
|
},
|
||||||
|
addItem: function(item) {
|
||||||
|
console.log('TAB BAR ADD ITEM', item);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.controllers = this.controllers;
|
$scope.controllers = this.controllers;
|
||||||
@ -51,7 +55,7 @@ angular.module('ionic.ui', [])
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
transclude: true,
|
transclude: true,
|
||||||
template: '<div ng-transclude></div>',
|
template: '<div ng-show="isVisible" ng-transclude></div>',
|
||||||
require: '^tabs',
|
require: '^tabs',
|
||||||
scope: {
|
scope: {
|
||||||
title: '@'
|
title: '@'
|
||||||
@ -70,9 +74,7 @@ angular.module('ionic.ui', [])
|
|||||||
transclude: true,
|
transclude: true,
|
||||||
replace: true,
|
replace: true,
|
||||||
template: '<div class="tabs">' +
|
template: '<div class="tabs">' +
|
||||||
'<a href="#" class="tab-item" ng-repeat="controller in controllers">' +
|
'<tab-item title="{{controller.title}}" icon="{{controller.icon}}" active="controller.isVisible" index="$index" ng-repeat="controller in controllers"></tab-item>' +
|
||||||
'<i class="{{item.icon}}"></i> {{controller.title}}' +
|
|
||||||
'</a>' +
|
|
||||||
'</div>'
|
'</div>'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -81,41 +83,28 @@ angular.module('ionic.ui', [])
|
|||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
require: '^tabBar',
|
require: '^tabs',
|
||||||
scope: {
|
scope: {
|
||||||
text: '@',
|
title: '@',
|
||||||
icon: '@',
|
icon: '@',
|
||||||
active: '=',
|
active: '=',
|
||||||
tabSelected: '@',
|
tabSelected: '@',
|
||||||
|
index: '='
|
||||||
},
|
},
|
||||||
compile: function(element, attrs, transclude) {
|
link: function(scope, element, attrs, tabsCtrl) {
|
||||||
return function(scope, element, attrs, tabBarCtrl) {
|
|
||||||
var getActive, setActive;
|
|
||||||
|
|
||||||
scope.$watch('active', function(active) {
|
|
||||||
console.log('ACTIVE CHANGED', active);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
},
|
|
||||||
link: function(scope, element, attrs, tabBarCtrl) {
|
|
||||||
|
|
||||||
// Store the index of this list item, which
|
// Store the index of this list item, which
|
||||||
// specifies which tab item it is
|
// specifies which tab item it is
|
||||||
scope.tabIndex = element.index();
|
//scope.tabIndex = element.index();
|
||||||
|
|
||||||
scope.active = true;
|
|
||||||
|
|
||||||
scope.selectTab = function(index) {
|
scope.selectTab = function(index) {
|
||||||
console.log('SELECT TAB', index);
|
console.log('SELECT TAB', scope.index);
|
||||||
tabBarCtrl.selectTabAtIndex(index);
|
tabsCtrl.selectController(scope.index);
|
||||||
};
|
};
|
||||||
|
|
||||||
tabBarCtrl.addTab(scope);
|
|
||||||
},
|
},
|
||||||
template: '<li class="tab-item" ng-class="{active:active}">' +
|
template:
|
||||||
'<a href="#" ng-click="selectTab(tabIndex)">' +
|
'<a href="#" ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' +
|
||||||
'<i class="{{icon}}"></i>' +
|
'<i class="{{icon}}"></i> {{title}}' +
|
||||||
'{{text}}' +
|
'</a>'
|
||||||
'</a></li>'
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -94,13 +94,11 @@ TabBarController.prototype = {
|
|||||||
addController: function(controller) {
|
addController: function(controller) {
|
||||||
this.controllers.push(controller);
|
this.controllers.push(controller);
|
||||||
|
|
||||||
var item = TabBarItem.prototype.create({
|
this.tabBar.addItem({
|
||||||
title: controller.title,
|
title: controller.title,
|
||||||
icon: controller.icon
|
icon: controller.icon
|
||||||
});
|
});
|
||||||
|
|
||||||
this.tabBar.addItem(item);
|
|
||||||
|
|
||||||
// If we don't have a selected controller yet, select the first one.
|
// If we don't have a selected controller yet, select the first one.
|
||||||
if(!this.selectedController) {
|
if(!this.selectedController) {
|
||||||
this.setSelectedController(0);
|
this.setSelectedController(0);
|
||||||
|
|||||||
2
hacking/ViewController.js
Normal file
2
hacking/ViewController.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(function(window, document, ionic) {
|
||||||
|
})(this, document, ionic = this.ionic || {});
|
||||||
@ -7,7 +7,8 @@
|
|||||||
<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/angular.js"></script>
|
<script src="/vendor/angular/1.2.0rc2/angular-1.2.0rc2.min.js"></script>
|
||||||
|
<script src="/vendor/angular/1.2.0rc2/angular-touch.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.content {
|
.content {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -42,9 +43,6 @@
|
|||||||
</tab-controller>
|
</tab-controller>
|
||||||
</tabs>
|
</tabs>
|
||||||
|
|
||||||
<script src="../../js/ionic-events.js"></script>
|
|
||||||
<script src="../../js/ionic-gestures.js"></script>
|
|
||||||
<script src="TabBar.js"></script>
|
|
||||||
<script src="TabBarController.js"></script>
|
<script src="TabBarController.js"></script>
|
||||||
<script src="TabAngular.js"></script>
|
<script src="TabAngular.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Reference in New Issue
Block a user