From 649823de18564774a5812ae04083606447bd2b93 Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 28 Sep 2011 10:06:29 -0400 Subject: [PATCH] Fixes a fail in unit/traversing. Use an iframe's document for creating the html5 fragment when necessary. --- src/manipulation.js | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 8b0af08a9..bf0b8e10e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -22,22 +22,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, area: [ 1, "", "" ], _default: [ 0, "", "" ] }, - safeFragment = (function() { - var nodeNames = ( - "abbr article aside audio canvas datalist details figcaption figure footer " + - "header hgroup mark meter nav output progress section summary time video" - ).split( " " ), - safeFrag = document.createDocumentFragment(); - - if ( safeFrag.createElement ) { - while ( nodeNames.length ) { - safeFrag.createElement( - nodeNames.pop() - ); - } - } - return safeFrag; - })(); + safeFragment = createSafeFragment( document ); wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; @@ -643,7 +628,13 @@ jQuery.extend({ div = context.createElement("div"); // Append wrapper element to unknown element safe doc fragment - safeFragment.appendChild( div ); + if ( context === document ) { + // Use the fragment we've already created for this document + safeFragment.appendChild( div ); + } else { + // Use a fragment created with the owner document + createSafeFragment( context ).appendChild( div ); + } // Go to html and back, then peel off extra wrappers div.innerHTML = wrap[1] + elem + wrap[2]; @@ -786,4 +777,21 @@ function evalScript( i, elem ) { } } +function createSafeFragment( document ) { + var nodeNames = ( + "abbr article aside audio canvas datalist details figcaption figure footer " + + "header hgroup mark meter nav output progress section summary time video" + ).split( " " ), + safeFrag = document.createDocumentFragment(); + + if ( safeFrag.createElement ) { + while ( nodeNames.length ) { + safeFrag.createElement( + nodeNames.pop() + ); + } + } + return safeFrag; +} + })( jQuery ); -- 2.39.5