Rename variables for clarity
This commit is contained in:
parent
f021368a66
commit
26285e4be7
41
src/index.js
41
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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user