-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonClick.js
More file actions
21 lines (19 loc) · 776 Bytes
/
onClick.js
File metadata and controls
21 lines (19 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { moveUp, moveDown } from './moves.js'
export function handleClick(event) {
if (!event.target.closest("[data-level]")) return;
const activeAncestor = event.target.closest('[tabindex="0"]');
if (!activeAncestor) return;
if (
activeAncestor.getAttribute("data-reverse") === "true" ||
activeAncestor.querySelector('[data-reverse="true"]')
) {
let newActiveNode = moveUp(activeAncestor);
if (!newActiveNode)
activeAncestor
.querySelectorAll('[data-reverse="true"]')
.forEach((node) => node.removeAttribute("data-reverse"));
return;
}
let newActiveNode = moveDown(activeAncestor);
if (!newActiveNode) activeAncestor.setAttribute("data-reverse", "true");
}