From f021368a6697c6b064aa8da208cdf60265f4bfe0 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Sat, 4 May 2024 10:25:22 -0700
Subject: WIP: add fullscreen and download save abilities
---
src/index.js | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
(limited to 'src/index.js')
diff --git a/src/index.js b/src/index.js
index 1f8f2c1..91809c3 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,7 +10,8 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
proneToggle = document.getElementById('toggle-prone-counter'),
contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'),
object = document.querySelector('object'),
- fileName = `assets/images/${localStorage.getItem('map') || 'map1'}.svg`,
+ fileName = localStorage.getItem('map') || (env === 'test' ? 'test_map' : 'map1'),
+ map = `assets/images/${fileName}.svg`,
toggleContentVis = (function () {
document.querySelectorAll('#content div').forEach(div => {
@@ -118,6 +119,14 @@ document.querySelectorAll('.end-move').forEach(el => el.addEventListener('click'
gameboard.endMove();
}));
+document.querySelector('#fullscreen').addEventListener('click', e => {
+ if (!document.fullscreenElement) {
+ document.documentElement.requestFullscreen();
+ } else if (document.exitFullscreen) {
+ document.exitFullscreen();
+ }
+});
+
contentVisToggleEl.checked = (localStorage.getItem('content-visibility') !== 'false');
toggleContentVis();
@@ -129,8 +138,18 @@ mapSelectDialog
.changeMapOnConfirm();
object.addEventListener('load', load);
+object.data = map;
objectDataObserver.observe(object, { attributeFilter: ['data'] });
-if (object.getAttribute('data') !== fileName) {
- object.data = fileName;
-}
+document.querySelector('#download-save').addEventListener('click', e => {
+ const data = 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);
+ element.click();
+ document.body.removeChild(element);
+});
--
cgit v1.2.3