X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=2af2d7e7dc80598794e2d7d2b72b3a82d9b914bb;hb=6cf981eea20695987b4f7341f80442a7cf8271eb;hp=91031113028d9159bf249a260fc0c2df6165ff86;hpb=209278915592fc63bd62039e246046d446d329e0;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 9103111..2af2d7e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,12 +1,12 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, rleadingWhitespace = /^\s+/, rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g, - rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i, + rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i, rtagName = /<([\w:]+)/, rtbody = /"; }, @@ -32,24 +32,17 @@ if ( !jQuery.support.htmlSerialize ) { jQuery.fn.extend({ text: function( text ) { + if ( jQuery.isFunction(text) ) { + return this.each(function() { + return jQuery(this).text( text.call(this) ); + }); + } + if ( typeof text !== "object" && text !== undefined ) { return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); } - var ret = ""; - - 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; + return jQuery.getText( this ); }, wrapAll: function( html ) { @@ -61,13 +54,13 @@ jQuery.fn.extend({ if ( this[0] ) { // The elements to wrap the target around - var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(); + var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true); if ( this[0].parentNode ) { wrap.insertBefore( this[0] ); } - wrap.map(function(){ + wrap.map(function() { var elem = this; while ( elem.firstChild && elem.firstChild.nodeType === 1 ) { @@ -82,27 +75,27 @@ jQuery.fn.extend({ }, wrapInner: function( html ) { - return this.each(function(){ + return this.each(function() { jQuery( this ).contents().wrapAll( html ); }); }, wrap: function( html ) { - return this.each(function(){ + return this.each(function() { jQuery( this ).wrapAll( html ); }); }, unwrap: function() { - return this.parent().each(function(){ + return this.parent().each(function() { if ( !jQuery.nodeName( this, "body" ) ) { jQuery( this ).replaceWith( this.childNodes ); } }).end(); }, - + append: function() { - return this.domManip(arguments, true, function(elem){ + return this.domManip(arguments, true, function( elem ) { if ( this.nodeType === 1 ) { this.appendChild( elem ); } @@ -110,7 +103,7 @@ jQuery.fn.extend({ }, prepend: function() { - return this.domManip(arguments, true, function(elem){ + return this.domManip(arguments, true, function( elem ) { if ( this.nodeType === 1 ) { this.insertBefore( elem, this.firstChild ); } @@ -119,7 +112,7 @@ jQuery.fn.extend({ before: function() { if ( this[0] && this[0].parentNode ) { - return this.domManip(arguments, false, function(elem){ + return this.domManip(arguments, false, function( elem ) { this.parentNode.insertBefore( elem, this ); }); } else if ( arguments.length ) { @@ -131,7 +124,7 @@ jQuery.fn.extend({ after: function() { if ( this[0] && this[0].parentNode ) { - return this.domManip(arguments, false, function(elem){ + return this.domManip(arguments, false, function( elem ) { this.parentNode.insertBefore( elem, this.nextSibling ); }); } else if ( arguments.length ) { @@ -143,7 +136,7 @@ jQuery.fn.extend({ clone: function( events ) { // Do the clone - var ret = this.map(function(){ + var ret = this.map(function() { if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) { // IE copies events bound via attachEvent when // using cloneNode. Calling detachEvent on the @@ -211,7 +204,7 @@ jQuery.fn.extend({ replaceWith: function( value ) { if ( this[0] && this[0].parentNode ) { - return this.each(function(){ + return this.each(function() { var next = this.nextSibling, parent = this.parentNode; jQuery(this).remove(); @@ -285,22 +278,27 @@ jQuery.fn.extend({ function cloneCopyEvent(orig, ret) { var i = 0; - ret.each(function(){ - if ( this.nodeName !== orig[i].nodeName ) { + ret.each(function() { + if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) { return; } - var events = jQuery.data( orig[i], "events" ); + var oldData = jQuery.data( orig[i++] ), curData = jQuery.data( this, oldData ), events = oldData && oldData.events; - for ( var type in events ) { - for ( var handler in events[ type ] ) { - jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); + if ( events ) { + delete curData.handle; + curData.events = {}; + + for ( var type in events ) { + for ( var handler in events[ type ] ) { + jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); + } } } }); } -function buildFragment(args, nodes, scripts){ +function buildFragment( args, nodes, scripts ) { var fragment, cacheable, cached, cacheresults, doc; if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf(" or - wrap[1] == "" && !hasBody ? + wrap[1] === "
" && !hasBody ? div.childNodes : []; @@ -476,7 +476,7 @@ jQuery.extend({ function cleanData( elems ) { for ( var i = 0, elem, id; (elem = elems[i]) != null; i++ ) { - if ( (id = elem[expando]) ) { + if ( !jQuery.noData[elem.nodeName.toLowerCase()] && (id = elem[expando]) ) { delete jQuery.cache[ id ]; } }