This commit is contained in:
Letter N
2021-01-31 10:16:48 +08:00
parent 512124100e
commit 02bba115a6
104 changed files with 5086 additions and 986 deletions

View File

@@ -178,10 +178,10 @@ if (window.__windowId__ === '[' + 'tgui:windowId' + ']') {
// ------------------------------------------------------
var RETRY_ATTEMPTS = 5;
var RETRY_INTERVAL = 2000;
var RETRY_WAIT_INITIAL = 500;
var RETRY_WAIT_INCREMENT = 500;
var loadedCssByUrl = {};
var loadedJsByUrl = {};
var loadedAssetByUrl = {};
var isStyleSheetLoaded = function (node, url) {
// Method #1 (works on IE10+)
@@ -202,105 +202,105 @@ if (window.__windowId__ === '[' + 'tgui:windowId' + ']') {
return false;
};
var onDocumentBodyReady = function (done) {
if (document.body) {
return done();
}
setTimeout(function () {
onDocumentBodyReady(done);
});
};
var getRefNode = function () {
var refs = (document.body || document.getElementsByTagName('head')[0])
.childNodes;
return refs[refs.length - 1];
};
// Based on fg-loadcss package
// See: https://github.com/filamentgroup/loadCSS
Byond.loadCss = function (url, sync, attempt) {
if (loadedCssByUrl[url]) {
var injectNode = function (node) {
if (!document.body) {
setTimeout(function () {
injectNode(node);
});
return;
}
if (!attempt) {
attempt = 1;
}
loadedCssByUrl[url] = true;
// Inject the stylesheet
var ref = getRefNode();
/** @type {HTMLLinkElement} */
var node = document.createElement('link');
node.type = 'text/css';
node.rel = 'stylesheet';
node.href = url;
// Temporarily set media to something inapplicable
// to ensure it'll fetch without blocking render
if (!sync) {
node.media = 'only x';
}
onDocumentBodyReady(function () {
ref.parentNode.insertBefore(node, ref.nextSibling);
});
// Listen for the load event
node.onload = function () {
node.onload = null;
if (isStyleSheetLoaded(node, url)) {
// Render the stylesheet
node.media = 'all';
return;
}
// Try again
node.parentNode.removeChild(node);
node = null;
loadedCssByUrl[url] = null;
if (attempt >= RETRY_ATTEMPTS) {
throw new Error("Error: Failed to load the stylesheet "
+ "'" + url + "' after " + RETRY_ATTEMPTS + " attempts.\n"
+ "It was either not found, or you're trying to load "
+ "an empty stylesheet that has no CSS rules in it.");
}
setTimeout(function () {
Byond.loadCss(url, sync, attempt + 1);
}, RETRY_INTERVAL);
};
var refs = document.body.childNodes;
var ref = refs[refs.length - 1];
ref.parentNode.insertBefore(node, ref.nextSibling);
};
Byond.loadJs = function (url, sync, attempt) {
if (loadedJsByUrl[url]) {
var loadAsset = function (options) {
var url = options.url;
var type = options.type;
var sync = options.sync;
var attempt = options.attempt || 0;
if (loadedAssetByUrl[url]) {
return;
}
if (!attempt) {
attempt = 1;
}
loadedJsByUrl[url] = true;
// Inject the stylesheet
var ref = getRefNode();
var node = document.createElement('script');
node.type = 'text/javascript';
if (sync) {
node.defer = true;
}
else {
node.async = true;
}
node.src = url;
onDocumentBodyReady(function () {
ref.parentNode.insertBefore(node, ref.nextSibling);
});
node.onerror = function () {
node.onerror = null;
node.parentNode.removeChild(node);
node = null;
loadedJsByUrl[url] = null;
loadedAssetByUrl[url] = options;
// Generic retry function
var retry = function () {
if (attempt >= RETRY_ATTEMPTS) {
throw new Error("Error: Failed to load the script "
+ "'" + url + "' after " + RETRY_ATTEMPTS + " attempts.");
var errorMessage = "Error: Failed to load the asset "
+ "'" + url + "' after several attempts.";
if (type === 'css') {
errorMessage += + "\nStylesheet was either not found, "
+ "or you're trying to load an empty stylesheet "
+ "that has no CSS rules in it.";
}
throw new Error(errorMessage);
}
setTimeout(function () {
Byond.loadJs(url, sync, attempt + 1);
}, RETRY_INTERVAL);
loadedAssetByUrl[url] = null;
options.attempt += 1;
loadAsset(options);
}, RETRY_WAIT_INITIAL + attempt * RETRY_WAIT_INCREMENT);
};
// JS specific code
if (type === 'js') {
var node = document.createElement('script');
node.type = 'text/javascript';
// IE8: Prefer non-https protocols
node.src = Byond.IS_LTE_IE9
? url.replace('https://', 'http://')
: url;
if (sync) {
node.defer = true;
}
else {
node.async = true;
}
node.onerror = function () {
node.onerror = null;
node.parentNode.removeChild(node);
node = null;
retry();
};
injectNode(node);
return;
}
// CSS specific code
if (type === 'css') {
var node = document.createElement('link');
node.type = 'text/css';
node.rel = 'stylesheet';
// IE8: Prefer non-https protocols
node.href = Byond.IS_LTE_IE9
? url.replace('https://', 'http://')
: url;
// Temporarily set media to something inapplicable
// to ensure it'll fetch without blocking render
if (!sync) {
node.media = 'only x';
}
node.onload = function () {
node.onload = null;
if (isStyleSheetLoaded(node, url)) {
// Render the stylesheet
node.media = 'all';
return;
}
// Try again
node.parentNode.removeChild(node);
node = null;
retry();
};
injectNode(node);
return;
}
};
Byond.loadJs = function (url, sync) {
loadAsset({ url: url, sync: sync, type: 'js' });
};
Byond.loadCss = function (url, sync) {
loadAsset({ url: url, sync: sync, type: 'css' });
};
})();
@@ -322,12 +322,14 @@ window.onerror = function (msg, url, line, col, error) {
var errorStack = document.getElementById('FatalError__stack');
if (errorRoot) {
errorRoot.className = 'FatalError FatalError--visible';
if (errorStack.textContent) {
errorStack.textContent += '\n\n' + stack;
if (window.onerror.__stack__) {
window.onerror.__stack__ += '\n\n' + stack;
}
else {
errorStack.textContent = stack;
window.onerror.__stack__ = stack;
}
var textProp = Byond.IS_LTE_IE8 ? 'innerText' : 'textContent';
errorStack[textProp] = window.onerror.__stack__;
}
// Set window geometry
var setFatalErrorGeometry = function () {
@@ -505,9 +507,9 @@ o8o `8 "888" `Y8bood8P' 8""88888P'
<marquee class="FatalError__header">
A fatal exception has occurred at 002B:C562F1B7 in TGUI.
The current application will be terminated.
Please remain calm. Get to the nearest NTNet workstation
and send the copy of the following stack trace to:
www.github.com/Citadel-Station-13/Citadel-Station-13/issues. Thank you for your cooperation.
Send the copy of the following stack trace to an authorized
Nanotrasen incident handler at https://github.com/itadel-Station-13/Citadel-Station-13.
Thank you for your cooperation.
</marquee>
<div id="FatalError__stack" class="FatalError__stack"></div>
<div class="FatalError__footer">