index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/modules/map_select_dialog.js')
-rw-r--r-- | src/modules/map_select_dialog.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/modules/map_select_dialog.js b/src/modules/map_select_dialog.js new file mode 100644 index 0000000..a9f8bc8 --- /dev/null +++ b/src/modules/map_select_dialog.js @@ -0,0 +1,42 @@ +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 = `${selectEl.value}.svg`; + mapDialog.close(); + }); + } + }; +} |