diff options
author | Oleg <markelog@gmail.com> | 2013-01-09 13:52:15 +0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2013-01-11 13:00:37 -0500 |
commit | 8b82af9ef25806a3ed8fe7e5bab92ef5f7f13ef7 (patch) | |
tree | f56c7e8073a3934ff3ab5e0caeb8090a4b3bb06f /src | |
parent | f40eac1d3719be200bea8e62cc73d49fc37b062f (diff) | |
download | jquery-8b82af9ef25806a3ed8fe7e5bab92ef5f7f13ef7.tar.gz jquery-8b82af9ef25806a3ed8fe7e5bab92ef5f7f13ef7.zip |
Ref 0ed497b. Close gh-1125.
Diffstat (limited to 'src')
-rw-r--r-- | src/manipulation.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index ce05fd63c..984f80307 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -33,7 +33,7 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca legend: [ 1, "<fieldset>" ], area: [ 1, "<map>" ], param: [ 1, "<object>" ], - thead: [ 1, "<table>" ], + thead: [ 1, "<table>" ], tr: [ 2, "<table><tbody>" ], col: [ 2, "<table><tbody></tbody><colgroup>", "</table>" ], td: [ 3, "<table><tbody><tr>" ], @@ -308,9 +308,8 @@ jQuery.fn.extend({ }); } - if ( this[0] ) { - doc = this[0].ownerDocument; - fragment = jQuery.buildFragment( args, doc, false, this ); + if ( l ) { + fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this ); first = fragment.firstChild; if ( fragment.childNodes.length === 1 ) { @@ -619,21 +618,20 @@ jQuery.extend({ }, buildFragment: function( elems, context, scripts, selection ) { - var elem, j, tmp, tag, wrap, tbody, - nodes = [], - i = 0, + var contains, elem, tag, tmp, wrap, tbody, j, l = elems.length, - fragment = context.createDocumentFragment(), - safe = context === document && safeFragment; - // Ensure that context is a document - if ( !context || typeof context.createDocumentFragment === "undefined" ) { - context = document; - } + // Ensure a safe fragment + safe = createSafeFragment( context ), + + nodes = [], + i = 0; for ( ; i < l; i++ ) { elem = elems[ i ]; + if ( elem || elem === 0 ) { + // Add nodes directly if ( jQuery.type( elem ) === "object" ) { jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); @@ -644,8 +642,6 @@ jQuery.extend({ // Convert html into DOM nodes } else { - // Ensure a safe container - safe = safe || createSafeFragment( context ); tmp = tmp || safe.appendChild( context.createElement("div") ); // Deserialize a standard representation @@ -700,7 +696,7 @@ jQuery.extend({ } } - // Fix #11356: Clear elements from safeFragment + // Fix #11356: Clear elements from fragment if ( tmp ) { safe.removeChild( tmp ); } @@ -713,18 +709,20 @@ jQuery.extend({ i = 0; while ( (elem = nodes[ i++ ]) ) { - safe = jQuery.contains( elem.ownerDocument, elem ); - // Append to fragment // #4087 - If origin and destination elements are the same, and this is - // that element, do not append to fragment - if ( !selection || jQuery.inArray( elem, selection ) === -1 ) { - fragment.appendChild( elem ); + // that element, do not do anything + if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { + continue; } - tmp = getAll( elem, "script" ); + + contains = jQuery.contains( elem.ownerDocument, elem ); + + // Append to fragment + tmp = getAll( safe.appendChild( elem ), "script" ); // Preserve script evaluation history - if ( safe ) { + if ( contains ) { setGlobalEval( tmp ); } @@ -739,9 +737,9 @@ jQuery.extend({ } } - elem = tmp = safe = null; + tmp = null; - return fragment; + return safe; }, cleanData: function( elems, /* internal */ acceptData ) { |