From: Oleg Date: Tue, 17 Apr 2012 01:57:41 +0000 (-0400) Subject: Fix #8894. Ensure `.appendTo` creates a new set in oldIE. X-Git-Tag: 1.8b1~201 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=abd2a07498afa48a4ec3ce0471b9b0b4fc812b55;p=jquery.git Fix #8894. Ensure `.appendTo` creates a new set in oldIE. --- diff --git a/src/core.js b/src/core.js index 193dc1b34..4e38deaeb 100644 --- a/src/core.js +++ b/src/core.js @@ -801,7 +801,7 @@ jQuery.extend({ return proxy; }, - // Mutifunctional method to get and set values to a collection + // Multifunctional method to get and set values of a collection // The value/s can optionally be executed if it's a function access: function( elems, fn, key, value, chainable, emptyGet, pass ) { var exec, diff --git a/src/manipulation.js b/src/manipulation.js index da4f475b5..cc6acee82 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -40,7 +40,8 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca area: [ 1, "", "" ], _default: [ 0, "", "" ] }, - safeFragment = createSafeFragment( document ); + safeFragment = createSafeFragment( document ), + fragmentDiv = safeFragment.appendChild( document.createElement("div") ); wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; @@ -529,7 +530,7 @@ jQuery.each({ insert = jQuery( selector ), parent = this.length === 1 && this[0].parentNode; - if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) { + if ( (parent == null || parent && parent.nodeType === 11 && parent.childNodes.length === 1) && insert.length === 1 ) { insert[ original ]( this[0] ); return this; } else { @@ -563,24 +564,21 @@ function fixDefaultChecked( elem ) { } } -// Derived From: http://www.iecss.com/shimprove/javascript/shimprove.1-0-1.js -function shimCloneNode( elem ) { - var div = document.createElement( "div" ); - safeFragment.appendChild( div ); - - div.innerHTML = elem.outerHTML; - return div.firstChild; -} - jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { var srcElements, destElements, i, - // IE<=8 does not properly clone detached, unknown element nodes - clone = jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ? - elem.cloneNode( true ) : - shimCloneNode( elem ); + clone; + + if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { + clone = elem.cloneNode( true ); + + // IE<=8 does not properly clone detached, unknown element nodes + } else { + fragmentDiv.innerHTML = elem.outerHTML; + fragmentDiv.removeChild( clone = fragmentDiv.firstChild ); + } if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 4aae3e28e..672b204e1 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -571,7 +571,7 @@ test("IE8 serialization bug", function () { test("html() object element #10324", function() { expect( 1 ); - var object = jQuery("​").appendTo("#qunit-fixture"), + var object = jQuery("?").appendTo("#qunit-fixture"), clone = object.clone(); equal( clone.html(), object.html(), "html() returns correct innerhtml of cloned object elements" ); @@ -1776,3 +1776,11 @@ test("Guard against exceptions when clearing safeChildNodes", function() { ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" ); }); + +test("Ensure oldIE creates a new set on appendTo (#8894)", function() { + strictEqual( jQuery("
").clone().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); + strictEqual( jQuery("
").find("p").end().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); + strictEqual( jQuery("
").text("test").addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); + strictEqual( jQuery("").clone().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); + strictEqual( jQuery("

").appendTo("

").end().length, jQuery("

test

").appendTo("
").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); +});