mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Core: introduce createHTMLDocument in parseHTML; Safari 8/IE8 left out
Close gh-1506
This commit is contained in:
parent
51564bbd39
commit
828a718aa0
@ -1,8 +1,13 @@
|
|||||||
define([
|
define([
|
||||||
"../core",
|
"../core",
|
||||||
"./var/rsingleTag",
|
"./var/rsingleTag",
|
||||||
"../manipulation" // buildFragment
|
|
||||||
], function( jQuery, rsingleTag ) {
|
// This is the only module that needs core/support
|
||||||
|
"./support",
|
||||||
|
|
||||||
|
// buildFragment
|
||||||
|
"../manipulation"
|
||||||
|
], function( jQuery, rsingleTag, support ) {
|
||||||
|
|
||||||
// data: string of html
|
// data: string of html
|
||||||
// context (optional): If specified, the fragment will be created in this context,
|
// context (optional): If specified, the fragment will be created in this context,
|
||||||
@ -16,7 +21,11 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
|
|||||||
keepScripts = context;
|
keepScripts = context;
|
||||||
context = false;
|
context = false;
|
||||||
}
|
}
|
||||||
context = context || document;
|
// document.implementation stops scripts or inline event handlers from
|
||||||
|
// being executed immediately
|
||||||
|
context = context || ( support.createHTMLDocument ?
|
||||||
|
document.implementation.createHTMLDocument( "" ) :
|
||||||
|
document );
|
||||||
|
|
||||||
var parsed = rsingleTag.exec( data ),
|
var parsed = rsingleTag.exec( data ),
|
||||||
scripts = !keepScripts && [];
|
scripts = !keepScripts && [];
|
||||||
|
15
src/core/support.js
Normal file
15
src/core/support.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
define([
|
||||||
|
"../var/support"
|
||||||
|
], function( support ) {
|
||||||
|
|
||||||
|
support.createHTMLDocument = (function() {
|
||||||
|
if ( !document.implementation.createHTMLDocument ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var doc = document.implementation.createHTMLDocument( "" );
|
||||||
|
doc.body.innerHTML = "<form></form><form></form>";
|
||||||
|
return doc.body.childNodes.length === 2;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return support;
|
||||||
|
});
|
@ -1348,6 +1348,22 @@ test("jQuery.parseHTML", function() {
|
|||||||
equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
|
equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ( jQuery.support.createHTMLDocument ) {
|
||||||
|
asyncTest("jQuery.parseHTML", function() {
|
||||||
|
expect ( 1 );
|
||||||
|
|
||||||
|
Globals.register("parseHTMLError");
|
||||||
|
|
||||||
|
jQuery.globalEval("parseHTMLError = false;");
|
||||||
|
jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" );
|
||||||
|
|
||||||
|
window.setTimeout(function() {
|
||||||
|
start();
|
||||||
|
equal( window.parseHTMLError, false, "onerror eventhandler has not been called." );
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test("jQuery.parseJSON", function() {
|
test("jQuery.parseJSON", function() {
|
||||||
expect( 20 );
|
expect( 20 );
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
@ -108,6 +109,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": false,
|
"clearCloneStyle": false,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": true,
|
"focusinBubbles": true,
|
||||||
@ -137,6 +139,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": false,
|
"clearCloneStyle": false,
|
||||||
"cors": false,
|
"cors": false,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": true,
|
"focusinBubbles": true,
|
||||||
@ -166,6 +169,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": false,
|
"cors": false,
|
||||||
|
"createHTMLDocument": false,
|
||||||
"cssFloat": false,
|
"cssFloat": false,
|
||||||
"deleteExpando": false,
|
"deleteExpando": false,
|
||||||
"focusinBubbles": true,
|
"focusinBubbles": true,
|
||||||
@ -186,7 +190,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"style": false,
|
"style": false,
|
||||||
"submitBubbles": false
|
"submitBubbles": false
|
||||||
};
|
};
|
||||||
} else if ( /(6|7|8)\.0(\.\d+|) safari/i.test( userAgent ) ) {
|
} else if ( /(6|7)\.0(\.\d+|) safari/i.test( userAgent ) ) {
|
||||||
expected = {
|
expected = {
|
||||||
"ajax": true,
|
"ajax": true,
|
||||||
"boxSizingReliable": true,
|
"boxSizingReliable": true,
|
||||||
@ -195,6 +199,37 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
|
"cssFloat": true,
|
||||||
|
"deleteExpando": true,
|
||||||
|
"focusinBubbles": false,
|
||||||
|
"html5Clone": true,
|
||||||
|
"htmlSerialize": true,
|
||||||
|
"input": true,
|
||||||
|
"leadingWhitespace": true,
|
||||||
|
"noCloneChecked": true,
|
||||||
|
"noCloneEvent": true,
|
||||||
|
"opacity": true,
|
||||||
|
"optDisabled": true,
|
||||||
|
"optSelected": true,
|
||||||
|
"ownLast": false,
|
||||||
|
"pixelPosition": false,
|
||||||
|
"radioValue": true,
|
||||||
|
"reliableHiddenOffsets": true,
|
||||||
|
"reliableMarginRight": true,
|
||||||
|
"style": true,
|
||||||
|
"submitBubbles": true
|
||||||
|
};
|
||||||
|
} else if ( /8.0(\.\d+|) safari/i.test( userAgent ) ) {
|
||||||
|
expected = {
|
||||||
|
"ajax": true,
|
||||||
|
"boxSizingReliable": true,
|
||||||
|
"changeBubbles": true,
|
||||||
|
"checkClone": true,
|
||||||
|
"checkOn": true,
|
||||||
|
"clearCloneStyle": true,
|
||||||
|
"cors": true,
|
||||||
|
"createHTMLDocument": false,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
@ -224,6 +259,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
@ -253,6 +289,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": true,
|
"checkOn": true,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
@ -282,6 +319,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": false,
|
"checkOn": false,
|
||||||
"clearCloneStyle": true,
|
"clearCloneStyle": true,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
@ -311,6 +349,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
|
|||||||
"checkOn": false,
|
"checkOn": false,
|
||||||
"clearCloneStyle": false,
|
"clearCloneStyle": false,
|
||||||
"cors": true,
|
"cors": true,
|
||||||
|
"createHTMLDocument": true,
|
||||||
"cssFloat": true,
|
"cssFloat": true,
|
||||||
"deleteExpando": true,
|
"deleteExpando": true,
|
||||||
"focusinBubbles": false,
|
"focusinBubbles": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user