snappymail/dev/Component/Script.js

38 lines
925 B
JavaScript
Raw Normal View History

2016-07-02 06:49:59 +08:00
import $ from '$';
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 &&
params.element[0] &&
params.element[0].outerHTML
) {
2015-11-15 08:23:16 +08:00
let script = params.element[0].outerHTML;
2019-07-05 03:19:24 +08:00
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) {
2015-11-15 08:23:16 +08:00
params.element.text('');
params.element.replaceWith(
$(script).text(
2019-07-05 03:19:24 +08:00
params.component.templateNodes[0] && params.component.templateNodes[0].nodeValue
? params.component.templateNodes[0].nodeValue
: ''
)
);
2019-07-05 03:19:24 +08:00
} else {
2015-11-15 08:23:16 +08:00
params.element.remove();
}
}
}
}
2017-03-01 02:44:13 +08:00
export default componentExportHelper(ScriptComponent, 'ScriptComponent');