function requireUrl(url, global) {
        if (modules[url]) {
            // Module already loaded - resolve immediately.
            return Promise.resolve(modules[url]);
        }

        if (promiseCallbacks[url]) {
            // Module is already being loaded, return a promise that will complete when the in-progress load completes.
            return new Promise(function (resolve, reject) {
                promiseCallbacks[url].push([resolve, reject]);
            });
        }

        promiseCallbacks[url] = [];

        /**
         * Complete the loading of a script. Call the appropriate callbacks.
         *
         * @param {number} callback - 0 for the resolve callbacks, 1 for the reject callbacks.
         * @param {Object=} argument - the callback argument.
         * @returns {void}
         */
        function complete(callback, argument) {
            if (!promiseCallbacks[url]) {
                return;
            }
            promiseCallbacks[url].forEach(function(cbs) {
                cbs[callback](argument);
            });
            delete promiseCallbacks[url];
        }

        function resolveScript() {
            return complete(0, modules[url]);
        }

        function rejectScript() {
            return complete(1);
        }

        /** Script has finished loading.
         *
         * @param {Object=} callbackValue - the value delivered by a callback
         * @return {void}
         */
        function scriptLoaded(callbackValue) {
            if (defined) {
                var moduleDeps = depGraph[url] || {};
                var deps = defined[0];
                var factory = defined[1];
                defined = null;

                var dependencyPromises = deps.map(function(dep) {
                    var depUrl = relative(dep, url);
                    moduleDeps[depUrl] = 1;
                    return requireUrl(depUrl);
                });
                depGraph[url] = moduleDeps;
                if (findCycles(url)) {
                    rejectScript();
                    return;
                }
                Promise.all(dependencyPromises).then(function (loadedDeps) {
                    modules[url] = factory.apply(window, loadedDeps);
                    resolveScript();
                }).catch(rejectScript);
            } else {
                if (global) {
                    modules[url] = window[global];
                } else {
                    modules[url] = callbackValue || true;
                }
                resolveScript();
            }
        }

        return new Promise(function (resolve, reject) {
            promiseCallbacks[url].push([resolve, reject]);
            var useCallback = url.substr(-1) === '=';
            var src = url;
            var onload;
            if (useCallback) {
                // This module calls a callback.
                var callbackName = 'cb' + nextId;
                nextId++;
                window[callbackName] = scriptLoaded;
                src = url + callbackName;
            } else {
                onload = function(){
                    scriptLoaded();
                };
            }
            if (document) {
                var script = document.createElement('script');
                script.src = src;
                script.onload = onload;
                script.onerror = rejectScript;
                document.head.appendChild(script);
            } else {
                setTimeout(function() {
                    try {
                        importScripts(src);
                        if (onload) {
                            onload();
                        }
                    } catch (error) {
                        rejectScript();
                    }
                }, 1);
            }
        });
    }
/**
     * Load a module or script.
     *
     * @param {string} url - the url to the module or script
     * @param {string=} global - the name of the global variable that a non-module script declares
     * @returns {Promise} - a promise that will resolve or reject when the script has loaded or failed to load.
     */
