From ab2a70e6cfba19ec9140c3e393e8cdb60c537bdb Mon Sep 17 00:00:00 2001 From: Anton M Date: Sun, 21 Nov 2010 01:58:46 +0100 Subject: [PATCH] Make sure IE clones body elements correctly. Fixes 4386. --- src/manipulation.js | 5 ++++- test/unit/manipulation.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index d8fa020..e09dd7e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -10,6 +10,8 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, // checked="checked" or checked (html5) rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, raction = /\=([^="'>\s]+\/)>/g, + rbodystart = /^\s*\s*$/i, wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], @@ -198,11 +200,12 @@ jQuery.fn.extend({ // the name attribute on an input). var html = this.outerHTML, ownerDocument = this.ownerDocument; - if ( !html ) { var div = ownerDocument.createElement("div"); div.appendChild( this.cloneNode(true) ); html = div.innerHTML; + } else if ( rbodystart.test(html) && rbodyend.test(html) ) { + html = html.replace( rbodystart, "
" ).replace( rbodyend, "
" ); } return jQuery.clean([html.replace(rinlinejQuery, "") diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d4c4348..4805016 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -814,7 +814,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() { }); test("clone()", function() { - expect(31); + expect(32); equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' ); var clone = jQuery('#yahoo').clone(); equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' ); @@ -872,6 +872,8 @@ test("clone()", function() { form.appendChild( div ); equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); + + equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" ); }); if (!isLocal) { -- 1.7.10.4