X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=inline;f=src%2Fmanipulation.js;h=dbf86a7b3aff9d30576de8cd1e6888a644e174fb;hb=255a293cda03e787998747a3f7b1e456b683a0f6;hp=59973deee8ba546bd1612eab9a471f38b61da690;hpb=7d7a960035b7431887581c9cef09eaaef28e3d27;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 59973de..dbf86a7 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,16 +1,30 @@ +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 = /
" + tag + ">"; + }; + jQuery.fn.extend({ text: function( text ) { - if ( typeof text !== "object" && text != null ) + if ( typeof text !== "object" && text !== undefined ) return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); var ret = ""; jQuery.each( text || this, function(){ jQuery.each( this.childNodes, function(){ - if ( this.nodeType != 8 ) - ret += this.nodeType != 1 ? + if ( this.nodeType !== 8 ) { + ret += this.nodeType !== 1 ? this.nodeValue : jQuery.fn.text( [ this ] ); + } }); }); @@ -18,18 +32,26 @@ jQuery.fn.extend({ }, wrapAll: function( html ) { + if ( jQuery.isFunction( html ) ) { + return this.each(function() { + jQuery(this).wrapAll( html.apply(this, arguments) ); + }); + } + if ( this[0] ) { // The elements to wrap the target around - var wrap = jQuery( html, this[0].ownerDocument ).clone(); + var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(); - if ( this[0].parentNode ) + if ( this[0].parentNode ) { wrap.insertBefore( this[0] ); + } wrap.map(function(){ var elem = this; - while ( elem.firstChild ) + while ( elem.firstChild && elem.firstChild.nodeType === 1 ) { elem = elem.firstChild; + } return elem; }).append(this); @@ -52,15 +74,17 @@ jQuery.fn.extend({ append: function() { return this.domManip(arguments, true, function(elem){ - if (this.nodeType == 1) + if ( this.nodeType === 1 ) { this.appendChild( elem ); + } }); }, prepend: function() { return this.domManip(arguments, true, function(elem){ - if (this.nodeType == 1) + if ( this.nodeType === 1 ) { this.insertBefore( elem, this.firstChild ); + } }); }, @@ -95,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 @@ -105,8 +131,7 @@ jQuery.fn.extend({ var orig = this.find("*").andSelf(), i = 0; ret.find("*").andSelf().each(function(){ - if ( this.nodeName !== orig[i].nodeName ) - return; + if ( this.nodeName !== orig[i].nodeName ) { return; } var events = jQuery.data( orig[i], "events" ); @@ -127,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 ); }, @@ -136,16 +161,20 @@ 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; - var value = args[0]; + var fragment, scripts, cacheable, cached, cacheresults, first, + value = args[0]; if ( jQuery.isFunction(value) ) { return this.each(function() { 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("