Rename variables for clarity

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 22:41:30 -07:00
parent 73cbf3e6dd
commit fd99c0d839

View File

@ -9,8 +9,8 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
distanceOutput = document.getElementById('status'), distanceOutput = document.getElementById('status'),
proneToggle = document.getElementById('toggle-prone-counter'), proneToggle = document.getElementById('toggle-prone-counter'),
contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'), contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'),
object = document.querySelector('object'), // fileName = localStorage.getItem('map') || (env === 'test' ? 'test_map' : 'map1'),
fileName = localStorage.getItem('map') || (env === 'test' ? 'test_map' : 'map1'), fileName = localStorage.getItem('map') || 'map1',
map = `assets/images/${fileName}.svg`, map = `assets/images/${fileName}.svg`,
toggleContentVis = (function () { toggleContentVis = (function () {
@ -25,21 +25,23 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
localStorage.setItem('content-visibility', this.checked); localStorage.setItem('content-visibility', this.checked);
}).bind(contentVisToggleEl), }).bind(contentVisToggleEl),
objectDataObserver = new MutationObserver(function () { mapResourceObserver = new MutationObserver(function () {
const currentObj = document.querySelector('object'); const current = document.querySelector('object');
const currentData = currentObj.getAttribute('data'); const resource = current.getAttribute('data');
const nextObj = document.createElement('object'); const next = document.createElement('object');
nextObj.setAttribute('type', 'image/svg+xml'); next.setAttribute('type', 'image/svg+xml');
nextObj.style.opacity = 0; next.style.opacity = 0;
nextObj.addEventListener('load', load); next.addEventListener('load', load);
mapPlaceholder.after(nextObj); mapPlaceholder.after(next);
mapPlaceholder.style.opacity = 1; mapPlaceholder.style.opacity = 1;
nextObj.data = currentData; next.data = resource;
this.disconnect(); this.disconnect();
currentObj.remove(); current.remove();
this.observe(nextObj, { attributeFilter: ['data'] }); this.observe(next, { attributeFilter: ['data'] });
}); });
let mapResourceEl = document.querySelector('object');
function updateTurnCounter() { function updateTurnCounter() {
const turnCounter = document.getElementById('turn-count'); const turnCounter = document.getElementById('turn-count');
@ -137,19 +139,20 @@ mapSelectDialog
.updateValueOnSelection() .updateValueOnSelection()
.changeMapOnConfirm(); .changeMapOnConfirm();
object.addEventListener('load', load); mapResourceEl.addEventListener('load', load);
object.data = map; mapResourceEl.data = map;
objectDataObserver.observe(object, { attributeFilter: ['data'] }); mapResourceObserver.observe(mapResourceEl, { attributeFilter: ['data'] });
mapResourceEl = null;
document.querySelector('#download-save').addEventListener('click', e => { document.querySelector('#download-save').addEventListener('click', e => {
const data = object.contentDocument.documentElement.outerHTML; const data = document.querySelector('object').contentDocument.documentElement.outerHTML;
const element = document.createElement('a'); const element = document.createElement('a');
element.setAttribute('download', 'save.svg'); element.setAttribute('download', 'save.svg');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data)); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data));
element.style.display = 'none'; element.style.display = 'none';
document.body.appendChild(element); // document.body.appendChild(element);
element.click(); element.click();
document.body.removeChild(element); // document.body.removeChild(element);
}); });