aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-01-25 17:01:07 -0500
committerjeresig <jeresig@gmail.com>2010-01-25 17:01:07 -0500
commit390186b902c4c1ac13e23754d33ed4d8b3d5fa38 (patch)
treeedb94a89926d029bfc56d35bc2b640dcfccca86d
parent0474917c9d82fa13d865282d2da2d3cb6e5b89ec (diff)
downloadjquery-390186b902c4c1ac13e23754d33ed4d8b3d5fa38.tar.gz
jquery-390186b902c4c1ac13e23754d33ed4d8b3d5fa38.zip
Make sure that special.add actually copies over event namespaces and data. Fixes #5779 and #5834.
-rw-r--r--src/event.js2
-rw-r--r--test/unit/event.js41
2 files changed, 43 insertions, 0 deletions
diff --git a/src/event.js b/src/event.js
index 8ec1d4f36..58f7a3190 100644
--- a/src/event.js
+++ b/src/event.js
@@ -114,6 +114,8 @@ jQuery.event = {
var modifiedHandler = special.add.call( elem, handler, data, namespaces, handlers );
if ( modifiedHandler && jQuery.isFunction( modifiedHandler ) ) {
modifiedHandler.guid = modifiedHandler.guid || handler.guid;
+ modifiedHandler.data = modifiedHandler.data || handler.data;
+ modifiedHandler.type = modifiedHandler.type || handler.type;
handler = modifiedHandler;
}
}
diff --git a/test/unit/event.js b/test/unit/event.js
index 30ed09e29..824707fee 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -71,6 +71,47 @@ test("bind(), multiple events at once and namespaces", function() {
div.trigger("focusout.b");
});
+test("bind(), namespace with special add", function() {
+ expect(9);
+
+ var div = jQuery("<div/>").bind("test", function(e) {
+ ok( true, "Test event fired." );
+ });
+
+ var i = 0;
+
+ jQuery.event.special.test = {
+ setup: function(){},
+ teardown: function(){},
+ add: function( handler, data, namespaces ) {
+ return function(e) {
+ e.xyz = ++i;
+ handler.apply( this, arguments );
+ };
+ },
+ remove: function() {}
+ };
+
+ div.bind("test.a", {x: 1}, function(e) {
+ ok( !!e.xyz, "Make sure that the data is getting passed through." );
+ equals( e.data.x, 1, "Make sure data is attached properly." );
+ });
+
+ div.bind("test.b", {x: 2}, function(e) {
+ ok( !!e.xyz, "Make sure that the data is getting passed through." );
+ equals( e.data.x, 2, "Make sure data is attached properly." );
+ });
+
+ // Should trigger 5
+ div.trigger("test");
+
+ // Should trigger 2
+ div.trigger("test.a");
+
+ // Should trigger 2
+ div.trigger("test.b");
+});
+
test("bind(), no data", function() {
expect(1);
var handler = function(event) {