More clean up on jQuery.clean

This commit is contained in:
Brandon Aaron 2006-10-19 21:47:05 +00:00
parent 24142f6031
commit 4bcb578c79

17
src/jquery/jquery.js vendored
View file

@ -1548,9 +1548,10 @@ jQuery.extend({
clean: function(a) { clean: function(a) {
var r = []; var r = [];
for ( var i = 0; i < a.length; i++ ) { for ( var i = 0; i < a.length; i++ ) {
if ( a[i].constructor == String ) { // Convert html string into DOM nodes var arg = a[i];
if ( arg.constructor == String ) { // Convert html string into DOM nodes
// Trim whitespace, otherwise indexOf won't work as expected // Trim whitespace, otherwise indexOf won't work as expected
var s = jQuery.trim(a[i]), div = document.createElement("div"), wrap = [0,"",""]; var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
if ( !s.indexOf("<opt") ) // option or optgroup if ( !s.indexOf("<opt") ) // option or optgroup
wrap = [1, "<select>", "</select>"]; wrap = [1, "<select>", "</select>"];
@ -1564,14 +1565,14 @@ jQuery.extend({
// Go to html and back, then peel off extra wrappers // Go to html and back, then peel off extra wrappers
div.innerHTML = wrap[1] + s + wrap[2]; div.innerHTML = wrap[1] + s + wrap[2];
while ( wrap[0]-- ) div = div.firstChild; while ( wrap[0]-- ) div = div.firstChild;
a[i] = div.childNodes; arg = div.childNodes;
} }
if ( a[i].length != undefined && !a[i].nodeType ) // Handles Array, jQuery, DOM NodeList collections if ( arg.length != undefined && !arg.nodeType ) // Handles Array, jQuery, DOM NodeList collections
for ( var n=0; n < a[i].length; n++ ) for ( var n = 0; n < arg.length; n++ )
r.push(a[i][n]); r.push(arg[n]);
else if ( a[i] !== null ) else
r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) ); r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
} }
return r; return r;