diff options
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 906d9b2..0c7ff02 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -56,7 +56,7 @@ export const markdown2HTML = (container, mdContent) => { | |||
56 | const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/ | 56 | const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/ |
57 | const coordinateValue = { | 57 | const coordinateValue = { |
58 | validate: coordinateRegex, | 58 | validate: coordinateRegex, |
59 | normalize: function(match) { | 59 | normalize: function (match) { |
60 | const [, , x, sep, y] = match.text.match(coordinateRegex) | 60 | const [, , x, sep, y] = match.text.match(coordinateRegex) |
61 | match.url = `geo:${y},${x}?xy=${x},${y}` | 61 | match.url = `geo:${y},${x}?xy=${x},${y}` |
62 | match.text = `${x}${sep} ${y}` | 62 | match.text = `${x}${sep} ${y}` |
@@ -99,7 +99,7 @@ export const markdown2HTML = (container, mdContent) => { | |||
99 | const blocks = htmlHolder.querySelectorAll(':scope > div:not(:has(nav))') | 99 | const blocks = htmlHolder.querySelectorAll(':scope > div:not(:has(nav))') |
100 | blocks.forEach(b => { | 100 | blocks.forEach(b => { |
101 | b.classList.add('dumby-block') | 101 | b.classList.add('dumby-block') |
102 | b.setAttribute('data-total', blocks.length) | 102 | b.dataset.total = blocks.length |
103 | }) | 103 | }) |
104 | 104 | ||
105 | return container | 105 | return container |
@@ -113,11 +113,10 @@ export const markdown2HTML = (container, mdContent) => { | |||
113 | * @return {Object} dumbymap -- Include and Elements and Methods about managing contents | 113 | * @return {Object} dumbymap -- Include and Elements and Methods about managing contents |
114 | */ | 114 | */ |
115 | export const generateMaps = (container, { layouts = [], delay, renderCallback } = {}) => { | 115 | export const generateMaps = (container, { layouts = [], delay, renderCallback } = {}) => { |
116 | |||
117 | /** Prepare Contaner/HTML Holder/Showcase */ | 116 | /** Prepare Contaner/HTML Holder/Showcase */ |
118 | container.classList.add('Dumby') | 117 | container.classList.add('Dumby') |
119 | container.removeAttribute('data-layout') | 118 | delete container.dataset.layout |
120 | container.setAttribute('data-layout', defaultLayouts[0].name) | 119 | container.dataset.layout = defaultLayouts[0].name |
121 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container | 120 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container |
122 | const blocks = Array.from(htmlHolder.querySelectorAll('.dumby-block')) | 121 | const blocks = Array.from(htmlHolder.querySelectorAll('.dumby-block')) |
123 | const showcase = document.createElement('div') | 122 | const showcase = document.createElement('div') |
@@ -197,7 +196,7 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
197 | 196 | ||
198 | // Placeholder for map in Showcase, it should has the same DOMRect | 197 | // Placeholder for map in Showcase, it should has the same DOMRect |
199 | const placeholder = target.cloneNode(true) | 198 | const placeholder = target.cloneNode(true) |
200 | placeholder.removeAttribute('id') | 199 | delete placeholder.id |
201 | placeholder.className = '' | 200 | placeholder.className = '' |
202 | 201 | ||
203 | const parent = target.parentElement | 202 | const parent = target.parentElement |
@@ -212,10 +211,10 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
212 | // To make sure the original height of placeholder is applied, DOM changes seems needed | 211 | // To make sure the original height of placeholder is applied, DOM changes seems needed |
213 | // then set data-attribute for CSS selector to change height to 0 | 212 | // then set data-attribute for CSS selector to change height to 0 |
214 | placeholder.getBoundingClientRect() | 213 | placeholder.getBoundingClientRect() |
215 | placeholder.setAttribute('data-placeholder', target.id) | 214 | placeholder.dataset.placeholder = target.id |
216 | 215 | ||
217 | // To fit showcase, remove all inline style | 216 | // To fit showcase, remove all inline style |
218 | target.removeAttribute('style') | 217 | target.style.cssText = '' |
219 | target.style.order = placeholder.style.order | 218 | target.style.order = placeholder.style.order |
220 | showcase.appendChild(target) | 219 | showcase.appendChild(target) |
221 | 220 | ||
@@ -248,7 +247,7 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
248 | const layoutObserver = new window.MutationObserver(mutations => { | 247 | const layoutObserver = new window.MutationObserver(mutations => { |
249 | const mutation = mutations.at(-1) | 248 | const mutation = mutations.at(-1) |
250 | const oldLayout = mutation.oldValue | 249 | const oldLayout = mutation.oldValue |
251 | const newLayout = container.getAttribute(mutation.attributeName) | 250 | const newLayout = container.dataset.layout |
252 | 251 | ||
253 | // Apply handler for leaving/entering layouts | 252 | // Apply handler for leaving/entering layouts |
254 | if (oldLayout) { | 253 | if (oldLayout) { |
@@ -260,7 +259,7 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
260 | Object.values(dumbymap) | 259 | Object.values(dumbymap) |
261 | .flat() | 260 | .flat() |
262 | .filter(ele => ele instanceof window.HTMLElement) | 261 | .filter(ele => ele instanceof window.HTMLElement) |
263 | .forEach(ele => ele.removeAttribute('style')) | 262 | .forEach(ele => { ele.style.cssText = '' }) |
264 | 263 | ||
265 | if (newLayout) { | 264 | if (newLayout) { |
266 | dumbymap.layouts | 265 | dumbymap.layouts |
@@ -293,8 +292,8 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
293 | const mapElement = renderer.target | 292 | const mapElement = renderer.target |
294 | // FIXME | 293 | // FIXME |
295 | mapElement.renderer = renderer | 294 | mapElement.renderer = renderer |
296 | mapElement.setAttribute('tabindex', '-1') | 295 | mapElement.tabindex = -1 |
297 | if (mapElement.getAttribute('data-render') === 'fulfilled') { | 296 | if (mapElement.dataset.render === 'fulfilled') { |
298 | mapCache[mapElement.id] ??= renderer | 297 | mapCache[mapElement.id] ??= renderer |
299 | } else { | 298 | } else { |
300 | return | 299 | return |
@@ -354,9 +353,9 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
354 | target.animations = target.animations.then(async () => { | 353 | target.animations = target.animations.then(async () => { |
355 | await new Promise(resolve => setTimeout(resolve, 100)) | 354 | await new Promise(resolve => setTimeout(resolve, 100)) |
356 | if (final) passNum += '\x20' | 355 | if (final) passNum += '\x20' |
357 | target.setAttribute('data-report', passNum) | 356 | target.dataset.report = passNum |
358 | 357 | ||
359 | if (final) setTimeout(() => target.removeAttribute('data-report'), 100) | 358 | if (final) setTimeout(() => delete target.dataset.report, 100) |
360 | }) | 359 | }) |
361 | } | 360 | } |
362 | /** | 361 | /** |