index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-28 16:19:32 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-28 16:19:32 -0700 |
commit | cf190d8e7a7087fee343138b62431c4b800710ec (patch) | |
tree | 95c4a43df174eae82aafea18d665e42533dfdd04 | |
parent | 1d5d5a2cda8ea462f1ed60757b8d2622522486b8 (diff) |
Restore content visibility on page reload
-rw-r--r-- | src/index.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/index.js b/src/index.js index a8b766a..3a8a48e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,8 @@ const mapPlaceholder = document.querySelector('.map-placeholder'), proneToggle = document.getElementById('toggle-prone-counter'), object = document.querySelector('object'); -object.addEventListener('load', function () { +object.addEventListener('load', function (e) { + console.log('object load listener', e); mapPlaceholder.remove(); this.style.opacity = 1; @@ -89,20 +90,24 @@ document.getElementById('toggle-prone-counter').addEventListener('input', functi object.data = `${localStorage.getItem('map') || 'map1'}.svg`; -document - .querySelector('#content input[type="checkbox"].visible') - .addEventListener('input', function () { - const divs = document.querySelectorAll('#content div'); - - divs.forEach(d => { - if (this.checked) { - d.style.display = d.id == 'record-sheet' ? 'flex' : 'block'; - } else { - d.style.display = 'none'; - } - }); +const contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'); +contentVisToggleEl.checked = (localStorage.getItem('content-visibility') !== 'false'); + +const toggleContentVis = (function () { + document.querySelectorAll('#content div').forEach(div => { + if (this.checked) { + div.style.display = div.id == 'record-sheet' ? 'flex' : 'block'; + } else { + div.style.display = 'none'; + } }); + localStorage.setItem('content-visibility', this.checked); +}).bind(contentVisToggleEl); + +toggleContentVis(); +contentVisToggleEl.addEventListener('input', toggleContentVis); + const showButton = document.getElementById('show-dialog'), mapDialog = document.getElementById('map-dialog'), selectEl = mapDialog.querySelector('select'), |