UNPKG

zj-element

Version:

基于ElementUI的VUE组件——Жидзин(Zidjin)系列组件库。

43 lines (36 loc) 1.27 kB
let callbacks = []; export default function (id, src, func) { // eslint-disable-next-line @typescript-eslint/no-empty-function const callback = func || function () {}; const isExisting = document.getElementById(id); if (!isExisting) { const script = document.createElement('script'); script.src = src; script.id = id; document.body.appendChild(script); callbacks.push(callback); 'onload' in script ? renderBrower(script) : renderIEBrower(script); } if (isExisting && callback) { window.tinymce ? callback(null, isExisting) : callbacks.push(callback); } function renderIEBrower(script) { script.onreadystatechange = function () { if (this.readyState !== 'complete' && this.readyState !== 'loaded') return; this.onreadystatechange = null; callbacks.forEach((func) => func(null, script)); callbacks = []; }; } function renderBrower(script) { script.onload = function () { this.onerror = this.onload = null; callbacks.forEach((func) => func(null, script)); callbacks = []; }; script.onerror = function () { this.onerror = this.onload = null; callback(new Error('Failed to load ' + src), script); }; } }