Permalink
Browse files

Added preventDefault.

  • Loading branch information...
1 parent 8443b4f commit 3d7969cbd5b7a748b86282bd34391f5dd5158531 @orangemug orangemug committed Feb 17, 2014
Showing with 23 additions and 0 deletions.
  1. +1 −0 lib/delegate.js
  2. +22 −0 test/tests/delegateTest.js
View
@@ -312,6 +312,7 @@ Delegate.prototype.handle = function(event) {
// false
if (returned === false) {
event[EVENTIGNORE] = true;
+ event.preventDefault();
return;
}
}
View
@@ -173,6 +173,28 @@ buster.testCase('Delegate', {
delegate.off();
},
+ 'Returning false from a callback should preventDefault': function(done) {
+ var delegate = new Delegate(document.body);
+
+ var spyA = this.spy();
+
+ delegate.on("click", '#delegate-test-clickable', function(event) {
+ spyA();
+
+ setTimeout(function() {
+ assert.equals(event.defaultPrevented, true);
+ done();
+ }, 0);
+
+ return false;
+ });
+
+ var element = document.getElementById('delegate-test-clickable');
+ element.dispatchEvent(setupHelper.getMouseEvent("click"));
+
+ assert.calledOnce(spyA);
+ delegate.off();
+ },
'Returning false from a callback should stop propagation globally': function() {
var delegateA = new Delegate(document), delegateB = new Delegate(document);

0 comments on commit 3d7969c

Please sign in to comment.