Commit c4b4df46 authored by John Resig's avatar John Resig

Make sure that .data() events don't bubble, per the discussion in...

Make sure that .data() events don't bubble, per the discussion in 2e10af14. Fixes #6832.
parent 646fbea5
...@@ -143,13 +143,18 @@ jQuery.fn.extend({ ...@@ -143,13 +143,18 @@ jQuery.fn.extend({
if ( data === undefined && this.length ) { if ( data === undefined && this.length ) {
data = jQuery.data( this[0], key ); data = jQuery.data( this[0], key );
} }
return data === undefined && parts[1] ? return data === undefined && parts[1] ?
this.data( parts[0] ) : this.data( parts[0] ) :
data; data;
} else { } 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.data( this, key, value );
jQuery.event.trigger( "changeData" + parts[1] + "!", [parts[0], value], this ); $this.triggerHandler( "changeData" + parts[1] + "!", args );
}); });
} }
}, },
......
...@@ -70,7 +70,13 @@ test(".data()", function() { ...@@ -70,7 +70,13 @@ test(".data()", function() {
test(".data(String) and .data(String, Object)", function() { test(".data(String) and .data(String, Object)", function() {
expect(27); expect(27);
var div = jQuery("<div/>"); var parent = jQuery("<div><div></div></div>"),
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" ); ok( div.data("test") === undefined, "Check for no data exists" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment