X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmanipulation.js;h=f577cf83772928522e2c42e70ccff2114d788207;hb=f57d93bf18a2d5c3b7a0b50da67cf6147aa389c3;hp=9406aa83949e2b490fed5fcd9c48731998f33da3;hpb=ec7fdf37235583a807b3f08e146edaadc81ca974;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 9406aa8..f577cf8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,3 +1,16 @@ +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 = /"; + }); + jQuery.fn.extend({ text: function( text ) { if ( typeof text !== "object" && text !== undefined ) @@ -106,9 +119,11 @@ jQuery.fn.extend({ html = div.innerHTML; } - return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")], ownerDocument)[0]; - } else + return jQuery.clean([html.replace(rinlinejQuery, "") + .replace(rleadingWhitespace, "")], ownerDocument)[0]; + } else { return this.cloneNode(true); + } }); // Copy the events from the original to the clone @@ -137,7 +152,7 @@ jQuery.fn.extend({ html: function( value ) { return value === undefined ? (this[0] ? - this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") : + this[0].innerHTML.replace(rinlinejQuery, "") : null) : this.empty().append( value ); }, @@ -155,7 +170,7 @@ jQuery.fn.extend({ args[0] = value.call(this); return jQuery(this).domManip( args, table, callback ); }); - }; + } if ( this[0] ) { if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("$/.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 +308,11 @@ 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) ? - all : - front + ">"; - }); + elem = elem.replace(rxhtmlTag, fcloseTag); // 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 +322,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - /^<(thead|tbody|tfoot|colg|cap)/.test(tags) && + rinsideTable.test(tags) && [ 1, "", "
" ] || !tags.indexOf(", *may* have spurious - var hasBody = /