From c4b4df469161ed3c3d372ebed342261efd413ac1 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 27 Jul 2010 13:45:32 -0400 Subject: [PATCH] Make sure that .data() events don't bubble, per the discussion in 2e10af143b7eafb7142524f6534a62aee1910bd1. Fixes #6832. --- src/data.js | 9 +++++++-- test/unit/data.js | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/data.js b/src/data.js index eb96b860f..d38d47d3c 100644 --- a/src/data.js +++ b/src/data.js @@ -143,13 +143,18 @@ jQuery.fn.extend({ if ( data === undefined && this.length ) { data = jQuery.data( this[0], key ); } + return data === undefined && parts[1] ? this.data( parts[0] ) : data; + } else { - return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() { + return this.each(function() { + var $this = jQuery( this ), args = [ parts[0], value ]; + + $this.triggerHandler( "setData" + parts[1] + "!", args ); jQuery.data( this, key, value ); - jQuery.event.trigger( "changeData" + parts[1] + "!", [parts[0], value], this ); + $this.triggerHandler( "changeData" + parts[1] + "!", args ); }); } }, diff --git a/test/unit/data.js b/test/unit/data.js index 8a7a87b9d..872bbb753 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -70,7 +70,13 @@ test(".data()", function() { test(".data(String) and .data(String, Object)", function() { expect(27); - var div = jQuery("
"); + var parent = jQuery("
"), + div = parent.children(); + + parent + .bind("getData", function(){ ok( false, "getData bubbled." ) }) + .bind("setData", function(){ ok( false, "setData bubbled." ) }) + .bind("changeData", function(){ ok( false, "changeData bubbled." ) }); ok( div.data("test") === undefined, "Check for no data exists" ); -- 2.39.5