Don't show print dialog until styles loaded

This commit is contained in:
RunasSudo 2021-05-25 01:12:54 +10:00
parent 1ad1684e67
commit 56e32d11b3
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 18 additions and 3 deletions

View File

@ -593,11 +593,28 @@ function printResult() {
wprint.document.title = 'pyRCV2 Report';
// Add stylesheets
let numToLoad = 0;
let numLoaded = 0;
function onLoadStylesheet() {
numLoaded++;
if (numLoaded == numToLoad) {
wprint.print();
}
}
for (let elCSSBase of document.querySelectorAll('head link')) {
numToLoad++;
let elCSS = wprint.document.createElement('link');
elCSS.rel = elCSSBase.rel;
elCSS.type = elCSSBase.type;
elCSS.href = elCSSBase.href;
if (elCSSBase.href.endsWith('?v=GITVERSION')) {
elCSS.href = elCSSBase.href.replace('?v=GITVERSION', '?v=' + Math.random());
} else {
elCSS.href = elCSSBase.href;
}
elCSS.onload = onLoadStylesheet;
wprint.document.head.appendChild(elCSS);
}
@ -702,6 +719,4 @@ function printResult() {
divResultLogs2 = wprint.document.createElement('div');
divResultLogs2.innerHTML = divResultLogs1.innerHTML;
elContainer.appendChild(divResultLogs2);
wprint.print();
}