diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 10:29:54 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 12:17:22 +0800 |
commit | 8d161bfb1f014a3184ab7111f7cd39b3c253f552 (patch) | |
tree | 42f6dadd251fb80bfc32571a1dc4276fc9a4b079 /src/dumbymap.mjs | |
parent | c7ac371639e223282efff546c198428f736232f0 (diff) |
feat: add focusNextBlock util
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 01463c0..d7c822a 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -175,6 +175,22 @@ function switchToNextLayout(reverse = false) { | |||
175 | this.container.setAttribute("data-layout", nextLayout.name) | 175 | this.container.setAttribute("data-layout", nextLayout.name) |
176 | } | 176 | } |
177 | 177 | ||
178 | function focusNextBlock(reverse = false) { | ||
179 | const blocks = this.blocks.filter(b=>b.checkVisibility({ | ||
180 | contentVisibilityAuto: true, | ||
181 | opacityProperty: true, | ||
182 | visibilityProperty: true, | ||
183 | })) | ||
184 | const currentBlock = blocks.find(b=>b.classList.contains('focus')) | ||
185 | const currentIndex = blocks.indexOf(currentBlock) | ||
186 | const padding = reverse ? -1 : 1 | ||
187 | const nextIndex = currentIndex === -1 ? 0 : (currentIndex + padding + blocks.length) % blocks.length | ||
188 | const nextBlock = blocks[nextIndex] | ||
189 | blocks.forEach(b=>b.classList.remove('focus')) | ||
190 | nextBlock?.classList?.add('focus') | ||
191 | nextBlock.scrollIntoView({behavior: 'smooth', block: "nearest"}) | ||
192 | } | ||
193 | |||
178 | export const generateMaps = (container, callback) => { | 194 | export const generateMaps = (container, callback) => { |
179 | container.classList.add('Dumby') | 195 | container.classList.add('Dumby') |
180 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container | 196 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container |