snappymail/dev/Component/Script.js

32 lines
798 B
JavaScript
Raw Normal View History

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 &&
params.element
2019-07-05 03:19:24 +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) {
const koNodes = params.component.templateNodes[0];
el.textContent = '';
el.replaceWith(
Element.fromHTML(script).textContent = koNodes && koNodes.nodeValue ? koNodes.nodeValue : ''
);
2019-07-05 03:19:24 +08:00
} else {
el.remove();
2015-11-15 08:23:16 +08:00
}
}
}
}
2017-03-01 02:44:13 +08:00
export default componentExportHelper(ScriptComponent, 'ScriptComponent');