]> source.dussan.org Git - jquery.git/commitdiff
Fix #11796. Preserve oldIE change delegation on clone. Closes gh-789.
authorJason Moon <jmoon@socialcast.com>
Mon, 21 May 2012 23:01:59 +0000 (18:01 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 23 May 2012 01:29:13 +0000 (21:29 -0400)
src/event.js
src/manipulation.js
test/unit/event.js

index 458eafbc2b6dccad95793bb8cdc377079016cb63..b4a76c7101c61132485ed01db386c2d035aacbe4 100644 (file)
@@ -835,13 +835,13 @@ if ( !jQuery.support.changeBubbles ) {
                        jQuery.event.add( this, "beforeactivate._change", function( e ) {
                                var elem = e.target;
 
-                               if ( rformElems.test( elem.nodeName ) && !elem._change_attached ) {
+                               if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "_change_attached" ) ) {
                                        jQuery.event.add( elem, "change._change", function( event ) {
                                                if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
                                                        jQuery.event.simulate( "change", this.parentNode, event, true );
                                                }
                                        });
-                                       elem._change_attached = true;
+                                       jQuery._data( elem, "_change_attached", true );
                                }
                        });
                },
index ee5a84c51483e7c3c6522cb528921d5c4c2fc336..2c1f0d2b367ff3c1546dea0307628052d4fe966a 100644 (file)
@@ -464,10 +464,6 @@ function cloneFixAttributes( src, dest ) {
        // Event data gets referenced instead of copied if the expando
        // gets copied too
        dest.removeAttribute( jQuery.expando );
-
-       // Clear flags for bubbling special change/submit events, they must
-       // be reattached when the newly cloned events are first activated
-       dest.removeAttribute( "_change_attached" );
 }
 
 jQuery.buildFragment = function( args, context, scripts ) {
index 78d14b6757c1ea9739fb7c36ce22ee91adcd420d..db7065fd16f366eca4aa38e1c80b683f6d42bb2a 100644 (file)
@@ -1098,6 +1098,38 @@ test( "submit event bubbles on copied forms (#11649)", function(){
        $testForm.off( "submit", noSubmit );
 });
 
+test( "change event bubbles on copied forms (#11796)", function(){
+       expect( 3 );
+       
+       var $formByClone, $formByHTML,
+               $form = jQuery("#form"),
+               $fixture = jQuery("#qunit-fixture"),
+               $wrapperDiv = jQuery("<div/>").appendTo( $fixture );
+       
+       function delegatedChange() {
+               ok( true, "Make sure change event bubbles up." );
+               return false;
+       }
+       
+       // Attach a delegated change handler to the form
+       $fixture.on( "change", "form", delegatedChange );
+       
+       // Trigger change event to introduce the _change_attached property
+       $form.find("select[name=select1]").val("1").change();
+       
+       // Copy the form via .clone() and .html()
+       $formByClone = $form.clone( true, true ).removeAttr("id");
+       $formByHTML = jQuery( $fixture.html() ).filter("#form").removeAttr("id");
+       $wrapperDiv.append( $formByClone, $formByHTML );
+       
+       // Check change bubbling on the copied forms
+       $wrapperDiv.find("form select[name=select1]").val("2").change();
+       
+       // Clean up
+       $wrapperDiv.remove();
+       $fixture.off( "change", "form", delegatedChange );
+});
+
 test("trigger(eventObject, [data], [fn])", function() {
        expect(28);