]> source.dussan.org Git - jquery.git/commitdiff
Make sure that .data() events don't bubble, per the discussion in 2e10af143b7eafb7142...
authorJohn Resig <jeresig@gmail.com>
Tue, 27 Jul 2010 17:45:32 +0000 (13:45 -0400)
committerJohn Resig <jeresig@gmail.com>
Tue, 27 Jul 2010 17:45:32 +0000 (13:45 -0400)
src/data.js
test/unit/data.js

index eb96b860f74b9dea789a8921b5ecbc11e471f459..d38d47d3c19114936a79b8b633a53d6b8409f37a 100644 (file)
@@ -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 );
                        });
                }
        },
index 8a7a87b9d72bfdafb4e3f70895b84849b9686006..872bbb753067dced760af96bc28fd8f5051cae0c 100644 (file)
@@ -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" );