diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-22 19:14:07 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-22 19:14:07 +0800 |
| commit | e7715f530a25cd923581dfbbb847e22793f5cde3 (patch) | |
| tree | a5ec631689097f5942d799be1d91ea329cd3c52e /src | |
| parent | 99f80919d6a5546425c8b7418c4e874f8c99e69a (diff) | |
refactor: logic about overlap of draggable block
Diffstat (limited to 'src')
| -rw-r--r-- | src/Layout.mjs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Layout.mjs b/src/Layout.mjs index 789027b..d0fde0f 100644 --- a/src/Layout.mjs +++ b/src/Layout.mjs | |||
| @@ -59,6 +59,13 @@ export class Overlay extends Layout { | |||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | addDraggable = (element) => { | 61 | addDraggable = (element) => { |
| 62 | // Make sure current element always on top | ||
| 63 | const siblings = Array.from(element.parentElement?.querySelectorAll(':scope > *') ?? []) | ||
| 64 | element.onmouseover = () => { | ||
| 65 | siblings.forEach(e => e.style.removeProperty('z-index')) | ||
| 66 | element.style.zIndex = '9000' | ||
| 67 | } | ||
| 68 | |||
| 62 | // Add draggable part | 69 | // Add draggable part |
| 63 | const draggablePart = document.createElement('div') | 70 | const draggablePart = document.createElement('div') |
| 64 | element.appendChild(draggablePart) | 71 | element.appendChild(draggablePart) |
| @@ -83,18 +90,14 @@ export class Overlay extends Layout { | |||
| 83 | 90 | ||
| 84 | // FIXME use pure CSS to hide utils | 91 | // FIXME use pure CSS to hide utils |
| 85 | const utils = element.querySelector('.utils') | 92 | const utils = element.querySelector('.utils') |
| 86 | const siblings = Array.from(element.parentElement.querySelectorAll(':scope > *')) | ||
| 87 | draggable.onDragStart = () => { | 93 | draggable.onDragStart = () => { |
| 88 | utils.style.opacity = 0 | 94 | utils.style.display = 'none' |
| 89 | element.classList.add('drag') | 95 | element.classList.add('drag') |
| 90 | // Remove z-index from previous dragged | ||
| 91 | siblings.forEach(e => e.style.removeProperty('z-index')) | ||
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | draggable.onDragEnd = () => { | 98 | draggable.onDragEnd = () => { |
| 95 | utils.style = '' | 99 | utils.style = '' |
| 96 | element.classList.remove('drag') | 100 | element.classList.remove('drag') |
| 97 | // Ensuer last dragged block always on top | ||
| 98 | element.style.zIndex = '9000' | 101 | element.style.zIndex = '9000' |
| 99 | } | 102 | } |
| 100 | 103 | ||