git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9e06903
)
Make it so that you can pass in event data to .click(), et. al. Fixes #6187.
author
jeresig
<jeresig@gmail.com>
Sat, 27 Feb 2010 01:01:19 +0000
(20:01 -0500)
committer
jeresig
<jeresig@gmail.com>
Sat, 27 Feb 2010 01:01:19 +0000
(20:01 -0500)
src/event.js
patch
|
blob
|
history
test/unit/event.js
patch
|
blob
|
history
diff --git
a/src/event.js
b/src/event.js
index
bfe2dd1
..
779c069
100644
(file)
--- a/
src/event.js
+++ b/
src/event.js
@@
-1071,8
+1071,10
@@
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
"change select submit keydown keypress keyup error").split(" "), function( i, name ) {
// Handle event binding
"change select submit keydown keypress keyup error").split(" "), function( i, name ) {
// Handle event binding
- jQuery.fn[ name ] = function( fn ) {
- return fn ? this.bind( name, fn ) : this.trigger( name );
+ jQuery.fn[ name ] = function( data, fn ) {
+ return data || fn ?
+ this.bind( name, fn ? data : null, fn || data ) :
+ this.trigger( name );
};
if ( jQuery.attrFn ) {
};
if ( jQuery.attrFn ) {
diff --git
a/test/unit/event.js
b/test/unit/event.js
index
a220ebf
..
6404900
100644
(file)
--- a/
test/unit/event.js
+++ b/
test/unit/event.js
@@
-11,6
+11,17
@@
test("bind(), with data", function() {
ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
});
ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
});
+test("click(), with data", function() {
+ expect(3);
+ var handler = function(event) {
+ ok( event.data, "bind() with data, check passed data exists" );
+ equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
+ };
+ jQuery("#firstp").click({foo: "bar"}, handler).click().unbind("click", handler);
+
+ ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
+});
+
test("bind(), with data, trigger with data", function() {
expect(4);
var handler = function(event, data) {
test("bind(), with data, trigger with data", function() {
expect(4);
var handler = function(event, data) {