Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Manipulation: Add support for scripts with module type
- Loading branch information
|
@@ -3,12 +3,26 @@ define( [ |
|
|
], function( document ) { |
|
|
"use strict"; |
|
|
|
|
|
function DOMEval( code, doc ) { |
|
|
var preservedScriptAttributes = { |
|
|
type: true, |
|
|
src: true, |
|
|
noModule: true |
|
|
}; |
|
|
|
|
|
function DOMEval( code, doc, node ) { |
|
|
doc = doc || document; |
|
|
|
|
|
var script = doc.createElement( "script" ); |
|
|
var i, |
|
|
script = doc.createElement( "script" ); |
|
|
|
|
|
script.text = code; |
|
|
if ( node ) { |
|
|
for ( i in preservedScriptAttributes ) { |
|
|
if ( node[ i ] ) { |
|
|
script[ i ] = node[ i ]; |
|
|
} |
|
|
} |
|
|
} |
|
|
doc.head.appendChild( script ).parentNode.removeChild( script ); |
|
|
} |
|
|
|
|
|
|
@@ -194,14 +194,14 @@ function domManip( collection, args, callback, ignored ) { |
|
|
!dataPriv.access( node, "globalEval" ) && |
|
|
jQuery.contains( doc, node ) ) { |
|
|
|
|
|
if ( node.src ) { |
|
|
if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) { |
|
|
|
|
|
// Optional AJAX dependency, but won't run scripts if not present |
|
|
if ( jQuery._evalUrl ) { |
|
|
jQuery._evalUrl( node.src ); |
|
|
} |
|
|
} else { |
|
|
DOMEval( node.textContent.replace( rcleanScript, "" ), doc ); |
|
|
DOMEval( node.textContent.replace( rcleanScript, "" ), doc, node ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
@@ -1,5 +1,5 @@ |
|
|
define( function() { |
|
|
"use strict"; |
|
|
|
|
|
return ( /^$|\/(?:java|ecma)script/i ); |
|
|
return ( /^$|^module$|\/(?:java|ecma)script/i ); |
|
|
} ); |
|
|
@@ -0,0 +1 @@ |
|
|
window.ok( true, "evaluated: innert module with src" ); |
|
|
@@ -0,0 +1 @@ |
|
|
window.ok( true, "evaluated: module with src" ); |
|
@@ -1797,6 +1797,22 @@ QUnit.test( "html(Function)", function( assert ) { |
|
|
testHtml( manipulationFunctionReturningObj, assert ); |
|
|
} ); |
|
|
|
|
|
QUnit.test( "html(script type module)", function( assert ) { |
|
|
assert.expect( 1 ); |
|
|
var fixture = jQuery( "#qunit-fixture" ), |
|
|
tmp = fixture.html( |
|
|
[ |
|
|
"<script type='module'>ok( true, 'evaluated: module' );</script>", |
|
|
"<script type='module' src='./data/module.js'></script>", |
|
|
"<div>", |
|
|
"<script type='module'>ok( true, 'evaluated: inner module' );</script>", |
|
|
"<script type='module' src='./data/inner_module.js'></script>", |
|
|
"</div>" |
|
|
].join( "" ) |
|
|
).find( "script" ); |
|
|
assert.equal( tmp.length, 4, "All script tags remain." ); |
|
|
} ); |
|
|
|
|
|
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) { |
|
|
|
|
|
assert.expect( 4 ); |
|
|