Web Dev Solutions

Catalin Mititiuc

From 3e521e2f64809edc47f50f7215a6a05dd32b69dc Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sun, 28 Apr 2024 16:46:25 -0700 Subject: Rename element class 'board' to 'gameboard' --- src/map.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/map.js') 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]); -- cgit v1.2.3