()
| 215 | } |
| 216 | |
| 217 | function initMenus() { |
| 218 | 'use strict'; |
| 219 | |
| 220 | let activeMenu = null; |
| 221 | let activeMenuHdr = null; |
| 222 | |
| 223 | function cancelActiveMenu() { |
| 224 | if (activeMenu == null) return; |
| 225 | activeMenu.style.display = 'none'; |
| 226 | activeMenu = null; |
| 227 | activeMenuHdr = null; |
| 228 | } |
| 229 | |
| 230 | // Set click handlers on every menu header. |
| 231 | for (const menu of document.getElementsByClassName('submenu')) { |
| 232 | const hdr = menu.parentElement; |
| 233 | if (hdr == null) return; |
| 234 | if (hdr.classList.contains('disabled')) return; |
| 235 | function showMenu(e) { |
| 236 | // menu is a child of hdr, so this event can fire for clicks |
| 237 | // inside menu. Ignore such clicks. |
| 238 | if (e.target.parentElement != hdr) return; |
| 239 | activeMenu = menu; |
| 240 | activeMenuHdr = hdr; |
| 241 | menu.style.display = 'block'; |
| 242 | } |
| 243 | hdr.addEventListener('mousedown', showMenu); |
| 244 | hdr.addEventListener('touchstart', showMenu); |
| 245 | } |
| 246 | |
| 247 | // If there is an active menu and a down event outside, retract the menu. |
| 248 | for (const t of ['mousedown', 'touchstart']) { |
| 249 | document.addEventListener(t, (e) => { |
| 250 | // Note: to avoid unnecessary flicker, if the down event is inside |
| 251 | // the active menu header, do not retract the menu. |
| 252 | if (activeMenuHdr != e.target.closest('.menu-item')) { |
| 253 | cancelActiveMenu(); |
| 254 | } |
| 255 | }, { passive: true, capture: true }); |
| 256 | } |
| 257 | |
| 258 | // If there is an active menu and an up event inside, retract the menu. |
| 259 | document.addEventListener('mouseup', (e) => { |
| 260 | if (activeMenu == e.target.closest('.submenu')) { |
| 261 | cancelActiveMenu(); |
| 262 | } |
| 263 | }, { passive: true, capture: true }); |
| 264 | } |
| 265 | |
| 266 | function sendURL(method, url, done) { |
| 267 | fetch(url.toString(), {method: method}) |
no test coverage detected
searching dependent graphs…