diff options
author | Colin Snover <github.com@zetafleet.com> | 2011-01-28 10:55:39 -0600 |
---|---|---|
committer | Colin Snover <github.com@zetafleet.com> | 2011-01-28 10:55:39 -0600 |
commit | 0a0cff9d29c4bd559da689d96c532d06c03fce09 (patch) | |
tree | 489e079c3625d15c7e8adac2bbcd2268f0474d8b /src/manipulation.js | |
parent | bbd3f4f3fe66fc4ce6c6db31a17a1c04037323be (diff) | |
download | jquery-0a0cff9d29c4bd559da689d96c532d06c03fce09.tar.gz jquery-0a0cff9d29c4bd559da689d96c532d06c03fce09.zip |
Use the original element/fragment as the last item to be appended to the document instead of the first in order to prevent missing elements when appending to multiple elements. Fixes #8070.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r-- | src/manipulation.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index b7f2d3e43..442a14d29 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -186,7 +186,7 @@ jQuery.fn.extend({ clone: function( dataAndEvents, deepDataAndEvents ) { dataAndEvents = dataAndEvents == null ? true : dataAndEvents; deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; - + return this.map( function () { return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); }); @@ -311,12 +311,19 @@ jQuery.fn.extend({ if ( first ) { table = table && jQuery.nodeName( first, "tr" ); - for ( var i = 0, l = this.length; i < l; i++ ) { + for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) { callback.call( table ? root(this[i], first) : this[i], - i > 0 || results.cacheable || (this.length > 1 && i > 0) ? + // Make sure that we do not leak memory by inadvertently discarding + // the original fragment (which might have attached data) instead of + // using it; in addition, use the original fragment object for the last + // item instead of first because it can end up being emptied incorrectly + // in certain situations (Bug #8070). + // Fragments from the fragment cache must always be cloned and never used + // in place. + results.cacheable || (l > 1 && i < lastIndex) ? jQuery.clone( fragment, true, true ) : fragment ); @@ -484,9 +491,9 @@ jQuery.each({ jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { - var clone = elem.cloneNode(true), - srcElements, - destElements, + var clone = elem.cloneNode(true), + srcElements, + destElements, i; if ( !jQuery.support.noCloneEvent && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { |