-
Notifications
You must be signed in to change notification settings - Fork 219
/
ionHeaderBar.js
78 lines (67 loc) · 1.91 KB
/
ionHeaderBar.js
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
IonHeaderBar = {
alignTitle: function () {
var align = this.data.alignTitle || 'center';
var $title = this.$('.title');
if (Platform.isAndroid() && !this.alignTitle) {
$title.addClass('title-left');
return;
}
if (align === 'center') {
$title.addClass('title-center');
} else if (align === 'left') {
$title.addClass('title-left');
} else if (align === 'right') {
$title.addClass('title-right');
}
},
positionTitle: function () {
var $title = this.$('.title');
var $leftButton = $('.button.pull-left');
var $rightButton = $('.button.pull-right');
// Find out which button is wider,
// use that to offset the title on both sides
var leftButtonWidth = 0;
var rightButtonWidth = 0;
if ($leftButton.length) {
$leftButton.each(function(index, element){
leftButtonWidth += $(element).outerWidth();
});
}
if ($rightButton.length) {
$rightButton.each(function(index, element){
rightButtonWidth += $(element).outerWidth();
});
}
// If we're on Android, we only care about the left button
var margin;
if (Platform.isAndroid()) {
margin = leftButtonWidth;
} else {
margin = Math.max(leftButtonWidth, rightButtonWidth);
}
$title.css('left', margin);
$title.css('right', margin);
}
};
Template.ionHeaderBar.created = function () {
this.data = this.data || {};
};
Template.ionHeaderBar.rendered = function () {
Session.set('hasHeader', true);
IonHeaderBar.alignTitle.call(this);
IonHeaderBar.positionTitle.call(this);
};
Template.ionHeaderBar.destroyed = function () {
Session.set('hasHeader', false);
};
Template.ionHeaderBar.helpers({
classes: function () {
var classes = ['bar', 'bar-header'];
if (this.class) {
classes.push(this.class);
} else {
classes.push('bar-stable');
}
return classes.join(' ');
}
});