This commit is contained in:
Max Lynch
2013-11-12 16:34:48 -06:00
parent 8b8ef12273
commit 7d4756eaef
12 changed files with 423 additions and 56 deletions

View File

@ -0,0 +1,34 @@
(function(ionic) {
'use strict';
angular.module('ionic.ui.header', ['ngAnimate'])
.directive('headerBar', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
template: '<header class="bar bar-header" ng-transclude></header>',
scope: {
type: '@',
alignTitle: '@',
},
link: function($scope, $element, $attr) {
var hb = new ionic.views.HeaderBar({
el: $element[0],
alignTitle: $scope.alignTitle || 'center'
});
$element.addClass($scope.type);
$scope.headerBarView = hb;
$scope.$on('$destroy', function() {
//
});
}
};
});
})(ionic);

View File

@ -32,6 +32,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
// Pop function, throttled
this.popController = ionic.throttle(function() {
_this.pop();
$scope.$broadcast('navs.pop');
}, 300, {
trailing: false
});
@ -79,6 +80,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
*/
$scope.pushController = function(scope, element) {
_this.push(scope);
$scope.$broadcast('navs.push', scope);
};
$scope.navController = this;
@ -105,22 +107,46 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
restrict: 'E',
require: '^navs',
replace: true,
scope: true,
scope: {
type: '@',
backButtonType: '@',
alignTitle: '@'
},
template: '<header class="bar bar-header nav-bar" ng-class="{hidden: !navController.navBar.isVisible}">' +
'<a href="#" ng-click="goBack()" class="button" ng-if="navController.controllers.length > 1">Back</a>' +
'<button ng-click="goBack()" class="button" ng-if="navController.controllers.length > 1" ng-class="backButtonType">Back</button>' +
'<h1 class="title">{{navController.getTopController().title}}</h1>' +
'</header>',
link: function(scope, element, attrs, navCtrl) {
scope.navController = navCtrl;
link: function($scope, $element, $attr, navCtrl) {
var backButton;
scope.barType = attrs.barType || 'bar-dark';
element.addClass(scope.barType);
$scope.navController = navCtrl;
scope.$watch('navController.controllers.length', function(value) {
});
scope.goBack = function() {
$scope.goBack = function() {
navCtrl.popController();
};
var hb = new ionic.views.HeaderBar({
el: $element[0],
alignTitle: $scope.alignTitle || 'center'
});
$element.addClass($scope.type);
$scope.headerBarView = hb;
$scope.$parent.$on('navs.push', function() {
backButton = angular.element($element[0].querySelector('.button'));
backButton.addClass($scope.backButtonType);
hb.align();
});
$scope.$parent.$on('navs.pop', function() {
hb.align();
});
$scope.$on('$destroy', function() {
//
});
}
};
})

View File

@ -16,6 +16,7 @@ angular.module('ionic.ui', [
'ionic.ui.content',
'ionic.ui.tabs',
'ionic.ui.nav',
'ionic.ui.header',
'ionic.ui.sideMenu',
'ionic.ui.list',
'ionic.ui.checkbox',

View File

@ -0,0 +1,40 @@
<html ng-app="headerTest">
<head>
<meta charset="utf-8">
<title>Header</title>
<!-- Sets initial viewport load and disables zooming -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-animate.js"></script>
</head>
<body>
<header-bar type="bar-primary" align-title="left">
<button class="button">Tap</button>
<h1 class="title">A really really long title here here here here her</h1>
</header-bar>
<script src="../../../../dist/js/ionic.js"></script>
<script src="../../../../dist/js/ionic-angular.js"></script>
<script>
angular.module('headerTest', ['ionic']);
var midPoint = window.clientWidth / 2;
var box = document.createElement('div');
box.style.backgroundColor = 'red';
box.style.opacity = '0.6';
box.style.width = '2px';
box.style.height = '44px';
box.style.left = '50%';
box.style.position = 'fixed';
box.style.zIndex = 100;
box.style.top = '0px';
box.style.marginLeft = '-1px';
document.body.appendChild(box);
window.onresize = function() {
var s = angular.element(document.getElementsByTagName('header')[0]).isolateScope();
s.headerBarView.align();
};
</script>
</body>
</html>

View File

@ -32,16 +32,17 @@
<body>
<navs>
<nav-bar></nav-bar>
<nav-bar type="bar-primary" back-button-type="button-pure" align-title="right">
</nav-bar>
<div ng-controller="AppCtrl">
<content has-header="true">
</content>
</div>
<div ng-controller="AppCtrl">
<content has-header="true">
</content>
</div>
</navs>
<script id="page.html" type="text/ng-template">
<div title="Home" ng-controller="CatsCtrl" class="nav-content">
<div title="Home home home home home home home home home" ng-controller="CatsCtrl" class="nav-content">
<h1></h1>
<a href="#" class="button button-success" ng-click="goNext()">Next</a>
<list><list-item ng-repeat="item in items" on-select="goNext()">Test</list-item></list>