Skip to content
Permalink
Browse files

Fix #8894. Ensure `.appendTo` creates a new set in oldIE.

  • Loading branch information...
markelog authored and dmethvin committed Apr 17, 2012
1 parent 8fadc5b commit abd2a07498afa48a4ec3ce0471b9b0b4fc812b55
Showing with 23 additions and 17 deletions.
  1. +1 −1 src/core.js
  2. +13 −15 src/manipulation.js
  3. +9 −1 test/unit/manipulation.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,
@@ -40,7 +40,8 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca
area: [ 1, "<map>", "</map>" ],
_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) ) {
@@ -571,7 +571,7 @@ test("IE8 serialization bug", function () {
test("html() object element #10324", function() {
expect( 1 );

var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>").appendTo("#qunit-fixture"),
var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>?").appendTo("#qunit-fixture"),

This comment has been minimized.

Copy link
@Krinkle

Krinkle Apr 20, 2012

Member

Was this intentional?

This comment has been minimized.

Copy link
@markelog

markelog Apr 20, 2012

Author Member

No. I don't see it in my pull. I guess its rebase artefact, but Its a test, it did not break, so who cares? I'm sure it will be corrected later.

This comment has been minimized.

Copy link
@dmethvin

dmethvin Apr 20, 2012

Member

Must have been a keyboard spasm on my part. Stray text outside elements in $() is ignored which explains why it has no effect. I will clean it up on the next commit in this area. Thanks for keeping an eye open!

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("<div/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" );
strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" );
strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" );
strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" );
strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
});

0 comments on commit abd2a07

Please sign in to comment.
You can’t perform that action at this time.