/// (function(w) { const d = window.document; const r = d.createElement("a"); const protocol = location.href.match(/^\w+:/)[0]; const resolveUrl = function(url: string) { r.setAttribute("href", url); var href = r.href; if (/^\/\//.test(href)) href = protocol + href; return href; } const rmClass = function(elements: HTMLCollection, visibleClass: string) { var element: Element; const classRegex = new RegExp("(^|\\s+)" + (visibleClass as string).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s+|$)", "g"); for(var i=0; i': '>', '"': '"', "'": ''', '`': '`', '/': '/', '=': '=', ' ': "  ", '\n': "
" }; const html = messageAndStack.replace(/([&<>"'`=\/\n]| )/g, function (s) { return replacements[s]; }); for(var i=0; i= totalScripts) { if (oncomplete) oncomplete(); else if (progressBarContainer) rmClass(progressBarContainer, "loader-progress-visible"); document.body.style.overflow = "auto"; prog = 1; } else prog = 1-Math.pow(5, 1-(loadedScripts / totalScripts))/5; prog = (prog*100) + "%"; for (var i = 0; i < progressBar.length; i++) progressBar[i]['style'] && (progressBar[i]['style'].width = prog); }; resetProgress = function(by = 1) { totalScripts = by; loadedScripts = 0; } } else if(progressBarContainer.length) { let totalScripts = 0, loadedScripts = 0; incrementProgress = function(oncomplete?) { if(++loadedScripts >= totalScripts) { if (oncomplete) oncomplete(); else rmClass(progressBarContainer, "loader-progress-visible"); } }; resetProgress = function(by = 1) { totalScripts = by; loadedScripts = 0; } } else { let totalScripts = 0, loadedScripts = 0; incrementProgress = function(oncomplete?) { if(++loadedScripts >= totalScripts && oncomplete) oncomplete(); }; resetProgress = function(by = 1) { totalScripts = by; loadedScripts = 0; } } if (progressBarContainer) addClass(progressBarContainer, "loader-progress-visible"); document.body.style.overflow = "hidden"; /** * https://stackoverflow.com/questions/3728798/running-javascript-downloaded-with-xmlhttprequest/35247060#answer-31275143 */ const base64 = function(data: string) { try { return btoa(data); } catch (e) { // script file may contain characters that not included in Latin1 var symbols = data.split(''); for (var i = 0, l = symbols.length; i < l; i++) { var symbol = symbols[i]; // here we are trying to find these symbols in catch branch try { btoa(symbol); } catch (e) { var code = symbol.charCodeAt(0).toString(16); while (code.length < 4) { code = '0' + code; } // replace original symbol to unicode character symbols[i] = '\\u' + code; } } // create new base64 string from string with replaced characters return btoa(symbols.join('')); } } const padLeft = function(data: string, count = 8, using = "0") { while (data.length < count) data = using + data; return data; } const stringHash = function(data: string) { if (data.length === 0) return "00000000"; var hash = 0; for (var i = 0; i < data.length; i++) hash = (((hash << 5) - hash) + data.charCodeAt(i)) | 0; return padLeft(hash.toString(16)); }; var initialVersions: string[]; const loadCallbacks: {[index: string]: Function[]} = {}; const resourceSources: {[index: string]: string} = {}; const NexusFrameworkLoaderImpl = { load(data: NexusFrameworkLoaderData, oncomplete?: () => void) { if (initialVersions) { const versions = data[0]; const len = versions.length; if (len !== initialVersions.length) return location.reload(true); for (var i=0; i void, deps: string[] = [], inlineOrIntegrity?: boolean | string, name?: string) { try { var processResource: (data: string) => void, callCallbacks: (err?: Error) => void; var contentType: string; if(type == "script") { contentType = "text/javascript"; processResource = function(url) { const scriptel = d.createElement('script'); scriptel.type = "text/javascript"; if (inlineOrIntegrity && inlineOrIntegrity !== true) scriptel.integrity = inlineOrIntegrity; scriptel.async = true; scriptel.onload = function() { callCallbacks(); }; scriptel.onerror = function() { callCallbacks(new Error("Failed to load resource: " + source)); }; scriptel.src = url; d.body.appendChild(scriptel); } } else if(type == "style") { contentType = "text/css"; processResource = function(url) { const linkel = d.createElement('link'); linkel.type = "text/css"; linkel.rel = "stylesheet"; if (inlineOrIntegrity && inlineOrIntegrity !== true) linkel.integrity = inlineOrIntegrity; linkel.onload = function() { callCallbacks(); }; linkel.onerror = function() { callCallbacks(new Error("Failed to load resource: " + source)); }; linkel.href = url; d.body.appendChild(linkel); } } else throw new Error("Unknown type: " + type); var errored = false; const onLoad = function(err?: Error) { if(errored) return; if(err) { errored = true; cb(err); } else cb(); }; var url: string; if (inlineOrIntegrity !== true) url = source = resolveUrl(source); if (!name) { if(inlineOrIntegrity === true) { name = "inline-" + stringHash(source); } else { name = source; var index = name.lastIndexOf("/"); if(index > -1) name = name.substring(index+1); var match = name.match(/^(([a-z][a-z0-9]*[\-_\.]?)+)\.(css|js)(\?.*)?$/i); if(match) name = match[1]; else name = name.replace(/\.(css|js)(\?.*)?$/i, ""); if(/\.min$/.test(name)) name = name.substring(0, name.length-4); if(/\.slim$/.test(name)) name = name.substring(0, name.length-5); if(/\.umd$/.test(name)) name = name.substring(0, name.length-4); match = name.match(/^(.+)\-\d+([\.\-]\d)*$/); if (match) name = match[1]; } } const key = type + ":" + name; var callbacks = loadCallbacks[key]; if(callbacks) return callbacks.push(onLoad); callCallbacks = function(err?: Error) { callbacks.forEach(function(cb) { cb(err); }); if (inlineOrIntegrity === true && type === "script") delete loadCallbacks[key]; else loadCallbacks[key] = {push: function(cb: Function) { cb(err); }} as any; } callbacks = loadCallbacks[key] = [onLoad]; if(inlineOrIntegrity !== true && source.indexOf("/") == -1) return callCallbacks(new Error(type[0].toUpperCase() + type.substring(1) + " `" + name + "` is required, but not included.")); if (deps.length) { var toLoad = deps.length; deps.forEach(function(dep) { NexusFrameworkLoaderImpl.loadResource(type, dep, function(err?: Error) { if(err) callCallbacks(err); else if(!--toLoad) { resourceSources[key] = source; if(inlineOrIntegrity === true) processResource('data:'+contentType+';base64,' + base64(source)); else processResource(source); } }); }); } else if(inlineOrIntegrity === true) processResource('data:'+contentType+';base64,' + base64(source)); else processResource(source); } catch(e) { console.warn(e); cb(e); } } } as NexusFrameworkLoader; NexusFrameworkLoaderImpl.resetError = function() { if(errorFade && errorContainerArray.length) rmClass(errorContainerArray, errorFade); errorShowed = false; }; NexusFrameworkLoaderImpl.showError = function(err) { errorShowed = false; return showError(err); }; var messageVisible: boolean, progressTimeout: number; NexusFrameworkLoaderImpl.showProgress = function(cb?: () => void, title?: string, message?: string) { if (progressBarContainer) { addClass(progressBarContainer, "loader-progress-visible"); if (message) { Array.prototype.forEach.call(progressBarContainer, function(container) { const cont = container.querySelector(".loader-progress-message-container"); cont.querySelector("h5").innerHTML = title; cont.querySelector("p").innerHTML = message; }); addClass(progressBarContainer, "loader-progress-message-visible"); messageVisible = true; } else if(messageVisible) { rmClass(progressBarContainer, "loader-progress-message-visible"); messageVisible = undefined; } if (cb) { try {clearTimeout(progressTimeout)}catch(e){} progressTimeout = setTimeout(cb, 200) as any; } } else if (cb) cb(); document.body.style.overflow = "hidden"; return progressBarContainer; }; NexusFrameworkLoaderImpl.resetProgress = function() { if (progressBarContainer) { try {clearTimeout(progressTimeout)}catch(e){} rmClass(progressBarContainer, "loader-progress-visible"); if (messageVisible) { rmClass(progressBarContainer, "loader-progress-message-visible"); messageVisible = undefined; } } document.body.style.overflow = "auto"; }; Object.defineProperty(w, "NexusFrameworkLoader", { value: NexusFrameworkLoaderImpl }); } catch(e) { showError(e); } })(window);