X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=baf99d52d90626792b8c966b6dda28e45dd6e097;hb=c90a1cb61b41a5686bc3764f144a156e734ed459;hp=1699f680189012a72ea94334ea1e82affe6bf8de;hpb=7c4144fab314d98b85303d01ab904bb711bc2ecc;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 1699f68..baf99d5 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -31,19 +31,21 @@ if ( !jQuery.support.htmlSerialize ) { jQuery.fn.extend({ text: function( text ) { - if ( typeof text !== "object" && text !== undefined ) + 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 ? - this.nodeValue : - jQuery.fn.text( [ this ] ); - } - }); + jQuery.each( this, function() { + // Get the text from text nodes and CDATA nodes + if ( this.nodeType === 3 || this.nodeType === 4 ) { + ret += this.nodeValue; + + // Traverse everything else, except comment nodes + } else if ( this.nodeType !== 8 ) { + ret += jQuery.fn.text.call( this.childNodes ); + } }); return ret; @@ -166,21 +168,8 @@ jQuery.fn.extend({ // Copy the events from the original to the clone if ( events === true ) { - var orig = this.find("*").andSelf(), i = 0; - - ret.find("*").andSelf().each(function(){ - if ( this.nodeName !== orig[i].nodeName ) { return; } - - var events = jQuery.data( orig[i], "events" ); - - for ( var type in events ) { - for ( var handler in events[ type ] ) { - jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); - } - } - - i++; - }); + cloneCopyEvent( this, ret ); + cloneCopyEvent( this.find("*"), ret.find("*") ); } // Return the cloned set @@ -195,7 +184,7 @@ jQuery.fn.extend({ // See if we can take a shortcut and just use innerHTML } else if ( typeof value === "string" && !/