Skip to content

Commit

Permalink
Move fixChecked function definition out of clean and out of the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Apr 17, 2011
1 parent ac39d0c commit 54b3fb8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/manipulation.js
Expand Up @@ -509,6 +509,18 @@ function getAll( elem ) {
}
}

// Used in clean, fixes the defaultChecked property
// on all inputs and checkboxes within html recursively
function fixChecked( elem ) {
if ( jQuery.nodeName( elem, "input" ) ) {
if ( elem.type === "checkbox" || elem.type === "radio" ) {
elem.defaultChecked = elem.checked;
}
} else if ( elem.getElementsByTagName ) {
jQuery.grep( elem.getElementsByTagName("input"), fixChecked );
}
}

jQuery.extend({
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
var clone = elem.cloneNode(true),
Expand Down Expand Up @@ -558,7 +570,7 @@ jQuery.extend({
},

clean: function( elems, context, fragment, scripts ) {
var checkScriptType, fixChecked, len;
var checkScriptType;

context = context || document;

Expand Down Expand Up @@ -629,18 +641,10 @@ jQuery.extend({
}
}

// Resets defaultChecked for any radios and checkboxes about to be appended to the DOM in IE 6/7 (#8060)
// Resets defaultChecked for any radios and checkboxes
// about to be appended to the DOM in IE 6/7 (#8060)
var len;
if ( !jQuery.support.appendChecked ) {
fixChecked = function( elem ) {
if ( jQuery.nodeName( elem, "input" ) ) {
if ( elem.type === "checkbox" || elem.type === "radio" ) {
elem.defaultChecked = elem.checked;
}
} else if ( elem.getElementsByTagName ) {
jQuery.grep( elem.getElementsByTagName("input"), fixChecked );
}
};

if ( elem[0] && typeof (len = elem.length) === "number" ) {
for ( i = 0; i < len; i++ ) {
fixChecked( elem[i] );
Expand Down

0 comments on commit 54b3fb8

Please sign in to comment.