mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-31 03:52:01 +08:00
31 lines
798 B
JavaScript
31 lines
798 B
JavaScript
import { AbstractComponent, componentExportHelper } from 'Component/Abstract';
|
|
|
|
class ScriptComponent extends AbstractComponent {
|
|
/**
|
|
* @param {Object} params
|
|
*/
|
|
constructor(params) {
|
|
super();
|
|
|
|
if (
|
|
params.component &&
|
|
params.component.templateNodes &&
|
|
params.element
|
|
) {
|
|
let el = params.element, script = el.outerHTML;
|
|
script = script ? script.replace(/<x-script/i, '<script').replace(/<b><\/b><\/x-script>/i, '</script>') : '';
|
|
|
|
if (script) {
|
|
const koNodes = params.component.templateNodes[0];
|
|
el.textContent = '';
|
|
el.replaceWith(
|
|
Element.fromHTML(script).textContent = koNodes && koNodes.nodeValue ? koNodes.nodeValue : ''
|
|
);
|
|
} else {
|
|
el.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default componentExportHelper(ScriptComponent, 'ScriptComponent');
|