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