index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-17 10:20:15 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-17 10:20:15 -0700 |
commit | 4229c732bca15f4563f596ca345d576984bc517a (patch) | |
tree | bc26701b2a96d0f6dfe813d252efff1420c4f0ed /src/index.js | |
parent | 460027e96507c8015878a03f14508bd50d68e97f (diff) |
Use JS for damage indicator changes instead of CSS
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/index.js b/src/index.js index a0a99f4..fd679d2 100644 --- a/src/index.js +++ b/src/index.js @@ -3,18 +3,23 @@ import Game from './modules/game.js'; const PanZoom = new function () { const vb = 'viewBox'; + let svg; - function storeLatestViewBoxVal(svg) { + function storeViewBoxVal() { + localStorage.setItem(vb, svg.getAttribute(vb)); + } + + function observeViewBoxChanges() { const observer = new MutationObserver(mutations => { if (mutations.find(m => m.target == svg && m.attributeName == vb)) { - localStorage.setItem(vb, svg.getAttribute(vb)); + storeViewBoxVal(svg); } }); observer.observe(svg, { attributes: true }); } - function restoreViewboxVal(svg) { + function restoreViewBoxVal() { const storedVbVal = localStorage.getItem(vb); if (storedVbVal) { @@ -22,9 +27,7 @@ const PanZoom = new function () { } } - this.start = function (svg) { - restoreViewboxVal(svg); - + function addEventListeners() { svg.addEventListener('wheel', e => { e.preventDefault(); @@ -36,8 +39,13 @@ const PanZoom = new function () { pan(svg, e); }, { passive: false }); + } - storeLatestViewBoxVal(svg); + this.start = function (el) { + svg = el; + restoreViewBoxVal(); + addEventListeners(); + observeViewBoxChanges(); }; }; |