Skip to content

Commit

Permalink
Manager : fix off method
Browse files Browse the repository at this point in the history
When you didn't attach an event and you use a Hammerjs.Manager.off
method , you will see script error.

Fixes #768
Closes #839
Ref #770
  • Loading branch information
sculove authored and arschmitz committed Nov 11, 2015
1 parent 70075f2 commit da49a27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Manager.prototype = {
if (!handler) {
delete handlers[event];
} else {
handlers[event].splice(inArray(handlers[event], handler), 1);
handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
}
});
return this;
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ test('test the eventemitter', function() {
ee.emit('testEvent2', inputData); // doenst trigger a thing
ee.emit('testEvent3', inputData); // doenst trigger a thing
});

/*
* Hammer.Manager.off method : exception handling
*/
test("When Hammer.Manager didn't attach an event, 'off' method is ignored", function() {
var count = 0;
hammer = new Hammer(el, { inputTarget: document.body });
hammer.off("swipeleft", function(e) {
count++;
});
ok(true, "nothing");
});

0 comments on commit da49a27

Please sign in to comment.