Load a module or script.
@param {string} url - the url to the module or script
@param {string=} global - the name of the global variable that a non-module script declares
@returns {Promise} - a promise that will resolve or reject when the script has loaded or failed to load.
Load a module or script . @param { string } url - the url to the module or script @param { string = } global - the name of the global variable that a non - module script declares @returns { Promise } - a promise that will resolve or reject when the script has loaded or failed to load .
function requireUrl(url, global) {
        if (modules[url]) {
            return Promise.resolve(modules[url]);
        }
        if (promiseCallbacks[url]) {
            return new Promise(function (resolve, reject) {
                promiseCallbacks[url].push([resolve, reject]);
            });
        }
        promiseCallbacks[url] = [];
        function complete(callback, argument) {
            if (!promiseCallbacks[url]) {
                return;
            }
            promiseCallbacks[url].forEach(function(cbs) {
                cbs[callback](argument);
            });
            delete promiseCallbacks[url];
        }
        function resolveScript() {
            return complete(0, modules[url]);
        }
        function rejectScript() {
            return complete(1);
        }
        function scriptLoaded(callbackValue) {
            if (defined) {
                var moduleDeps = depGraph[url] || {};
                var deps = defined[0];
                var factory = defined[1];
                defined = null;
                var dependencyPromises = deps.map(function(dep) {
                    var depUrl = relative(dep, url);
                    moduleDeps[depUrl] = 1;
                    return requireUrl(depUrl);
                });
                depGraph[url] = moduleDeps;
                if (findCycles(url)) {
                    rejectScript();
                    return;
                }
                Promise.all(dependencyPromises).then(function (loadedDeps) {
                    modules[url] = factory.apply(window, loadedDeps);
                    resolveScript();
                }).catch(rejectScript);
            } else {
                if (global) {
                    modules[url] = window[global];
                } else {
                    modules[url] = callbackValue || true;
                }
                resolveScript();
            }
        }
        return new Promise(function (resolve, reject) {
            promiseCallbacks[url].push([resolve, reject]);
            var useCallback = url.substr(-1) === '=';
            var src = url;
            var onload;
            if (useCallback) {
                var callbackName = 'cb' + nextId;
                nextId++;
                window[callbackName] = scriptLoaded;
                src = url + callbackName;
            } else {
                onload = function(){
                    scriptLoaded();
                };
            }
            if (document) {
                var script = document.createElement('script');
                script.src = src;
                script.onload = onload;
                script.onerror = rejectScript;
                document.head.appendChild(script);
            } else {
                setTimeout(function() {
                    try {
                        importScripts(src);
                        if (onload) {
                            onload();
                        }
                    } catch (error) {
                        rejectScript();
                    }
                }, 1);
            }
        });
    }
function requireUrl ( url , global ) { if ( modules [ url ] ) { return Promise . resolve ( modules [ url ] ) ; } if ( promiseCallbacks [ url ] ) { return new Promise ( function ( resolve , reject ) { promiseCallbacks [ url ] . push ( [ resolve , reject ] ) ; } ) ; } promiseCallbacks [ url ] = [ ] ; function complete ( callback , argument ) { if ( ! promiseCallbacks [ url ] ) { return ; } promiseCallbacks [ url ] . forEach ( function ( cbs ) { cbs [ callback ] ( argument ) ; } ) ; delete promiseCallbacks [ url ] ; } function resolveScript ( ) { return complete ( 0 , modules [ url ] ) ; } function rejectScript ( ) { return complete ( 1 ) ; } function scriptLoaded ( callbackValue ) { if ( defined ) { var moduleDeps = depGraph [ url ] || { } ; var deps = defined [ 0 ] ; var factory = defined [ 1 ] ; defined = null ; var dependencyPromises = deps . map ( function ( dep ) { var depUrl = relative ( dep , url ) ; moduleDeps [ depUrl ] = 1 ; return requireUrl ( depUrl ) ; } ) ; depGraph [ url ] = moduleDeps ; if ( findCycles ( url ) ) { rejectScript ( ) ; return ; } Promise . all ( dependencyPromises ) . then ( function ( loadedDeps ) { modules [ url ] = factory . apply ( window , loadedDeps ) ; resolveScript ( ) ; } ) . catch ( rejectScript ) ; } else { if ( global ) { modules [ url ] = window [ global ] ; } else { modules [ url ] = callbackValue || true ; } resolveScript ( ) ; } } return new Promise ( function ( resolve , reject ) { promiseCallbacks [ url ] . push ( [ resolve , reject ] ) ; var useCallback = url . substr ( - 1 ) === '=' ; var src = url ; var onload ; if ( useCallback ) { var callbackName = 'cb' + nextId ; nextId ++ ; window [ callbackName ] = scriptLoaded ; src = url + callbackName ; } else { onload = function ( ) { scriptLoaded ( ) ; } ; } if ( document ) { var script = document . createElement ( 'script' ) ; script . src = src ; script . onload = onload ; script . onerror = rejectScript ; document . head . appendChild ( script ) ; } else { setTimeout ( function ( ) { try { importScripts ( src ) ; if ( onload ) { onload ( ) ; } } catch ( error ) { rejectScript ( ) ; } } , 1 ) ; } } ) ; }
Load a module or script.
Load a module or script .
// Module already loaded - resolve immediately. // Module is already being loaded, return a promise that will complete when the in-progress load completes. /**
         * Complete the loading of a script. Call the appropriate callbacks.
         *
         * @param {number} callback - 0 for the resolve callbacks, 1 for the reject callbacks.
         * @param {Object=} argument - the callback argument.
         * @returns {void}
         */ /** Script has finished loading.
         *
         * @param {Object=} callbackValue - the value delivered by a callback
         * @return {void}
         */ // This module calls a callback.