diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-10 18:26:15 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-10 19:08:50 +0800 |
| commit | 963f1ecf81ca2938364b5defdad5bd059c851601 (patch) | |
| tree | 94872683cd0c0219e671f44b39e4946740a84b05 | |
| parent | 484f3e5b494c32d722e0ca98ad0e78e12cc82eb9 (diff) | |
feat: only show map id when select manually
| -rw-r--r-- | src/MenuItem.mjs | 6 | ||||
| -rw-r--r-- | src/css/dumbymap.css | 2 | ||||
| -rw-r--r-- | src/dumbyUtils.mjs | 2 | ||||
| -rw-r--r-- | src/dumbymap.mjs | 13 |
4 files changed, 17 insertions, 6 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index 8b54539..cffd4a7 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
| @@ -355,7 +355,11 @@ export const toggleBlockFocus = block => | |||
| 355 | export const toggleMapFocus = map => | 355 | export const toggleMapFocus = map => |
| 356 | new Item({ | 356 | new Item({ |
| 357 | text: 'Toggle Focus', | 357 | text: 'Toggle Focus', |
| 358 | onclick: () => map.classList.toggle('focus'), | 358 | onclick: () => { |
| 359 | if (map.classList.toggle('focus')) { | ||
| 360 | map.classList.add('focus-manual') | ||
| 361 | } | ||
| 362 | }, | ||
| 359 | }) | 363 | }) |
| 360 | 364 | ||
| 361 | /** | 365 | /** |
diff --git a/src/css/dumbymap.css b/src/css/dumbymap.css index 4a7bf4f..fe6c0d7 100644 --- a/src/css/dumbymap.css +++ b/src/css/dumbymap.css | |||
| @@ -68,7 +68,7 @@ a[href^='http']:not(:has(img))::after, | |||
| 68 | 68 | ||
| 69 | transition: flex-basis 300ms ease-in-out; | 69 | transition: flex-basis 300ms ease-in-out; |
| 70 | 70 | ||
| 71 | &.focus::after { | 71 | &.focus.focus-manual::after { |
| 72 | content: 'Map-ID: ' attr(id); | 72 | content: 'Map-ID: ' attr(id); |
| 73 | padding: 0.3rem 0.5rem; | 73 | padding: 0.3rem 0.5rem; |
| 74 | 74 | ||
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 8148366..170cb16 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
| @@ -12,7 +12,7 @@ export function focusNextMap (reverse = false) { | |||
| 12 | const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length | 12 | const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length |
| 13 | 13 | ||
| 14 | const nextMap = renderedList.at(nextIndex) | 14 | const nextMap = renderedList.at(nextIndex) |
| 15 | nextMap.classList.add('focus') | 15 | nextMap.classList.add('focus', 'focus-manual') |
| 16 | nextMap.scrollIntoView({ behavior: 'smooth' }) | 16 | nextMap.scrollIntoView({ behavior: 'smooth' }) |
| 17 | } | 17 | } |
| 18 | 18 | ||
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index b01c73e..35a4614 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
| @@ -173,7 +173,7 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
| 173 | * mapFocusObserver. observe for map focus | 173 | * mapFocusObserver. observe for map focus |
| 174 | * @return {MutationObserver} observer | 174 | * @return {MutationObserver} observer |
| 175 | */ | 175 | */ |
| 176 | const mapFocusObserver = () => | 176 | const mapClassObserver = () => |
| 177 | new window.MutationObserver(mutations => { | 177 | new window.MutationObserver(mutations => { |
| 178 | const mutation = mutations.at(-1) | 178 | const mutation = mutations.at(-1) |
| 179 | const target = mutation.target | 179 | const target = mutation.target |
| @@ -191,6 +191,13 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
| 191 | .renderedMaps() | 191 | .renderedMaps() |
| 192 | .filter(map => map.id !== target.id) | 192 | .filter(map => map.id !== target.id) |
| 193 | .forEach(map => map.classList.remove('focus')) | 193 | .forEach(map => map.classList.remove('focus')) |
| 194 | |||
| 195 | if (target.classList.contains('focus-manual')) { | ||
| 196 | setTimeout( | ||
| 197 | () => target.classList.remove('focus-manual'), | ||
| 198 | 2000, | ||
| 199 | ) | ||
| 200 | } | ||
| 194 | } | 201 | } |
| 195 | 202 | ||
| 196 | if (shouldBeInShowcase) { | 203 | if (shouldBeInShowcase) { |
| @@ -304,7 +311,7 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
| 304 | renderCallback?.(renderer) | 311 | renderCallback?.(renderer) |
| 305 | 312 | ||
| 306 | // Work with Mutation Observer | 313 | // Work with Mutation Observer |
| 307 | const observer = mapFocusObserver() | 314 | const observer = mapClassObserver() |
| 308 | observer.observe(mapElement, { | 315 | observer.observe(mapElement, { |
| 309 | attributes: true, | 316 | attributes: true, |
| 310 | attributeFilter: ['class'], | 317 | attributeFilter: ['class'], |
| @@ -511,4 +518,4 @@ export const generateMaps = (container, { layouts = [], delay, renderCallback } | |||
| 511 | ) | 518 | ) |
| 512 | 519 | ||
| 513 | return Object.seal(dumbymap) | 520 | return Object.seal(dumbymap) |
| 514 | } \ No newline at end of file | 521 | } |