Web Dev Solutions

Catalin Mititiuc

From cf190d8e7a7087fee343138b62431c4b800710ec Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sun, 28 Apr 2024 16:19:32 -0700 Subject: Restore content visibility on page reload --- src/index.js | 31 ++++++++++++++++++------------- 1 file 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'), -- cgit v1.2.3