X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=0051bbc0b343452c931a2cd99abdcb588dbd8167;hb=0ac9898d6b7200075d20e36d7c31ad77585c8778;hp=b5ace4d73b4dd755ac9effc148969d560b99214a;hpb=991dafae16e44512c5107b90bc8ce9675d8f5c12;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index b5ace4d..0051bbc 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,16 +1,25 @@ +var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, + rleadingWhitespace = /^\s+/, + rsingleTag = /^<(\w+)\s*\/?>$/, + rxhtmlTag = /(<(\w+)[^>]*?)\/>/g, + rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i, + rinsideTable = /^<(thead|tbody|tfoot|colg|cap)/, + rtbody = /$/.exec(elems[0]); - if ( match ) + var match = rsingleTag.exec(elems[0]); + if ( match ) { return [ context.createElement( match[1] ) ]; + } } var ret = [], scripts = [], div = context.createElement("div"); jQuery.each(elems, function(i, elem){ - if ( typeof elem === "number" ) + if ( typeof elem === "number" ) { elem += ''; + } - if ( !elem ) - return; + if ( !elem ) { return; } // Convert html string into DOM nodes if ( typeof elem === "string" ) { // Fix "XHTML"-style tags in all browsers - elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ - return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? + elem = elem.replace(rxhtmlTag, function(all, front, tag){ + return rselfClosing.test(tag) ? all : front + ">"; }); // Trim whitespace, otherwise indexOf won't work as expected - var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase(); + var tags = elem.replace(rleadingWhitespace, "") + .substring(0, 10).toLowerCase(); var wrap = // option or optgroup @@ -302,7 +321,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + rinsideTable.test(tags) && [ 1, "", "
" ] || !tags.indexOf(" from table fragments if ( !jQuery.support.tbody ) { // String was a , *may* have spurious - var hasBody = / or - wrap[1] == "
" && !hasBody ? - div.childNodes : - []; + // String was a bare or + wrap[1] == "
" && !hasBody ? + div.childNodes : + []; - for ( var j = tbody.length - 1; j >= 0 ; --j ) - if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) + for ( var j = tbody.length - 1; j >= 0 ; --j ) { + if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) { tbody[ j ].parentNode.removeChild( tbody[ j ] ); - + } } + } + // IE completely kills leading whitespace when innerHTML is used - if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) - div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); + if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { + div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild ); + } elem = jQuery.makeArray( div.childNodes ); } - if ( elem.nodeType ) + if ( elem.nodeType ) { ret.push( elem ); - else + } else { ret = jQuery.merge( ret, elem ); + } }); @@ -366,8 +390,9 @@ jQuery.extend({ if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); } else { - if ( ret[i].nodeType === 1 ) + if ( ret[i].nodeType === 1 ) { ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); + } fragment.appendChild( ret[i] ); } }