Skip to content
Permalink
Browse files

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

…0af1. Fixes #6832.
  • Loading branch information...
jeresig committed Jul 27, 2010
1 parent 646fbea commit c4b4df469161ed3c3d372ebed342261efd413ac1
Showing with 14 additions and 3 deletions.
  1. +7 −2 src/data.js
  2. +7 −1 test/unit/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 );
});
}
},
@@ -70,7 +70,13 @@ test(".data()", function() {

test(".data(String) and .data(String, Object)", function() {
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" );

1 comment on commit c4b4df4

@jdalton

This comment has been minimized.

Copy link
Member

commented on c4b4df4 Jul 27, 2010

Shouldn't the changeData event only fire if the value is changed.
So say the value was foo.If you set the value to fooagain then the value didn't change and thechangeData event shouldn't trigger, amirite?

Please sign in to comment.
You can’t perform that action at this time.