diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Layout.mjs | 14 | ||||
-rw-r--r-- | src/dumbyUtils.mjs | 4 | ||||
-rw-r--r-- | src/dumbymap.mjs | 27 | ||||
-rw-r--r-- | src/editor.mjs | 18 |
4 files changed, 33 insertions, 30 deletions
diff --git a/src/Layout.mjs b/src/Layout.mjs index c5276b4..5236475 100644 --- a/src/Layout.mjs +++ b/src/Layout.mjs | |||
@@ -64,7 +64,7 @@ export class SideBySide extends Layout { | |||
64 | resizeByLeft(pos.left) | 64 | resizeByLeft(pos.left) |
65 | } | 65 | } |
66 | draggable.onDragEnd = _ => { | 66 | draggable.onDragEnd = _ => { |
67 | handle.removeAttribute('style') | 67 | handle.style.cssText = '' |
68 | } | 68 | } |
69 | 69 | ||
70 | onRemove(bar, () => draggable.remove()) | 70 | onRemove(bar, () => draggable.remove()) |
@@ -98,8 +98,8 @@ export class Overlay extends Layout { | |||
98 | */ | 98 | */ |
99 | saveLeftTopAsData = element => { | 99 | saveLeftTopAsData = element => { |
100 | const { left, top } = element.getBoundingClientRect() | 100 | const { left, top } = element.getBoundingClientRect() |
101 | element.setAttribute('data-left', left) | 101 | element.dataset.left = left |
102 | element.setAttribute('data-top', top) | 102 | element.dataset.top = top |
103 | } | 103 | } |
104 | 104 | ||
105 | /** | 105 | /** |
@@ -178,8 +178,8 @@ export class Overlay extends Layout { | |||
178 | // Create draggable blocks and set each position by previous one | 178 | // Create draggable blocks and set each position by previous one |
179 | let [left, top] = [20, 20] | 179 | let [left, top] = [20, 20] |
180 | blocks.forEach(block => { | 180 | blocks.forEach(block => { |
181 | const originLeft = Number(block.getAttribute('data-left')) | 181 | const originLeft = Number(block.dataset.left) |
182 | const originTop = Number(block.getAttribute('data-top')) | 182 | const originTop = Number(block.dataset.top) |
183 | 183 | ||
184 | // Create draggable block | 184 | // Create draggable block |
185 | const wrapper = document.createElement('div') | 185 | const wrapper = document.createElement('div') |
@@ -229,13 +229,13 @@ export class Overlay extends Layout { | |||
229 | } | 229 | } |
230 | utils.onmouseout = () => { | 230 | utils.onmouseout = () => { |
231 | wrapper.appendChild(utils) | 231 | wrapper.appendChild(utils) |
232 | utils.removeAttribute('style') | 232 | utils.style.cssText = '' |
233 | } | 233 | } |
234 | 234 | ||
235 | // Close button | 235 | // Close button |
236 | wrapper.querySelector('#close').onclick = () => { | 236 | wrapper.querySelector('#close').onclick = () => { |
237 | block.classList.remove('focus') | 237 | block.classList.remove('focus') |
238 | utils.removeAttribute('style') | 238 | utils.style.cssText = '' |
239 | } | 239 | } |
240 | // Plus/Minus font-size of content | 240 | // Plus/Minus font-size of content |
241 | wrapper.querySelector('#plus-font-size').onclick = () => { | 241 | wrapper.querySelector('#plus-font-size').onclick = () => { |
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index fde4dae..83d24c0 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
@@ -67,7 +67,7 @@ export function focusDelay () { | |||
67 | */ | 67 | */ |
68 | export function switchToNextLayout (reverse = false) { | 68 | export function switchToNextLayout (reverse = false) { |
69 | const layouts = this.layouts | 69 | const layouts = this.layouts |
70 | const currentLayoutName = this.container.getAttribute('data-layout') | 70 | const currentLayoutName = this.container.dataset.layout |
71 | const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) | 71 | const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) |
72 | const padding = reverse ? -1 : 1 | 72 | const padding = reverse ? -1 : 1 |
73 | const nextIndex = | 73 | const nextIndex = |
@@ -75,7 +75,7 @@ export function switchToNextLayout (reverse = false) { | |||
75 | ? 0 | 75 | ? 0 |
76 | : (currentIndex + padding + layouts.length) % layouts.length | 76 | : (currentIndex + padding + layouts.length) % layouts.length |
77 | const nextLayout = layouts[nextIndex] | 77 | const nextLayout = layouts[nextIndex] |
78 | this.container.setAttribute('data-layout', nextLayout.name) | 78 | this.container.dataset.layout = nextLayout.name |
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
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 | /** |
diff --git a/src/editor.mjs b/src/editor.mjs index a8cccf2..ed63f9c 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -34,10 +34,10 @@ const appendRefLink = ({ cm, ref, link }) => { | |||
34 | * and the layout is not 'normal', it sets the layout to 'normal' and switch to editing mode | 34 | * and the layout is not 'normal', it sets the layout to 'normal' and switch to editing mode |
35 | */ | 35 | */ |
36 | new window.MutationObserver(() => { | 36 | new window.MutationObserver(() => { |
37 | const mode = context.getAttribute('data-mode') | 37 | const mode = context.dataset.mode |
38 | const layout = dumbyContainer.getAttribute('data-layout') | 38 | const layout = dumbyContainer.dataset.layout |
39 | if (mode === 'editing' && layout !== 'normal') { | 39 | if (mode === 'editing' && layout !== 'normal') { |
40 | dumbyContainer.setAttribute('data-layout', 'normal') | 40 | dumbyContainer.dataset.layout = 'normal' |
41 | } | 41 | } |
42 | }).observe(context, { | 42 | }).observe(context, { |
43 | attributes: true, | 43 | attributes: true, |
@@ -48,8 +48,12 @@ new window.MutationObserver(() => { | |||
48 | * toggleEditing: toggle editing mode | 48 | * toggleEditing: toggle editing mode |
49 | */ | 49 | */ |
50 | const toggleEditing = () => { | 50 | const toggleEditing = () => { |
51 | const mode = context.getAttribute('data-mode') | 51 | const mode = context.dataset.mode |
52 | context.setAttribute('data-mode', mode === 'editing' ? '' : 'editing') | 52 | if (mode === 'editing') { |
53 | delete context.dataset.mode | ||
54 | } else { | ||
55 | context.dataset.mode = 'editing' | ||
56 | } | ||
53 | } | 57 | } |
54 | // }}} | 58 | // }}} |
55 | // Set up EasyMDE {{{ | 59 | // Set up EasyMDE {{{ |
@@ -949,9 +953,9 @@ document.onkeydown = e => { | |||
949 | // Layout Switch {{{ | 953 | // Layout Switch {{{ |
950 | new window.MutationObserver(mutaions => { | 954 | new window.MutationObserver(mutaions => { |
951 | const mutation = mutaions.at(-1) | 955 | const mutation = mutaions.at(-1) |
952 | const layout = dumbyContainer.getAttribute('data-layout') | 956 | const layout = dumbyContainer.dataset.layout |
953 | if (layout !== 'normal' || mutation.oldValue === 'normal') { | 957 | if (layout !== 'normal' || mutation.oldValue === 'normal') { |
954 | context.setAttribute('data-mode', '') | 958 | delete context.dataset.mode |
955 | } | 959 | } |
956 | }).observe(dumbyContainer, { | 960 | }).observe(dumbyContainer, { |
957 | attributes: true, | 961 | attributes: true, |