mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
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.
This commit is contained in:
parent
499658970b
commit
633ca9c161
@ -50,6 +50,7 @@ jQuery.event = {
|
||||
if ( handler.handler ) {
|
||||
handleObjIn = handler;
|
||||
handler = handleObjIn.handler;
|
||||
selector = handleObjIn.selector;
|
||||
}
|
||||
|
||||
// Make sure that the handler has a unique ID, used to find/remove it later
|
||||
|
@ -394,7 +394,7 @@ function cloneCopyEvent( src, dest ) {
|
||||
|
||||
for ( type in events ) {
|
||||
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
|
||||
jQuery.event.add( dest, type + ( events[ type ][ i ].namespace ? "." : "" ) + events[ type ][ i ].namespace, events[ type ][ i ], events[ type ][ i ].data );
|
||||
jQuery.event.add( dest, type, events[ type ][ i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2657,6 +2657,29 @@ test(".on( event-map, null-selector, data ) #11130", function() {
|
||||
$p.on( map, null, data ).trigger("foo");
|
||||
});
|
||||
|
||||
test("clone() delegated events (#11076)", function() {
|
||||
expect(3);
|
||||
|
||||
var counter = { center: 0, fold: 0, centerfold: 0 },
|
||||
clicked = function( event ) {
|
||||
counter[ jQuery(this).text().replace(/\s+/, "") ]++;
|
||||
},
|
||||
table =
|
||||
jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" )
|
||||
.on( "click", "tr", clicked )
|
||||
.on( "click", "td:first-child", clicked )
|
||||
.on( "click", "td:last-child", clicked ),
|
||||
clone = table.clone( true );
|
||||
|
||||
clone.find("td").click();
|
||||
equal( counter.center, 1, "first child" );
|
||||
equal( counter.fold, 1, "last child" );
|
||||
equal( counter.centerfold, 2, "all children" );
|
||||
|
||||
table.remove();
|
||||
clone.remove();
|
||||
});
|
||||
|
||||
test("delegated events quickIs", function() {
|
||||
expect(14);
|
||||
var markup = jQuery(
|
||||
|
Loading…
Reference in New Issue
Block a user