Skip to content

Commit

Permalink
event handlers now receive custom data in multiple arguments
Browse files Browse the repository at this point in the history
For jQuery compatibility.

closes #183
  • Loading branch information
John Boxall authored and mislav committed Aug 1, 2011
1 parent 90a0ec1 commit 11de4dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -31,7 +31,7 @@
events.split(/\s/).forEach(function(event){
var callback = delegate || fn;
var proxyfn = function (event) {
var result = callback.call(element, event, event.data);
var result = callback.apply(element, [event].concat(event.data));
if (result === false) {
event.preventDefault();
}
Expand Down
24 changes: 24 additions & 0 deletions test/zepto.html
Expand Up @@ -1663,6 +1663,30 @@ <h1>Zepto DOM unit tests</h1>
var $endTest2 = $('#end_test').find('div').find('span').end().end();
t.assertEqual($endTest.length, $endTest2.length);
t.assertEqual($endTest.get(0), $endTest2.get(0));
},

testCustomEvents: function (t) {
var $body = $(document.body);

$body.bind('custom', function(evt, a, b) {
t.assertEqual(a, 1);
t.assertEqual(b, 2);
$body.unbind();
})
$body.trigger('custom', [1, 2]);

$body.bind('custom', function(evt, a) {
t.assertEqual(a, 1);
$body.unbind();
})
$body.trigger('custom', 1);

var eventData = {z: 1};
$body.bind('custom', function(evt, a) {
t.assertEqual(a, eventData);
$body.unbind();
})
$body.trigger('custom', eventData);
}
});
</script>
Expand Down

0 comments on commit 11de4dc

Please sign in to comment.