X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=dbf86a7b3aff9d30576de8cd1e6888a644e174fb;hb=6a85898d131f9921f2d8e885a892fbdcf4d9c5c6;hp=9406aa83949e2b490fed5fcd9c48731998f33da3;hpb=ec7fdf37235583a807b3f08e146edaadc81ca974;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 9406aa8..dbf86a7 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 ) @@ -24,7 +37,7 @@ jQuery.fn.extend({ jQuery(this).wrapAll( html.apply(this, arguments) ); }); } - + if ( this[0] ) { // The elements to wrap the target around var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(); @@ -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 ); }, @@ -146,6 +161,10 @@ jQuery.fn.extend({ return this.after( value ).remove(); }, + detach: function( selector ) { + return this.remove( selector, true ); + }, + domManip: function( args, table, callback ) { var fragment, scripts, cacheable, cached, cacheresults, first, value = args[0]; @@ -155,7 +174,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 +313,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 +327,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - /^<(thead|tbody|tfoot|colg|cap)/.test(tags) && + rinsideTable.test(tags) && [ 1, "", "
" ] || !tags.indexOf(", *may* have spurious - var hasBody = /