diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-17 12:40:50 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-17 21:32:49 +0800 |
commit | 4dd0fa87859e6ffa1b230eedd1388098a8ba81a1 (patch) | |
tree | bd1c163a4091c812cfe6b569aeb38c439f97b56c /src/dumbymap.mjs | |
parent | 5cbe9c55eca1b5b0a264414f9a255ea2d019d6e2 (diff) |
feat: set "sticky" as one of default layouts
* move function addDraggable() into module scope
* showcase in sticky layout is draggable now
* add query paramerter for "use"
* FIX: set initialLayout after observer is set
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index b612367..13f4574 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -5,7 +5,7 @@ import MarkdownItFrontMatter from 'markdown-it-front-matter' | |||
5 | import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' | 5 | import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' |
6 | import * as mapclay from 'mapclay' | 6 | import * as mapclay from 'mapclay' |
7 | import { replaceTextNodes, onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' | 7 | import { replaceTextNodes, onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' |
8 | import { Layout, SideBySide, Overlay } from './Layout' | 8 | import { Layout, SideBySide, Overlay, Sticky } from './Layout' |
9 | import * as utils from './dumbyUtils' | 9 | import * as utils from './dumbyUtils' |
10 | import * as menuItem from './MenuItem' | 10 | import * as menuItem from './MenuItem' |
11 | import PlainModal from 'plain-modal' | 11 | import PlainModal from 'plain-modal' |
@@ -23,6 +23,7 @@ const defaultLayouts = [ | |||
23 | new Layout({ name: 'normal' }), | 23 | new Layout({ name: 'normal' }), |
24 | new SideBySide({ name: 'side-by-side' }), | 24 | new SideBySide({ name: 'side-by-side' }), |
25 | new Overlay({ name: 'overlay' }), | 25 | new Overlay({ name: 'overlay' }), |
26 | new Sticky({ name: 'sticky' }), | ||
26 | ] | 27 | ] |
27 | 28 | ||
28 | /** Cache across every dumbymap generation */ | 29 | /** Cache across every dumbymap generation */ |
@@ -169,13 +170,12 @@ export const generateMaps = (container, { | |||
169 | /** Prepare Contaner */ | 170 | /** Prepare Contaner */ |
170 | container.classList.add('Dumby') | 171 | container.classList.add('Dumby') |
171 | delete container.dataset.layout | 172 | delete container.dataset.layout |
172 | container.dataset.layout = initialLayout ?? defaultLayouts[0].name | ||
173 | 173 | ||
174 | /** Prepare Semantic HTML part and blocks of contents inside */ | 174 | /** Prepare Semantic HTML part and blocks of contents inside */ |
175 | const htmlHolder = container.querySelector('.SemanticHtml') ?? | 175 | const htmlHolder = container.querySelector('.SemanticHtml') ?? |
176 | Array.from(container.children).find(e => e.id?.includes('main') || e.className.includes('main')) ?? | 176 | Array.from(container.children).find(e => e.id?.includes('main') || e.className.includes('main')) ?? |
177 | Array.from(container.children).sort((a, b) => a.textContent.length < b.textContent.length).at(0) | 177 | Array.from(container.children).sort((a, b) => a.textContent.length < b.textContent.length).at(0) |
178 | htmlHolder.classList.add('.SemanticHtml') | 178 | htmlHolder.classList.add('SemanticHtml') |
179 | 179 | ||
180 | const blocks = addBlocks(htmlHolder) | 180 | const blocks = addBlocks(htmlHolder) |
181 | blocks.forEach(b => { | 181 | blocks.forEach(b => { |
@@ -280,13 +280,7 @@ export const generateMaps = (container, { | |||
280 | const mutation = mutations.at(-1) | 280 | const mutation = mutations.at(-1) |
281 | const target = mutation.target | 281 | const target = mutation.target |
282 | const focus = target.classList.contains('focus') | 282 | const focus = target.classList.contains('focus') |
283 | const shouldBeInShowcase = | 283 | const shouldBeInShowcase = focus && showcase.checkVisibility() |
284 | focus && | ||
285 | showcase.checkVisibility({ | ||
286 | contentVisibilityAuto: true, | ||
287 | opacityProperty: true, | ||
288 | visibilityProperty: true, | ||
289 | }) | ||
290 | 284 | ||
291 | if (focus) { | 285 | if (focus) { |
292 | dumbymap.utils | 286 | dumbymap.utils |
@@ -393,6 +387,7 @@ export const generateMaps = (container, { | |||
393 | }) | 387 | }) |
394 | 388 | ||
395 | onRemove(htmlHolder, () => layoutObserver.disconnect()) | 389 | onRemove(htmlHolder, () => layoutObserver.disconnect()) |
390 | container.dataset.layout = initialLayout ?? defaultLayouts[0].name | ||
396 | 391 | ||
397 | /** | 392 | /** |
398 | * afterMapRendered. callback of each map rendered | 393 | * afterMapRendered. callback of each map rendered |