forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavBarController.js
More file actions
131 lines (109 loc) · 3.43 KB
/
navBarController.js
File metadata and controls
131 lines (109 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
IonicModule
.controller('$ionicNavBar', [
'$scope',
'$element',
'$attrs',
'$ionicViewService',
'$animate',
'$compile',
'$ionicNavBarDelegate',
function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionicNavBarDelegate) {
//Let the parent know about our controller too so that children of
//sibling content elements can know about us
$element.parent().data('$ionNavBarController', this);
var deregisterInstance = $ionicNavBarDelegate._registerInstance(this, $attrs.delegateHandle);
$scope.$on('$destroy', deregisterInstance);
var self = this;
this.leftButtonsElement = jqLite(
$element[0].querySelector('.buttons.left-buttons')
);
this.rightButtonsElement = jqLite(
$element[0].querySelector('.buttons.right-buttons')
);
this.back = function() {
var backView = $ionicViewService.getBackView();
backView && backView.go();
return false;
};
this.align = function(direction) {
this._headerBarView.align(direction);
};
this.showBackButton = function(show) {
if (arguments.length) {
$scope.backButtonShown = !!show;
}
return !!($scope.hasBackButton && $scope.backButtonShown);
};
this.showBar = function(show) {
if (arguments.length) {
$scope.isInvisible = !show;
$scope.$parent.$hasHeader = !!show;
}
return !$scope.isInvisible;
};
this.setTitle = function(title) {
if ($scope.title === title) {
return;
}
$scope.oldTitle = $scope.title;
$scope.title = title || '';
};
this.changeTitle = function(title, direction) {
if ($scope.title === title) {
return false;
}
this.setTitle(title);
$scope.isReverse = direction == 'back';
$scope.shouldAnimate = !!direction;
if (!$scope.shouldAnimate) {
//We're done!
this._headerBarView.align();
} else {
this._animateTitles();
}
return true;
};
this.getTitle = function() {
return $scope.title || '';
};
this.getPreviousTitle = function() {
return $scope.oldTitle || '';
};
/**
* Exposed for testing
*/
this._animateTitles = function() {
var oldTitleEl, newTitleEl, currentTitles;
//If we have any title right now
//(or more than one, they could be transitioning on switch),
//replace the first one with an oldTitle element
currentTitles = $element[0].querySelectorAll('.title');
if (currentTitles.length) {
oldTitleEl = $compile('<h1 class="title" ng-bind-html="oldTitle"></h1>')($scope);
jqLite(currentTitles[0]).replaceWith(oldTitleEl);
}
//Compile new title
newTitleEl = $compile('<h1 class="title invisible" ng-bind-html="title"></h1>')($scope);
//Animate in on next frame
ionic.requestAnimationFrame(function() {
oldTitleEl && $animate.leave(jqLite(oldTitleEl));
var insert = oldTitleEl && jqLite(oldTitleEl) || null;
$animate.enter(newTitleEl, $element, insert, function() {
self._headerBarView.align();
});
//Cleanup any old titles leftover (besides the one we already did replaceWith on)
forEach(currentTitles, function(el) {
if (el && el.parentNode) {
//Use .remove() to cleanup things like .data()
jqLite(el).remove();
}
});
//$apply so bindings fire
$scope.$digest();
//Stop flicker of new title on ios7
ionic.requestAnimationFrame(function() {
newTitleEl[0].classList.remove('invisible');
});
});
};
}]);