break;
case 'scriptUrl':
- if (!$allowCmsOverride || !$cms->addScriptUrl($snippet['scriptUrl'], $this->_name)) {
+ if (!empty($snippet['esm'])) {
+ $html .= sprintf("<script type=\"module\" src=\"%s\">\n</script>\n", $snippet['scriptUrl']);
+ }
+ elseif (!$allowCmsOverride || !$cms->addScriptUrl($snippet['scriptUrl'], $this->_name)) {
$html .= sprintf("<script type=\"text/javascript\" src=\"%s\">\n</script>\n", $snippet['scriptUrl']);
}
break;
break;
case 'script':
- if (!$allowCmsOverride || !$cms->addScript($snippet['script'], $this->_name)) {
+ if (!empty($snippet['esm'])) {
+ $html .= sprintf("<script type=\"module\">\n%s\n</script>\n", $snippet['script']);
+ }
+ elseif (!$allowCmsOverride || !$cms->addScript($snippet['script'], $this->_name)) {
$html .= sprintf("<script type=\"text/javascript\">\n%s\n</script>\n", $snippet['script']);
}
break;
* not guaranteed among versions/implementations.)
* - disabled: int, default=0
* - region: string
+ * - esm: bool; for "script","scriptFile","scriptUrl", the "esm" flag enables Ecmascript 5 Module support
* - translate: bool|string, Autoload translations. (Only applies to 'scriptFile')
* - FALSE: Do not load translated strings.
* - TRUE: Load translated strings. Use the $ext's default domain.
CRM_Core_Region::instance('testAllTypes')->add([
'jquery' => '$("div");',
]);
+ CRM_Core_Region::instance('testAllTypes')->add([
+ 'scriptUrl' => '/my%20module.mjs',
+ 'esm' => TRUE,
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
+ 'script' => 'import foo from "./foobar.mjs";',
+ 'esm' => TRUE,
+ ]);
CRM_Core_Region::instance('testAllTypes')->add([
'styleUrl' => '/foo%20bar.css',
]);
. "<script type=\"text/javascript\" src=\"/foo%20bar.js\">\n</script>\n"
. "<script type=\"text/javascript\">\nalert(\"hi\");\n</script>\n"
. "<script type=\"text/javascript\">\nCRM.\$(function(\$) {\n\$(\"div\");\n});\n</script>\n"
+ . "<script type=\"module\" src=\"/my%20module.mjs\">\n</script>\n"
+ . "<script type=\"module\">\nimport foo from \"./foobar.mjs\";\n</script>\n"
. "<link href=\"/foo%20bar.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
. "<style type=\"text/css\">\nbody { background: black; }\n</style>\n";
$this->assertEquals($expected, $actual);