|
20 | 20 | this.on('mouseleave', '#notifications-schedule .entry', this.onEntryLeave, this); |
21 | 21 | } |
22 | 22 |
|
| 23 | + /** |
| 24 | + * Make the sidebar sortable and add drag&drop support. |
| 25 | + * |
| 26 | + * @param event The event object. |
| 27 | + */ |
23 | 28 | onRendered(event) |
24 | 29 | { |
25 | 30 | if (event.target !== event.currentTarget) { |
|
46 | 51 | }); |
47 | 52 | } |
48 | 53 |
|
| 54 | + /** |
| 55 | + * Handle drop event on the sidebar. |
| 56 | + * |
| 57 | + * @param event The event object. |
| 58 | + */ |
49 | 59 | onDrop(event) |
50 | 60 | { |
51 | 61 | event = event.originalEvent; |
|
74 | 84 | form.requestSubmit(); |
75 | 85 | } |
76 | 86 |
|
| 87 | + /** |
| 88 | + * Handle hover (`mouseenter`) event on schedule entries. |
| 89 | + * |
| 90 | + * @param event The mouse event object. |
| 91 | + */ |
77 | 92 | onEntryHover(event) |
78 | 93 | { |
79 | | - const entry = event.currentTarget; |
80 | | - const overlay = entry.parentElement; |
81 | | - const grid = overlay.previousSibling; |
82 | | - const sideBar = grid.previousSibling; |
| 94 | + const [relatedEntries, tooltip] = event.data.self.identifyRelatedEntries(event); |
83 | 95 |
|
84 | | - let relatedElements; |
85 | | - if ('rotationPosition' in entry.dataset) { |
86 | | - relatedElements = Array.from( |
87 | | - grid.querySelectorAll('[data-y-position="' + entry.dataset.rotationPosition + '"]') |
88 | | - ); |
89 | | - |
90 | | - relatedElements.push(sideBar.childNodes[Number(entry.dataset.rotationPosition)]); |
91 | | - } else { |
92 | | - relatedElements = overlay.querySelectorAll( |
93 | | - '[data-rotation-position="' + entry.dataset.entryPosition + '"]' |
94 | | - ); |
95 | | - } |
96 | | - |
97 | | - relatedElements.forEach((relatedElement) => { |
98 | | - relatedElement.classList.add('highlighted'); |
99 | | - }); |
| 96 | + relatedEntries.forEach(element => element.classList.add('highlighted')); |
100 | 97 |
|
101 | | - const tooltip = entry.querySelector('.rotation-info'); |
102 | 98 | if (tooltip) { |
| 99 | + const grid = event.currentTarget.parentElement.previousSibling; |
103 | 100 | requestAnimationFrame(() => { |
104 | 101 | const tooltipRect = tooltip.getBoundingClientRect(); |
105 | 102 | const gridRect = grid.getBoundingClientRect(); |
|
114 | 111 | } |
115 | 112 | } |
116 | 113 |
|
| 114 | + /** |
| 115 | + * Handle hover (`mouseleave`) event on schedule entries. |
| 116 | + * |
| 117 | + * @param event The mouse event object. |
| 118 | + */ |
117 | 119 | onEntryLeave(event) |
118 | 120 | { |
| 121 | + const [relatedEntries, tooltip] = event.data.self.identifyRelatedEntries(event); |
| 122 | + |
| 123 | + relatedEntries.forEach(element => element.classList.remove('highlighted')); |
| 124 | + |
| 125 | + if (tooltip) { |
| 126 | + tooltip.classList.remove('is-left', 'is-bottom'); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Identify hover-related entries. |
| 132 | + * |
| 133 | + * @param event The mouse event object. |
| 134 | + * @returns {[HTMLElement[], HTMLElement|null]} |
| 135 | + */ |
| 136 | + identifyRelatedEntries(event) { |
119 | 137 | const entry = event.currentTarget; |
120 | 138 | const overlay = entry.parentElement; |
121 | 139 | const grid = overlay.previousSibling; |
122 | 140 | const sideBar = grid.previousSibling; |
123 | 141 |
|
124 | | - let relatedElements; |
| 142 | + let relatedEntries; |
125 | 143 | if ('rotationPosition' in entry.dataset) { |
126 | | - relatedElements = Array.from( |
| 144 | + relatedEntries = Array.from( |
127 | 145 | grid.querySelectorAll('[data-y-position="' + entry.dataset.rotationPosition + '"]') |
128 | 146 | ); |
129 | 147 |
|
130 | | - relatedElements.push(sideBar.childNodes[Number(entry.dataset.rotationPosition)]); |
| 148 | + relatedEntries.push(sideBar.childNodes[Number(entry.dataset.rotationPosition)]); |
131 | 149 | } else { |
132 | | - relatedElements = overlay.querySelectorAll( |
133 | | - '[data-rotation-position="' + entry.dataset.entryPosition + '"]' |
| 150 | + relatedEntries = Array.from( |
| 151 | + overlay.querySelectorAll('[data-rotation-position="' + entry.dataset.entryPosition + '"]') |
134 | 152 | ); |
135 | 153 | } |
136 | 154 |
|
137 | | - relatedElements.forEach((relatedElement) => { |
138 | | - relatedElement.classList.remove('highlighted'); |
139 | | - }); |
140 | | - |
141 | | - const tooltip = entry.querySelector('.rotation-info'); |
142 | | - if (tooltip) { |
143 | | - tooltip.classList.remove('is-left', 'is-bottom'); |
144 | | - } |
| 155 | + return [ |
| 156 | + relatedEntries, |
| 157 | + entry.querySelector('.rotation-info') |
| 158 | + ]; |
145 | 159 | } |
146 | 160 | } |
147 | 161 |
|
|
0 commit comments