@@ -18,100 +18,108 @@ angular.module('ionic.ui.header', ['ngAnimate', 'ngSanitize'])
18
18
* @name ionHeaderBar
19
19
* @module ionic
20
20
* @restrict E
21
- * @group page layout
22
- * @controller ionicBar
23
- *
24
21
* @description
25
- * Adds a fixed header bar above some content.
22
+ * While Ionic provides simple Header and Footer bars that can be created through
23
+ * HTML and CSS alone, Header bars specifically can be extended in order to
24
+ * provide dynamic layout features such as auto-title centering and animation.
25
+ * They are also used by the Views and Navigation Controller to animate a title
26
+ * on navigation and toggle a back button.
27
+ *
28
+ * The main header bar feature provided is auto title centering.
29
+ * In this situation, the title text will center itself until either the
30
+ * left or right button content is too wide for the label to center.
31
+ * In that case, it will slide left or right until it can fit.
32
+ * You can also align the title left for a more Android-friendly header.
26
33
*
27
- * Is able to have left or right buttons, and additionally its title can be
28
- * aligned through the { @link ionic.controller:ionicBar ionicBar controller} .
34
+ * Using two-way data binding, the header bar will automatically
35
+ * readjust the heading title alignment when the title or buttons change .
29
36
*
30
- * @param {string= } model The model to assign this headerBar's
31
- * { @link ionic.controller:ionicBar ionicBar controller} to.
32
- * Defaults to assigning to $scope.headerBarController .
33
- * @param {string= } align-title Where to align the title at the start .
34
- * Avaialble: 'left', 'right', or 'center'. Defaults to 'center'.
37
+ * @param {string } title The title use on the headerBar.
38
+ * @param { expression= } leftButtons Point to an array of buttons to put on the left of the bar .
39
+ * @param { expression= } rightButtons Point to an array of buttons to put on the right of the bar .
40
+ * @param {string= } type The type of the bar, for example 'bar-positive' .
41
+ * @param { string= } align Where to align the title. 'left', 'right', or 'center'. Defaults to 'center'.
35
42
*
36
43
* @usage
37
44
* ```html
38
- * <ion-header-bar align-title="left">
39
- * <div class="buttons">
40
- * <button class="button">Left Button</button>
41
- * </div>
42
- * <h1 class="title">Title!</h1>
43
- * <div class="buttons">
44
- * <button class="button">Right Button</button>
45
- * </div>
45
+ * <ion-header-bar
46
+ * title="{{myTitle}}"
47
+ * left-buttons="leftButtons"
48
+ * right-buttons="rightButtons"
49
+ * type="bar-positive"
50
+ * align-title="center">
46
51
* </ion-header-bar>
47
- * <ion-content>
48
- * Some content!
49
- * </ion-content>
50
52
* ```
51
- */
52
- . directive ( 'ionHeaderBar' , barDirective ( true ) )
53
-
54
- /**
55
- * @ngdoc directive
56
- * @name ionFooterBar
57
- * @module ionic
58
- * @restrict E
59
- * @group page layout
60
- * @controller ionicBar
61
53
*
62
- * @description
63
- * Adds a fixed footer bar below some content.
64
- *
65
- * Is able to have left or right buttons, and additionally its title can be
66
- * aligned through the {@link ionic.controller:ionicBar ionicBar controller}.
67
- *
68
- * @param {string= } model The model to assign this footerBar's
69
- * {@link ionic.controller:ionicBar ionicBar controller} to.
70
- * Defaults to assigning to $scope.footerBarController.
71
- * @param {string= } align-title Where to align the title at the start.
72
- * Avaialble: 'left', 'right', or 'center'. Defaults to 'center'.
73
- *
74
- * @usage
75
- * ```html
76
- * <ion-content>
77
- * Some content!
78
- * </ion-content>
79
- * <ion-footer-bar align-title="left">
80
- * <div class="buttons">
81
- * <button class="button">Left Button</button>
82
- * </div>
83
- * <h1 class="title">Title!</h1>
84
- * <div class="buttons">
85
- * <button class="button">Right Button</button>
86
- * </div>
87
- * </ion-footer-bar>
88
- * ```
89
54
*/
90
- . directive ( 'ionFooterBar' , barDirective ( false ) ) ;
55
+ . directive ( 'ionHeaderBar' , [ '$ionicScrollDelegate' , function ( $ionicScrollDelegate ) {
56
+ return {
57
+ restrict : 'E' ,
58
+ replace : true ,
59
+ transclude : true ,
60
+ template : '<header class="bar bar-header">\
61
+ <div class="buttons">\
62
+ <button ng-repeat="button in leftButtons" class="button no-animation" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
63
+ </button>\
64
+ </div>\
65
+ <h1 class="title" ng-bind-html="title"></h1>\
66
+ <div class="buttons">\
67
+ <button ng-repeat="button in rightButtons" class="button no-animation" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
68
+ </button>\
69
+ </div>\
70
+ </header>' ,
91
71
92
- function barDirective ( isHeader ) {
93
- var BAR_TEMPLATE = isHeader ?
94
- '<header class="bar bar-header" ng-transclude></header>' :
95
- '<footer class="bar bar-header" ng-transclude></footer>' ;
96
- var BAR_MODEL_DEFAULT = isHeader ?
97
- 'headerBarController' :
98
- 'footerBarController' ;
99
- return [ '$parse' , function ( $parse ) {
100
- return {
101
- restrict : 'E' ,
102
- replace : true ,
103
- transclude : true ,
104
- template : BAR_TEMPLATE ,
105
- link : function ( $scope , $element , $attr ) {
106
- var hb = new ionic . views . HeaderBar ( {
107
- el : $element [ 0 ] ,
108
- alignTitle : $attr . alignTitle || 'center'
109
- } ) ;
72
+ scope : {
73
+ leftButtons : '=' ,
74
+ rightButtons : '=' ,
75
+ title : '@' ,
76
+ type : '@' ,
77
+ alignTitle : '@'
78
+ } ,
79
+ link : function ( $scope , $element , $attr ) {
80
+ var hb = new ionic . views . HeaderBar ( {
81
+ el : $element [ 0 ] ,
82
+ alignTitle : $scope . alignTitle || 'center'
83
+ } ) ;
84
+
85
+ $element . addClass ( $scope . type ) ;
86
+
87
+ $scope . headerBarView = hb ;
88
+
89
+ $scope . $watchCollection ( 'leftButtons' , function ( val ) {
90
+ // Resize the title since the buttons have changed
91
+ hb . align ( ) ;
92
+ } ) ;
110
93
111
- $parse ( $attr . model || BAR_MODEL_DEFAULT ) . assign ( $scope . $parent , hb ) ;
112
- }
113
- } ;
114
- } ] ;
115
- }
94
+ $scope . $watchCollection ( 'rightButtons' , function ( val ) {
95
+ // Resize the title since the buttons have changed
96
+ hb . align ( ) ;
97
+ } ) ;
98
+
99
+ $scope . $watch ( 'title' , function ( val ) {
100
+ // Resize the title since the title has changed
101
+ hb . align ( ) ;
102
+ } ) ;
103
+ }
104
+ } ;
105
+ } ] )
106
+
107
+ . directive ( 'ionFooterBar' , function ( ) {
108
+ return {
109
+ restrict : 'E' ,
110
+ replace : true ,
111
+ transclude : true ,
112
+ template : '<footer class="bar bar-footer" ng-transclude>\
113
+ </footer>' ,
114
+
115
+ scope : {
116
+ type : '@' ,
117
+ } ,
118
+
119
+ link : function ( $scope , $element , $attr ) {
120
+ $element . addClass ( $scope . type ) ;
121
+ }
122
+ } ;
123
+ } ) ;
116
124
117
125
} ) ( ionic ) ;
0 commit comments