commento.js: use a event listener in CSS overrides

Closes https://gitlab.com/commento/commento/-/issues/302
This commit is contained in:
Adhityaa Chandrasekar 2020-03-31 07:00:46 -04:00
parent fbc98bce08
commit daae592b5d

View File

@ -174,6 +174,13 @@
} }
function onload(node, f, arg) {
node.addEventListener("load", function() {
f(arg);
});
}
function attrSet(node, a, value) { function attrSet(node, a, value) {
node.setAttribute(a, value); node.setAttribute(a, value);
} }
@ -344,21 +351,21 @@
} }
selfLoad(resp.commenter, resp.email); selfLoad(resp.commenter, resp.email);
global.allShow(); allShow();
call(callback); call(callback);
}); });
} }
function cssLoad(file, onload) { function cssLoad(file, f) {
var link = create("link"); var link = create("link");
var head = document.getElementsByTagName("head")[0]; var head = document.getElementsByTagName("head")[0];
link.type = "text/css"; link.type = "text/css";
attrSet(link, "href", file); attrSet(link, "href", file);
attrSet(link, "rel", "stylesheet"); attrSet(link, "rel", "stylesheet");
attrSet(link, "onload", onload); onload(link, f);
append(head, link); append(head, link);
} }
@ -1783,7 +1790,7 @@
cookieSet("commentoCommenterToken", resp.commenterToken); cookieSet("commentoCommenterToken", resp.commenterToken);
selfLoad(resp.commenter, resp.email); selfLoad(resp.commenter, resp.email);
global.allShow(); allShow();
remove($(ID_LOGIN)); remove($(ID_LOGIN));
if (id !== null) { if (id !== null) {
@ -2015,16 +2022,16 @@
} }
global.loadCssOverride = function() { function loadCssOverride() {
if (cssOverride === undefined) { if (cssOverride === undefined) {
global.allShow(); allShow();
} else { } else {
cssLoad(cssOverride, "window.commento.allShow()"); cssLoad(cssOverride, allShow);
} }
} }
global.allShow = function() { function allShow() {
var mainArea = $(ID_MAIN_AREA); var mainArea = $(ID_MAIN_AREA);
var modTools = $(ID_MOD_TOOLS); var modTools = $(ID_MOD_TOOLS);
var loggedContainer = $(ID_LOGGED_CONTAINER); var loggedContainer = $(ID_LOGGED_CONTAINER);
@ -2134,7 +2141,7 @@
mainAreaCreate(); mainAreaCreate();
var footer = footerLoad(); var footer = footerLoad();
cssLoad(cdn + "/css/commento.css", "window.commento.loadCssOverride()"); cssLoad(cdn + "/css/commento.css", loadCssOverride);
selfGet(function() { selfGet(function() {
commentsGet(function() { commentsGet(function() {
@ -2143,7 +2150,7 @@
commentsRender(); commentsRender();
append(root, footer); append(root, footer);
loadHash(); loadHash();
global.allShow(); allShow();
nameWidthFix(); nameWidthFix();
call(callback); call(callback);
}); });