Skip to content

Commit

Permalink
Added Momentum.disable() for #28
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Mar 31, 2015
1 parent 3112103 commit b082a0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Animate height in from zero to full, out from full to zero. Works with auto-heig
# Your own plugin

Writing a plugin is simple. See the existing plugins for examples. You just need to provide an `insertElement` and `removeElement` (and optionally `moveElement`) hook. These have the same API as [Meteor's `_uihooks`](https://github.com/meteor/meteor/blob/master/History.md#blaze-2).
# Disabling momentum

On certain devices you may wish to disable momentum. To do, so call `Momentum.disable()`.

# Contributions

Expand Down
19 changes: 16 additions & 3 deletions momentum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ Template.momentum.rendered = function() {
check(hooks, Match.Where(function (x) {
return _.isFunction(x.insertElement) && _.isFunction(x.moveElement) && _.isFunction(x.removeElement);
}));

// get either hooks or the 'none' plugin hooks depending if we are disabled
var getHooks = function() {
if (Momentum.disabled) {
return Momentum.plugins.none();
} else {
return hooks;
}
}

// 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);
getHooks().insertElement(node, next, _.identity);
},
moveElement: function(node, next) {
hooks.moveElement(node, next, _.identity);
getHooks().moveElement(node, next, _.identity);
},
removeElement: function(node, done) {
hooks.removeElement(node, _.identity);
getHooks().removeElement(node, _.identity);
}
};
}
Expand All @@ -42,5 +51,9 @@ Momentum = {
check(name, String);
check(plugin, Function)
this.plugins[name] = plugin;
},
disabled: false,
disable: function() {
this.disabled = true;
}
}
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
summary: "Reactive animations",
version: "0.7.2",
version: "0.7.3",
name: "percolate:momentum",
git: "https://github.com/percolatestudio/meteor-momentum.git"
});
Expand Down

0 comments on commit b082a0d

Please sign in to comment.