2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
import $ from '$';
|
2015-11-15 08:23:16 +08:00
|
|
|
import {AbstractComponent, componentExportHelper} from 'Component/Abstract';
|
|
|
|
|
|
|
|
class ScriptComponent extends AbstractComponent
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
constructor(params) {
|
|
|
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
if (params.component && params.component.templateNodes && params.element &&
|
|
|
|
params.element[0] && params.element[0].outerHTML)
|
|
|
|
{
|
|
|
|
let script = params.element[0].outerHTML;
|
2015-11-19 01:32:29 +08:00
|
|
|
script = !script ? '' : script
|
2015-11-15 08:23:16 +08:00
|
|
|
.replace(/<x-script/i, '<script')
|
2016-06-30 08:02:45 +08:00
|
|
|
.replace(/<b><\/b><\/x-script>/i, '</script>');
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
if (script)
|
|
|
|
{
|
|
|
|
params.element.text('');
|
|
|
|
params.element.replaceWith(
|
|
|
|
$(script).text(params.component.templateNodes[0] &&
|
|
|
|
params.component.templateNodes[0].nodeValue ?
|
|
|
|
params.component.templateNodes[0].nodeValue : ''));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params.element.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = componentExportHelper(ScriptComponent, 'ScriptComponent');
|