diff --git a/html/index.js b/html/index.js index 9d1b6a4..a5c43e6 100644 --- a/html/index.js +++ b/html/index.js @@ -594,7 +594,7 @@ function printResult() { // Add stylesheets let numToLoad = 0; - let numLoaded = 0; + let numLoaded = -1; function onLoadStylesheet() { numLoaded++; @@ -676,7 +676,7 @@ function printResult() { return tdsAdded; } - function copyTableColumns(startCol) { + async function copyTableColumns(startCol) { // Add table let elTable2 = wprint.document.createElement('table'); elTable2.className = 'result'; @@ -701,6 +701,9 @@ function printResult() { for (let c = startCol; c < rows[0].length + 1; c++) { // +1 to account for final status column let tdsAdded = copyColumn(c, elTrs2); + // Nasty hack: DOM can take a while to update clientWidth + await new Promise(wprint.requestAnimationFrame); + // Check if overflowed if (elTable2.clientWidth > printableWidth) { for (let elTd2 of tdsAdded) { @@ -712,11 +715,14 @@ function printResult() { } } - copyTableColumns(1); - - // Copy result logs2 - divResultLogs1 = document.getElementById('resultLogs2'); - divResultLogs2 = wprint.document.createElement('div'); - divResultLogs2.innerHTML = divResultLogs1.innerHTML; - elContainer.appendChild(divResultLogs2); + copyTableColumns(1).then(function() { + // Copy result logs2 + divResultLogs1 = document.getElementById('resultLogs2'); + divResultLogs2 = wprint.document.createElement('div'); + divResultLogs2.innerHTML = divResultLogs1.innerHTML; + elContainer.appendChild(divResultLogs2); + + // Trigger print when ready + onLoadStylesheet(); + }); }