Skip to content

Commit 633ca9c

Browse files
committed
Fix #11076. If .clone() won't delegate, we must remediate.
Since `jQuery.event.add` can accept a handleObj there's no need to reiterate them as args, but we *do* need to set the `selector` variable correctly.
1 parent 4996589 commit 633ca9c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jQuery.event = {
5050
if ( handler.handler ) {
5151
handleObjIn = handler;
5252
handler = handleObjIn.handler;
53+
selector = handleObjIn.selector;
5354
}
5455

5556
// Make sure that the handler has a unique ID, used to find/remove it later

src/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ function cloneCopyEvent( src, dest ) {
394394

395395
for ( type in events ) {
396396
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
397-
jQuery.event.add( dest, type + ( events[ type ][ i ].namespace ? "." : "" ) + events[ type ][ i ].namespace, events[ type ][ i ], events[ type ][ i ].data );
397+
jQuery.event.add( dest, type, events[ type ][ i ] );
398398
}
399399
}
400400
}

test/unit/event.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,29 @@ test(".on( event-map, null-selector, data ) #11130", function() {
26572657
$p.on( map, null, data ).trigger("foo");
26582658
});
26592659

2660+
test("clone() delegated events (#11076)", function() {
2661+
expect(3);
2662+
2663+
var counter = { center: 0, fold: 0, centerfold: 0 },
2664+
clicked = function( event ) {
2665+
counter[ jQuery(this).text().replace(/\s+/, "") ]++;
2666+
},
2667+
table =
2668+
jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" )
2669+
.on( "click", "tr", clicked )
2670+
.on( "click", "td:first-child", clicked )
2671+
.on( "click", "td:last-child", clicked ),
2672+
clone = table.clone( true );
2673+
2674+
clone.find("td").click();
2675+
equal( counter.center, 1, "first child" );
2676+
equal( counter.fold, 1, "last child" );
2677+
equal( counter.centerfold, 2, "all children" );
2678+
2679+
table.remove();
2680+
clone.remove();
2681+
});
2682+
26602683
test("delegated events quickIs", function() {
26612684
expect(14);
26622685
var markup = jQuery(

0 commit comments

Comments
 (0)