"use strict"; /** * 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. * */ Object.defineProperty(exports, "__esModule", { value: true }); var Utils_1 = require("./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); } }; exports.create = function () { return { listeners: [], scriptId: Utils_1.uuid('tiny-script'), scriptLoaded: false }; }; exports.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; }); } } };