forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addVerticalBar.js
43 lines (30 loc) 路 844 Bytes
/
addVerticalBar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export function addVerticalBar(state, bodyListener) {
let moveBar = false;
bodyListener("mousedown", ".vertical-bar", (e) => {
moveBar = true;
});
bodyListener("mousemove", "", (e) => {
if (!moveBar) return;
let x = ((e.clientX - 30) / (window.innerWidth - 40)) * 100;
if (x === 0) return;
const minX = 2;
const maxX = 98;
if (x < minX) x = minX;
if (x > maxX) x = maxX;
document.documentElement.style.setProperty("--editor-width", `${x}%`);
pauseEvent(e);
});
bodyListener("mouseup", "", (e) => {
moveBar = false;
});
bodyListener("mouseleave", "", (e) => {
moveBar = false;
});
}
function pauseEvent(e) {
if (e.stopPropagation) e.stopPropagation();
if (e.preventDefault) e.preventDefault();
e.cancelBubble = true;
e.returnValue = false;
return false;
}