X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=9406aa83949e2b490fed5fcd9c48731998f33da3;hb=ec7fdf37235583a807b3f08e146edaadc81ca974;hp=b026672df7e789acfc103757d90f0cdccd027d3d;hpb=0c4418bbc4022ed5cb746af364ff1c0d7c331209;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index b026672..9406aa8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,16 +1,17 @@ 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 +19,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 +61,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 ); + } }); }, @@ -105,8 +116,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" ); @@ -137,10 +147,18 @@ jQuery.fn.extend({ }, domManip: function( args, table, callback ) { - var fragment, scripts, cacheable, cached, cacheresults, first; + 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 ) { + if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("]*?)\/>/g, function(all, front, tag){ - return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? + return /^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i.test(tag) ? all : front + ">"; }); @@ -290,7 +309,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + /^<(thead|tbody|tfoot|colg|cap)/.test(tags) && [ 1, "", "
" ] || !tags.indexOf(" from table fragments if ( !jQuery.support.tbody ) { @@ -324,28 +344,32 @@ jQuery.extend({ tbody = !tags.indexOf(" or - wrap[1] == "" && !hasBody ? - div.childNodes : - []; + // String was a bare or + wrap[1] == "
" && !hasBody ? + div.childNodes : + []; - for ( var j = tbody.length - 1; j >= 0 ; --j ) - if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) + for ( var j = tbody.length - 1; j >= 0 ; --j ) { + if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) { tbody[ j ].parentNode.removeChild( tbody[ j ] ); - + } } + } + // IE completely kills leading whitespace when innerHTML is used - if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) - div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); + if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) { + div.insertBefore( context.createTextNode( /^\s*/.exec(elem)[0] ), div.firstChild ); + } elem = jQuery.makeArray( div.childNodes ); } - if ( elem.nodeType ) + if ( elem.nodeType ) { ret.push( elem ); - else + } else { ret = jQuery.merge( ret, elem ); + } });