From 924864fc7434518ee0ae688f9be9d3086ba4b3f5 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 17 Oct 2024 23:20:45 +0800 Subject: fix: don't apply dumbymap twice --- addon/index.mjs | 22 ++++++++++++++++------ src/dumbymap.mjs | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/addon/index.mjs b/addon/index.mjs index 77716b6..4de11e0 100644 --- a/addon/index.mjs +++ b/addon/index.mjs @@ -34,10 +34,20 @@ const simpleRender = window.mapclay.renderWith(config => ({ }, })) -window.generateMaps(document.querySelector('main') ?? document.body, { - crs: url.searchParams.get('crs') ?? 'EPSG:4326', - addBlocks, - initialLayout: 'sticky', - render: simpleRender, - autoMap: true, +if (!document.querySelector('.Dumby')) { + window.generateMaps(document.querySelector('main') ?? document.body, { + crs: url.searchParams.get('crs') ?? 'EPSG:4326', + addBlocks, + initialLayout: 'sticky', + render: simpleRender, + autoMap: true, + }) +} + +new window.MutationObserver((ms) => { + for (const m of ms) { + console.log(m) + } +}).observe(document.querySelector('#doc'), { + childList: true, }) diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 13f4574..e9cb473 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs @@ -457,6 +457,7 @@ export const generateMaps = (container, { const mapContainer = document.createElement('pre') mapContainer.className = 'mapclay-container' mapContainer.textContent = '#Created by DumbyMap' + mapContainer.style.cssText = 'display: none;' htmlHolder.insertBefore(mapContainer, htmlHolder.firstElementChild) elementsWithMapConfig.push(mapContainer) } -- cgit v1.2.3-70-g09d2