From 6d23f2fd81f9f1894060a353e66effdf9738af16 Mon Sep 17 00:00:00 2001 From: John Resig Date: Sun, 19 Jul 2009 15:48:30 +0000 Subject: [PATCH] Made more formatting changes to manipulation.js. Also moved all inline RegExp into a top declaration. --- src/manipulation.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 9406aa839..237e957e5 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,3 +1,11 @@ +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"); @@ -292,14 +303,15 @@ jQuery.extend({ // 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 /^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i.test(tag) ? + 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 @@ -309,7 +321,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - /^<(thead|tbody|tfoot|colg|cap)/.test(tags) && + rinsideTable.test(tags) && [ 1, "", "
" ] || !tags.indexOf(", *may* have spurious - var hasBody = /