Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-28 16:46:25 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-28 16:46:25 -0700
commit3e521e2f64809edc47f50f7215a6a05dd32b69dc (patch)
treec82fcea9de791b5090383a4cbf3ad10a92cc06e0 /src/map.js
parent4ce55ea0cd7db1077bc7919ee976458c900c968c (diff)
Rename element class 'board' to 'gameboard'
Diffstat (limited to 'src/map.js')
-rw-r--r--src/map.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/map.js b/src/map.js
index 7a04626..06b6ce6 100644
--- a/src/map.js
+++ b/src/map.js
@@ -1,18 +1,21 @@
const svgns = "http://www.w3.org/2000/svg";
+const dataset = document.currentScript.dataset;
const svg = document.querySelector('svg');
-const cellTemplate = svg.querySelector('#hex');
const gb = svg.querySelector('.gameboard');
const bg = svg.querySelector('#background');
const imageMaps = svg.querySelector('#image-maps');
-const grid = gb.querySelector('.grid');
-const dataset = document.currentScript.dataset;
+
if ('cols' in dataset && 'rows' in dataset) {
+ const cellTemplate = svg.querySelector('#hex');
+ const grid = gb.querySelector('.grid');
+
createCells(grid, dataset, cellTemplate.id);
- setElAttrs(bg, calcComputedBboxFor(imageMaps));
- svg.setAttribute('viewBox', formatForViewBox(calcComputedBboxFor(gb)));
}
+setElAttrs(bg, calcComputedBboxFor(imageMaps));
+svg.setAttribute('viewBox', formatForViewBox(calcComputedBboxFor(gb)));
+
function setElAttrs(el, attrs) {
for (key in attrs) {
el.setAttributeNS(null, key, attrs[key]);