-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmomentum.js
46 lines (39 loc) · 1.33 KB
/
momentum.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
Template.momentum.rendered = function() {
if (! this.data || ! this.data.plugin)
return console.error("Missing 'plugin' argument to momentum");
var plugin = Momentum.plugins[this.data.plugin];
if (! plugin)
return console.error("Can't find momentum plugin '" + this.data.plugin + "'");
var hooks = plugin(_.omit(this.data, 'plugin'));
// default is to remove, *then* add
if (! hooks.moveElement)
hooks.moveElement = function(node, next, done) {
hooks.removeElement(node, function() {
hooks.insertElement(node, next, done);
});
}
check(hooks, Match.Where(function (x) {
return _.isFunction(x.insertElement) && _.isFunction(x.moveElement) && _.isFunction(x.removeElement);
}));
// Pass in the _identity function for the done callback as by default
// momentum doesn't care about when transitions are done.
this.lastNode._uihooks = {
insertElement: function(node, next) {
hooks.insertElement(node, next, _.identity);
},
moveElement: function(node, next) {
hooks.moveElement(node, next, _.identity);
},
removeElement: function(node, done) {
hooks.removeElement(node, _.identity);
}
};
}
Momentum = {
plugins: {},
registerPlugin: function(name, plugin) {
check(name, String);
check(plugin, Function)
this.plugins[name] = plugin;
}
}