NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@tinymce/tinymce-vue/lib/es2015/ScriptLoader.js
2023-09-14 14:47:11 +08:00

40 lines
1.1 KiB
Java

/**
* Copyright (c) 2018-present, Ephox, Inc.
*
* This source code is licensed under the Apache 2 license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { uuid } from './Utils';
var injectScriptTag = function (scriptId, doc, url, callback) {
var scriptTag = doc.createElement('script');
scriptTag.type = 'application/javascript';
scriptTag.id = scriptId;
scriptTag.addEventListener('load', callback);
scriptTag.src = url;
if (doc.head) {
doc.head.appendChild(scriptTag);
}
};
export var create = function () {
return {
listeners: [],
scriptId: uuid('tiny-script'),
scriptLoaded: false
};
};
export var load = function (state, doc, url, callback) {
if (state.scriptLoaded) {
callback();
}
else {
state.listeners.push(callback);
if (!doc.getElementById(state.scriptId)) {
injectScriptTag(state.scriptId, doc, url, function () {
state.listeners.forEach(function (fn) { return fn(); });
state.scriptLoaded = true;
});
}
}
};