From 3bd38bd7113c7230d10754ee792e5324c8688575 Mon Sep 17 00:00:00 2001 From: Elijah Steres Date: Thu, 31 Dec 2020 03:45:42 -0500 Subject: [PATCH] make games not jump around when other games end --- static/loader.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/static/loader.js b/static/loader.js index 738fa9b..b2cd024 100644 --- a/static/loader.js +++ b/static/loader.js @@ -41,21 +41,20 @@ $(document).ready(function (){ for (var slotnum = 0; slotnum < grid.children.length; slotnum++) { if (grid.children[slotnum].className == "game" && !(Object.keys(json).includes(grid.children[slotnum].timestamp))) { - grid.removeChild(grid.children[slotnum]); + grid.children[slotnum].className = "emptyslot"; + grid.children[slotnum].innerHTML = ""; } } - var requiredcells = Math.max(3, 3 * Math.ceil(Object.keys(json).length/3)); + while (grid.children[grid.children.length-1].className == "emptyslot" && + grid.children[grid.children.length-2].className == "emptyslot" && + grid.children[grid.children.length-3].className == "emptyslot" && + grid.children.length > 3) { - while (grid.children.length > requiredcells) { - grid.removeChild(grid.children[requiredcells]); + for (var i = 0; i < 3; i++) { + grid.removeChild(grid.children[grid.children.length-1]); + } } - - while (grid.children.length < requiredcells) { - insertEmpty(grid); - } - - console.log(grid.children.length) }); const insertEmpty = (grid) => {