mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Manipulation: Add support for scripts with module type
Fixes gh-3871 Close gh-3869
This commit is contained in:
parent
428ee4a624
commit
5d3a968e03
@ -3,12 +3,26 @@ define( [
|
|||||||
], function( document ) {
|
], function( document ) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function DOMEval( code, doc ) {
|
var preservedScriptAttributes = {
|
||||||
|
type: true,
|
||||||
|
src: true,
|
||||||
|
noModule: true
|
||||||
|
};
|
||||||
|
|
||||||
|
function DOMEval( code, doc, node ) {
|
||||||
doc = doc || document;
|
doc = doc || document;
|
||||||
|
|
||||||
var script = doc.createElement( "script" );
|
var i,
|
||||||
|
script = doc.createElement( "script" );
|
||||||
|
|
||||||
script.text = code;
|
script.text = code;
|
||||||
|
if ( node ) {
|
||||||
|
for ( i in preservedScriptAttributes ) {
|
||||||
|
if ( node[ i ] ) {
|
||||||
|
script[ i ] = node[ i ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
doc.head.appendChild( script ).parentNode.removeChild( script );
|
doc.head.appendChild( script ).parentNode.removeChild( script );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +194,14 @@ function domManip( collection, args, callback, ignored ) {
|
|||||||
!dataPriv.access( node, "globalEval" ) &&
|
!dataPriv.access( node, "globalEval" ) &&
|
||||||
jQuery.contains( doc, node ) ) {
|
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
|
// Optional AJAX dependency, but won't run scripts if not present
|
||||||
if ( jQuery._evalUrl ) {
|
if ( jQuery._evalUrl ) {
|
||||||
jQuery._evalUrl( node.src );
|
jQuery._evalUrl( node.src );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
|
DOMEval( node.textContent.replace( rcleanScript, "" ), doc, node );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
define( function() {
|
define( function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
return ( /^$|\/(?:java|ecma)script/i );
|
return ( /^$|^module$|\/(?:java|ecma)script/i );
|
||||||
} );
|
} );
|
||||||
|
1
test/data/inner_module.js
Normal file
1
test/data/inner_module.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
window.ok( true, "evaluated: innert module with src" );
|
1
test/data/module.js
Normal file
1
test/data/module.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
window.ok( true, "evaluated: module with src" );
|
@ -1797,6 +1797,22 @@ QUnit.test( "html(Function)", function( assert ) {
|
|||||||
testHtml( manipulationFunctionReturningObj, 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 ) {
|
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
|
||||||
|
|
||||||
assert.expect( 4 );
|
assert.expect( 4 );
|
||||||
|
Loading…
Reference in New Issue
Block a user