Browse Source

Remove custom render from ComponentScriptView

pull/5606/head
Artur Arseniev 3 years ago
parent
commit
16dfe11108
  1. 14
      src/dom_components/model/ComponentScript.ts
  2. 36
      src/dom_components/view/ComponentScriptView.ts

14
src/dom_components/model/ComponentScript.ts

@ -13,19 +13,11 @@ export default class ComponentScript extends Component {
droppable: false, droppable: false,
draggable: false, draggable: false,
layerable: false, layerable: false,
highlightable: false,
}; };
} }
static isComponent(el: HTMLImageElement) { static isComponent(el: HTMLScriptElement) {
if (toLowerCase(el.tagName) == type) { return toLowerCase(el.tagName) === type;
const result: any = { type };
if (el.src) {
result.src = el.src;
result.onload = el.onload;
}
return result;
}
} }
} }

36
src/dom_components/view/ComponentScriptView.ts

@ -8,40 +8,4 @@ export default class ComponentScriptView extends ComponentView {
events() { events() {
return {}; return {};
} }
render() {
this.renderAttributes();
const { model, em } = this;
const src = model.get('src');
const scrCnt = em && em.get('scriptCount');
const scriptCount = scrCnt ? scrCnt : 0;
let content = '';
// If it's an external script
if (src) {
const onload = model.get('onload');
const svar = `script${scriptCount}`;
const svarNext = `script${scriptCount + 1}`;
const svarFn = `${svar}Start`;
const svarNextFn = `${svarNext}Start`;
// Load multiple external scripts in the correct order
content = `
var ${svar} = document.createElement('script');
${svar}.onload = function() {
${onload ? `${onload}();\n` : ''}
typeof ${svarNextFn} == 'function' && ${svarNextFn}();
};
${svar}.src = '${src}';
function ${svarFn}() { document.body.appendChild(${svar}); };
${!scriptCount ? `${svarFn}();` : ''}
`;
em && em.set('scriptCount', scriptCount + 1);
} else {
content = model.__innerHTML()!;
}
this.el.innerHTML = content;
this.postRender();
return this;
}
} }

Loading…
Cancel
Save