Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-05-19 21:32:42 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-05-19 21:42:39 -0700
commitc692bc90207c4b04771f953ce5924100a1889cae (patch)
tree01afbbc26ec34bc7746631c6fd611b23ad6d18d1 /src/index.js
parentff7e88457c72f9cca9d2fdd965d8a4fd0e3de48a (diff)
Simplify loading scenarios
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/index.js b/src/index.js
index 9765c41..c71cc16 100644
--- a/src/index.js
+++ b/src/index.js
@@ -24,25 +24,22 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
});
localStorage.setItem('content-visibility', this.checked);
- }).bind(contentVisToggleEl),
-
- 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;
- next.data = resource;
- this.disconnect();
- current.remove();
- this.observe(next, { attributeFilter: ['data'] });
- });
+ }).bind(contentVisToggleEl);
let mapResourceEl = document.querySelector('object');
+function loadScenario(data) {
+ const current = document.querySelector('object');
+ 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;
+ next.data = data;
+ current.remove();
+}
+
function updateTurnCounter() {
const turnCounter = document.getElementById('turn-count');
@@ -161,11 +158,10 @@ mapSelectDialog
.selectCurrentOptionOnPageLoad()
.showOnClick()
.updateValueOnSelection()
- .changeMapOnConfirm();
+ .changeMapOnConfirm(loadScenario);
mapResourceEl.addEventListener('load', load);
mapResourceEl.data = map;
-mapResourceObserver.observe(mapResourceEl, { attributeFilter: ['data'] });
mapResourceEl = null;
document.querySelector('#download-save').addEventListener('click', e => {
@@ -187,5 +183,5 @@ document.querySelector('#upload-save').addEventListener('click', () => {
document.querySelector('input[type="file"]').addEventListener('change', e => {
const [file] = fileInputEl.files;
- document.querySelector('object').data = URL.createObjectURL(file);
+ loadScenario(URL.createObjectURL(file))
});