MCPcopy Index your code
hub / github.com/JsAaron/jQuery / cloneFixAttributes

Function cloneFixAttributes

1.7/manipulation.js:400–456  ·  view source on GitHub ↗
( src, dest )

Source from the content-addressed store, hash-verified

398}
399
400function cloneFixAttributes( src, dest ) {
401 var nodeName;
402
403 // We do not need to do anything for non-Elements
404 if ( dest.nodeType !== 1 ) {
405 return;
406 }
407
408 // clearAttributes removes the attributes, which we don't want,
409 // but also removes the attachEvent events, which we *do* want
410 if ( dest.clearAttributes ) {
411 dest.clearAttributes();
412 }
413
414 // mergeAttributes, in contrast, only merges back on the
415 // original attributes, not the events
416 if ( dest.mergeAttributes ) {
417 dest.mergeAttributes( src );
418 }
419
420 nodeName = dest.nodeName.toLowerCase();
421
422 // IE6-8 fail to clone children inside object elements that use
423 // the proprietary classid attribute value (rather than the type
424 // attribute) to identify the type of content to display
425 if ( nodeName === "object" ) {
426 dest.outerHTML = src.outerHTML;
427
428 } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
429 // IE6-8 fails to persist the checked state of a cloned checkbox
430 // or radio button. Worse, IE6-7 fail to give the cloned element
431 // a checked appearance if the defaultChecked value isn't also set
432 if ( src.checked ) {
433 dest.defaultChecked = dest.checked = src.checked;
434 }
435
436 // IE6-7 get confused and end up setting the value of a cloned
437 // checkbox/radio button to an empty string instead of "on"
438 if ( dest.value !== src.value ) {
439 dest.value = src.value;
440 }
441
442 // IE6-8 fails to return the selected option to the default selected
443 // state when cloning options
444 } else if ( nodeName === "option" ) {
445 dest.selected = src.defaultSelected;
446
447 // IE6-8 fails to set the defaultValue to the correct value when
448 // cloning other types of input fields
449 } else if ( nodeName === "input" || nodeName === "textarea" ) {
450 dest.defaultValue = src.defaultValue;
451 }
452
453 // Event data gets referenced instead of copied if the expando
454 // gets copied too
455 dest.removeAttribute( jQuery.expando );
456}
457

Callers 1

manipulation.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected