Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes a fail in unit/traversing. Use an iframe's document for creatin…

…g the html5 fragment when necessary.
  • Loading branch information...
commit 649823de18564774a5812ae04083606447bd2b93 1 parent 51fd459
@timmywil timmywil authored
Showing with 25 additions and 17 deletions.
  1. +25 −17 src/manipulation.js
View
42 src/manipulation.js
@@ -22,22 +22,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
area: [ 1, "<map>", "</map>" ],
_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 );
Please sign in to comment.
Something went wrong with that request. Please try again.