diff options
Diffstat (limited to 'src/OverlayLayout.mjs')
-rw-r--r-- | src/OverlayLayout.mjs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/OverlayLayout.mjs b/src/OverlayLayout.mjs index c87033b..8b4e073 100644 --- a/src/OverlayLayout.mjs +++ b/src/OverlayLayout.mjs | |||
@@ -10,11 +10,18 @@ export class OverlayLayout { | |||
10 | // Create draggable block | 10 | // Create draggable block |
11 | const draggableBlock = document.createElement('div') | 11 | const draggableBlock = document.createElement('div') |
12 | draggableBlock.classList.add('draggable-block') | 12 | draggableBlock.classList.add('draggable-block') |
13 | draggableBlock.innerHTML = ` | ||
14 | <div class="draggable"> | ||
15 | <div class="handle">\u2630</div> | ||
16 | </div> | ||
17 | <div class="utils"> | ||
18 | <div id="plus-font-size" ">\u2795</div> | ||
19 | <div id="minus-font-size">\u2796</div> | ||
20 | </div> | ||
21 | ` | ||
13 | 22 | ||
14 | // Add draggable part | 23 | // Add draggable part |
15 | const draggablePart = document.createElement('div'); | 24 | const draggablePart = draggableBlock.querySelector('.draggable') |
16 | draggablePart.classList.add('draggable') | ||
17 | draggablePart.textContent = '☰' | ||
18 | draggablePart.title = 'Use middle-click to remove block' | 25 | draggablePart.title = 'Use middle-click to remove block' |
19 | draggablePart.onmouseup = (e) => { | 26 | draggablePart.onmouseup = (e) => { |
20 | if (e.button === 1) { | 27 | if (e.button === 1) { |
@@ -34,6 +41,26 @@ export class OverlayLayout { | |||
34 | snap: { x: { step: 20 }, y: { step: 20 } }, | 41 | snap: { x: { step: 20 }, y: { step: 20 } }, |
35 | }) | 42 | }) |
36 | 43 | ||
44 | // Plus/Minus font-size of content | ||
45 | const plusButton = draggableBlock.querySelector('#plus-font-size') | ||
46 | plusButton.onclick = () => { | ||
47 | const fontSize = parseFloat(getComputedStyle(block).fontSize) / 16 | ||
48 | block.style.fontSize = `${fontSize + 0.1}rem` | ||
49 | } | ||
50 | const minusButton = draggableBlock.querySelector('#minus-font-size') | ||
51 | minusButton.onclick = () => { | ||
52 | const fontSize = parseFloat(getComputedStyle(block).fontSize) / 16 | ||
53 | block.style.fontSize = `${fontSize - 0.1}rem` | ||
54 | } | ||
55 | draggableInstance.onDragStart = () => { | ||
56 | plusButton.style.opacity = '0' | ||
57 | minusButton.style.opacity = '0' | ||
58 | } | ||
59 | draggableInstance.onDragEnd = () => { | ||
60 | plusButton.style = '' | ||
61 | minusButton.style = '' | ||
62 | } | ||
63 | |||
37 | // Reposition draggable instance when resized | 64 | // Reposition draggable instance when resized |
38 | new ResizeObserver(() => { | 65 | new ResizeObserver(() => { |
39 | try { | 66 | try { |