From 26285e4be7159108e5dba9a79543fff2860e8a69 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Wed, 15 May 2024 11:22:47 -0700
Subject: Rename variables for clarity
---
src/index.js | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
(limited to 'src')
diff --git a/src/index.js b/src/index.js
index 91809c3..3efa5a7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -9,8 +9,8 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
distanceOutput = document.getElementById('status'),
proneToggle = document.getElementById('toggle-prone-counter'),
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`,
toggleContentVis = (function () {
@@ -25,21 +25,23 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
localStorage.setItem('content-visibility', this.checked);
}).bind(contentVisToggleEl),
- objectDataObserver = new MutationObserver(function () {
- const currentObj = document.querySelector('object');
- const currentData = currentObj.getAttribute('data');
- const nextObj = document.createElement('object');
- nextObj.setAttribute('type', 'image/svg+xml');
- nextObj.style.opacity = 0;
- nextObj.addEventListener('load', load);
- mapPlaceholder.after(nextObj);
+ mapResourceObserver = new MutationObserver(function () {
+ const current = document.querySelector('object');
+ const resource = current.getAttribute('data');
+ const next = document.createElement('object');
+ next.setAttribute('type', 'image/svg+xml');
+ next.style.opacity = 0;
+ next.addEventListener('load', load);
+ mapPlaceholder.after(next);
mapPlaceholder.style.opacity = 1;
- nextObj.data = currentData;
+ next.data = resource;
this.disconnect();
- currentObj.remove();
- this.observe(nextObj, { attributeFilter: ['data'] });
+ current.remove();
+ this.observe(next, { attributeFilter: ['data'] });
});
+ let mapResourceEl = document.querySelector('object');
+
function updateTurnCounter() {
const turnCounter = document.getElementById('turn-count');
@@ -137,19 +139,20 @@ mapSelectDialog
.updateValueOnSelection()
.changeMapOnConfirm();
-object.addEventListener('load', load);
-object.data = map;
-objectDataObserver.observe(object, { attributeFilter: ['data'] });
+mapResourceEl.addEventListener('load', load);
+mapResourceEl.data = map;
+mapResourceObserver.observe(mapResourceEl, { attributeFilter: ['data'] });
+mapResourceEl = null;
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');
element.setAttribute('download', 'save.svg');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data));
element.style.display = 'none';
- document.body.appendChild(element);
+ // document.body.appendChild(element);
element.click();
- document.body.removeChild(element);
+ // document.body.removeChild(element);
});
--
cgit v1.2.3