X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=inline;f=src%2Fmanipulation.js;h=dbf86a7b3aff9d30576de8cd1e6888a644e174fb;hb=b7a3b220a8a2b5b0378c9f176ca5ae0f786a6fcf;hp=c2c0ff2a70bce0fc6fdc2689d59089504ee5d8a8;hpb=7c04a64016c1f295dfdf4e731f693f8400a987bc;p=jquery.git
diff --git a/src/manipulation.js b/src/manipulation.js
index c2c0ff2..dbf86a7 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -1,21 +1,30 @@
-// exclude the following css properties to add px
-var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
- // cache defaultView
- defaultView = document.defaultView || {};
+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 ] );
+ }
});
});
@@ -23,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);
@@ -57,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 );
+ }
});
},
@@ -100,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
@@ -110,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" );
@@ -132,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 );
},
@@ -141,25 +161,68 @@ 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];
+
+ if ( jQuery.isFunction(value) ) {
+ return this.each(function() {
+ args[0] = value.call(this);
+ return jQuery(this).domManip( args, table, callback );
+ });
+ }
+
if ( this[0] ) {
- var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
- scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
- first = fragment.firstChild;
-
- if ( first )
- for ( var i = 0, l = this.length; i < l; i++ )
- callback.call( root(this[i], first), this.length > 1 || i > 0 ?
- fragment.cloneNode(true) : fragment );
-
- if ( scripts )
+ if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("