Move cases of .replace(re, Function) out from inline (to avoid being redeclared on...
[jquery.git] / src / manipulation.js
index 237e957..f577cf8 100644 (file)
@@ -4,7 +4,12 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
        rxhtmlTag = /(<(\w+)[^>]*?)\/>/g,
        rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i,
        rinsideTable = /^<(thead|tbody|tfoot|colg|cap)/,
-       rtbody = /<tbody/i;
+       rtbody = /<tbody/i,
+       fcloseTag = function(all, front, tag){
+               return rselfClosing.test(tag) ?
+                       all :
+                       front + "></" + tag + ">";
+       });
 
 jQuery.fn.extend({
        text: function( text ) {
@@ -303,11 +308,7 @@ jQuery.extend({
                        // Convert html string into DOM nodes
                        if ( typeof elem === "string" ) {
                                // Fix "XHTML"-style tags in all browsers
-                               elem = elem.replace(rxhtmlTag, function(all, front, tag){
-                                       return rselfClosing.test(tag) ?
-                                               all :
-                                               front + "></" + tag + ">";
-                               });
+                               elem = elem.replace(rxhtmlTag, fcloseTag);
 
                                // Trim whitespace, otherwise indexOf won't work as expected
                                var tags = elem.replace(rleadingWhitespace, "")
@@ -370,8 +371,8 @@ jQuery.extend({
                                }
 
                                // IE completely kills leading whitespace when innerHTML is used
-                               if ( !jQuery.support.leadingWhitespace && leadingWhitespace.test( elem ) ) {
-                                       div.insertBefore( context.createTextNode( leadingWhitespace.exec(elem)[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 );