forked from meteoric/meteor-ionic
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ionNavBackButton.js
75 lines (60 loc) · 1.57 KB
/
ionNavBackButton.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
IonScrollPositions = {};
Router.onStop(function () {
IonScrollPositions[this.route.path(this.params)] = $('.overflow-scroll').scrollTop();
});
Template.ionNavBackButton.events({
'click': function (event, template) {
$('[data-nav-container]').attr('nav-view-direction', 'back');
$('[data-navbar-container]').attr('nav-bar-direction', 'back');
//get most up-to-date url, if it exists
backUrl = template.getBackUrl();
if (backUrl) {
Router.go(backUrl);
} else {
window.history.back();
}
}
});
Template.ionNavBackButton.onCreated(function () {
this.data = this.data || {};
});
Template.ionNavBackButton.onRendered(function () {
var self = this;
this.getBackUrl = function () {
var backUrl = null;
self.data = self.data || {};
if (self.data.href) {
backUrl = self.data.href;
}
if (self.data.path) {
backRoute = Router.routes[self.data.path];
if (!backRoute) {
console.warn("back to nonexistent route: ", self.data.path);
return;
}
backUrl = backRoute.path(Template.parentData(1));
}
return backUrl;
};
});
Template.ionNavBackButton.helpers({
classes: function () {
var classes = ['buttons button button-clear back-button pull-left'];
if (this.class) {
classes.push(this.class);
}
return classes.join(' ');
},
icon: function () {
if (this.icon) {
return this.icon;
}
if (Platform.isAndroid()) {
return 'android-arrow-back';
}
return 'ios-arrow-back';
},
text: function () {
return this.text;
}
});