@@ -434,26 +434,26 @@ function cloneCopyEvent( src, dest ) {
434
434
}
435
435
436
436
function cloneFixAttributes ( src , dest ) {
437
- var nodeName ;
437
+ var nodeName , data , e ;
438
438
439
439
// We do not need to do anything for non-Elements
440
440
if ( dest . nodeType !== 1 ) {
441
441
return ;
442
442
}
443
443
444
- // clearAttributes removes the attributes, which we don't want,
445
- // but also removes the attachEvent events, which we *do* want
446
- if ( dest . clearAttributes ) {
447
- dest . clearAttributes ( ) ;
448
- }
444
+ nodeName = dest . nodeName . toLowerCase ( ) ;
449
445
450
- // mergeAttributes, in contrast, only merges back on the
451
- // original attributes, not the events
452
- if ( dest . mergeAttributes ) {
453
- dest . mergeAttributes ( src ) ;
454
- }
446
+ // IE6-8 copies events bound via attachEvent when using cloneNode.
447
+ if ( ! jQuery . support . noCloneEvent && dest [ jQuery . expando ] ) {
448
+ data = jQuery . _data ( dest ) ;
455
449
456
- nodeName = dest . nodeName . toLowerCase ( ) ;
450
+ for ( e in data . events ) {
451
+ jQuery . removeEvent ( dest , e , data . handle ) ;
452
+ }
453
+
454
+ // Event data gets referenced instead of copied if the expando gets copied too
455
+ dest . removeAttribute ( jQuery . expando ) ;
456
+ }
457
457
458
458
// IE blanks contents when cloning scripts, and tries to evaluate newly-set text
459
459
if ( nodeName === "script" && dest . text !== src . text ) {
@@ -498,10 +498,6 @@ function cloneFixAttributes( src, dest ) {
498
498
} else if ( nodeName === "input" || nodeName === "textarea" ) {
499
499
dest . defaultValue = src . defaultValue ;
500
500
}
501
-
502
- // Event data gets referenced instead of copied if the expando
503
- // gets copied too
504
- dest . removeAttribute ( jQuery . expando ) ;
505
501
}
506
502
507
503
jQuery . each ( {
@@ -583,19 +579,12 @@ jQuery.extend({
583
579
584
580
if ( ( ! jQuery . support . noCloneEvent || ! jQuery . support . noCloneChecked ) &&
585
581
( elem . nodeType === 1 || elem . nodeType === 11 ) && ! jQuery . isXMLDoc ( elem ) ) {
586
- // IE copies events bound via attachEvent when using cloneNode.
587
- // Calling detachEvent on the clone will also remove the events
588
- // from the original. In order to get around this, we use some
589
- // proprietary methods to clear the events. Thanks to MooTools
590
- // guys for this hotness.
591
582
592
583
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
593
584
destElements = getAll ( clone ) ;
594
585
srcElements = getAll ( elem ) ;
595
586
596
- // Weird iteration because IE will replace the length property
597
- // with an element if you are cloning the body and one of the
598
- // elements on the page has a name or id of "length"
587
+ // Fix all IE cloning issues
599
588
for ( i = 0 ; ( node = srcElements [ i ] ) != null ; ++ i ) {
600
589
// Ensure that the destination node is not null; Fixes #9587
601
590
if ( destElements [ i ] ) {
@@ -607,8 +596,8 @@ jQuery.extend({
607
596
// Copy the events from the original to the clone
608
597
if ( dataAndEvents ) {
609
598
if ( deepDataAndEvents ) {
610
- destElements = getAll ( clone ) ;
611
- srcElements = getAll ( elem ) ;
599
+ srcElements = srcElements || getAll ( elem ) ;
600
+ destElements = destElements || getAll ( clone ) ;
612
601
613
602
for ( i = 0 ; ( node = srcElements [ i ] ) != null ; i ++ ) {
614
603
cloneCopyEvent ( node , destElements [ i ] ) ;
0 commit comments