43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
export function init() {
|
|
const showButton = document.getElementById('show-dialog'),
|
|
mapDialog = document.getElementById('map-dialog'),
|
|
selectEl = mapDialog.querySelector('select'),
|
|
confirmBtn = mapDialog.querySelector('#confirm-btn');
|
|
|
|
return {
|
|
selectCurrentOptionOnPageLoad() {
|
|
mapDialog.querySelectorAll('option').forEach(option =>
|
|
option.value === localStorage.getItem('map') && (option.selected = true)
|
|
);
|
|
|
|
return this;
|
|
},
|
|
|
|
showOnClick() {
|
|
showButton.addEventListener('click', () => {
|
|
mapDialog.showModal();
|
|
});
|
|
|
|
return this;
|
|
},
|
|
|
|
updateValueOnSelection() {
|
|
selectEl.addEventListener('change', () => {
|
|
confirmBtn.value = selectEl.value;
|
|
});
|
|
|
|
return this;
|
|
},
|
|
|
|
changeMapOnConfirm() {
|
|
confirmBtn.addEventListener('click', e => {
|
|
e.preventDefault();
|
|
localStorage.removeItem('pan-zoom');
|
|
localStorage.setItem('map', selectEl.value);
|
|
document.querySelector('object').data = `assets/images/${selectEl.value}.svg`;
|
|
mapDialog.close();
|
|
});
|
|
}
|
|
};
|
|
}
|