From f68ec55d6081e984f4686d276719db5d142e38fc Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Thu, 30 Apr 2020 12:39:55 -0500 Subject: [PATCH] fix for game ages not updating in selection box --- js/pacosako_ui.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/js/pacosako_ui.js b/js/pacosako_ui.js index 791d166..d9bf8f1 100644 --- a/js/pacosako_ui.js +++ b/js/pacosako_ui.js @@ -1006,12 +1006,30 @@ $(function (){ `).appendTo(gameSelectContent); + var selectBoxIntervalID = undefined; var selectBox = new jBox('Modal', { content: gameSelectContent, blockScroll: false, blockScrollAdjust: false, isolateScroll: false, delayClose: 750, + onOpen() { + if (selectBoxIntervalID !== undefined) { + clearInterval(selectBoxIntervalID); + } + selectBoxIntervalID = setInterval(() => { + updateTileAges(); + }, 15000); + updateTileAges(); + }, + onCloseComplete() { + if (selectBoxIntervalID !== undefined) { + clearInterval(selectBoxIntervalID); + selectBoxIntervalID = undefined; + } + }, + position: { x: 'center', y: 'center' }, + reposition: true, }); $('.new-game-tile').on('click', function() { @@ -1027,10 +1045,10 @@ $(function (){ return `${words[n] || n} ${n === 1 ? singular : (plural || (singular + 's'))}`; } - function updateTileAges(tiles) { + function updateTileAges() { const now = +new Date(); - for (const tileElem of (tiles || $('.game-tile.existing-game'))) { + for (const tileElem of $('.game-tile.existing-game-tile')) { const tile = $(tileElem); const game = tile.data('gameMeta'); @@ -1058,8 +1076,6 @@ $(function (){ } } - window.setInterval(() => { updateTileAges(); }, 15000); - function updateSelectGameMeta(data, gameId) { data = Object.assign({}, data, { gameId: gameId || data.gameId, @@ -1118,7 +1134,6 @@ $(function (){ } $('
').addClass('game-tile-age').appendTo(tile); - updateTileAges(tile); tile.on('click', function() { $('.game-tile-selected').removeClass('game-tile-selected'); @@ -1135,6 +1150,7 @@ $(function (){ return (then_a < then_b) ? 1 : (then_a === then_b) ? 0 : -1; }); $(list).appendTo(gameTiles); + updateTileAges(); tile.show("fold");