Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-05-15 11:22:47 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-05-15 11:22:47 -0700
commit26285e4be7159108e5dba9a79543fff2860e8a69 (patch)
tree06ce025e23731b99418dc5dc8558a9e9471d08fe
parentf021368a6697c6b064aa8da208cdf60265f4bfe0 (diff)
Rename variables for clarity
-rw-r--r--src/index.js41
1 files changed, 22 insertions, 19 deletions
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);
});