2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractComponent, componentExportHelper } from 'Component/Abstract';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class ScriptComponent extends AbstractComponent {
|
2015-11-15 08:23:16 +08:00
|
|
|
/**
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
constructor(params) {
|
|
|
|
super();
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (
|
|
|
|
params.component &&
|
|
|
|
params.component.templateNodes &&
|
2020-08-31 18:45:43 +08:00
|
|
|
params.element
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2020-08-31 18:45:43 +08:00
|
|
|
let el = params.element, script = el.outerHTML;
|
|
|
|
script = script ? script.replace(/<x-script/i, '<script').replace(/<b><\/b><\/x-script>/i, '</script>') : '';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (script) {
|
2020-08-31 18:45:43 +08:00
|
|
|
const koNodes = params.component.templateNodes[0];
|
|
|
|
el.textContent = '';
|
|
|
|
el.replaceWith(
|
|
|
|
Element.fromHTML(script).textContent = koNodes && koNodes.nodeValue ? koNodes.nodeValue : ''
|
2017-06-25 03:26:27 +08:00
|
|
|
);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-08-31 18:45:43 +08:00
|
|
|
el.remove();
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 02:44:13 +08:00
|
|
|
export default componentExportHelper(ScriptComponent, 'ScriptComponent');
|