forked from JamesLefrere/velociratchet-meteor-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzendy-velociratchet.js
executable file
·144 lines (134 loc) · 4.63 KB
/
zendy-velociratchet.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Namespace for package
Velociratchet = {};
Velociratchet.history = [];
Velociratchet.addToHistory = function( routeName ){
Velociratchet.history.push( routeName );
}
Velociratchet.removeFromHistory = function(){
Velociratchet.history.pop();
}
Velociratchet.clearHistory = function() {
Velociratchet.history = [];
}
// Events for layout template
// Add the following to your Meteor app:
// Template.myLayoutTemplateName.events(Velociratchet.events);
Velociratchet.events = {
'click': function ( evt ) {
Velociratchet.transition = 'vratchet-fade';
},
'click .icon-right-nav': function () {
Velociratchet.addToHistory(Iron.Location.get().path);
Velociratchet.transition = 'vratchet-right-to-left';
},
'click .navigate-right': function () {
Velociratchet.addToHistory(Iron.Location.get().path);
Velociratchet.transition = 'vratchet-right-to-left';
},
'click .icon-left-nav': function () {
Velociratchet.removeFromHistory();
Velociratchet.transition = 'vratchet-left-to-right';
},
'click .navigate-left': function () {
Velociratchet.removeFromHistory();
Velociratchet.transition = 'vratchet-left-to-right';
},
'click .toggle': function( event ){
var toggle = $(event.target);
if( toggle.hasClass( 'active' ) ){
toggle.removeClass( 'active' );
}else{
toggle.addClass( 'active' );
}
},
'click .toggle-handle': function( event ){
var toggle = $(event.target).parent();
if( toggle.hasClass( 'active' ) ){
toggle.removeClass( 'active' );
}else{
toggle.addClass( 'active' );
}
}
};
// Helpers for layout template
// Add the following to your Meteor app:
// Template.myLayoutTemplateName.helpers(Velociratchet.helpers);
Velociratchet.helpers = {
transition: function () {
return function (from, to, element) {
return Velociratchet.transition || 'vratchet-fade';
}
}
};
// Spacebar helpers
if( Meteor.isClient ) {
UI.registerHelper('getPreviousPage', function () {
return Velociratchet.history[Velociratchet.history.length-1];
});
UI.registerHelper('isActive', function (args) {
return args.hash.menu === args.hash.active ? 'active' : '';
});
UI.registerHelper('getCurrentRoute', function () {
return Router.current().route.getName();
});
// XXX: make this a plugin itself?
var sideToSide = function(fromX, toX) {
return function(options) {
options = _.extend({
duration: 500,
easing: 'ease-in-out'
}, options);
return {
insertElement: function(node, next, done) {
var $node = $(node);
$node
.css('transform', 'translateX(' + fromX + ')')
.insertBefore(next)
.velocity({
translateX: [0, fromX]
}, {
easing: options.easing,
duration: options.duration,
queue: false,
complete: function() {
$node.css('transform', '');
done();
}
});
},
removeElement: function(node, done) {
var $node = $(node);
$node
.velocity({
translateX: [toX]
}, {
duration: options.duration,
easing: options.easing,
complete: function() {
$node.remove();
done();
}
});
}
}
}
}
Momentum.registerPlugin('vratchet-right-to-left', sideToSide('100%', '-100%'));
Momentum.registerPlugin('vratchet-left-to-right', sideToSide('-100%', '100%'));
Momentum.registerPlugin('vratchet-fade', function(options) {
Velociratchet.clearHistory();
return {
insertElement: function(node, next) {
$(node)
.hide()
.insertBefore(next)
.velocity('fadeIn');
},
removeElement: function(node) {
$(node).velocity('fadeOut', function() {
$(this).remove();
});
}
}
});
}