-
Notifications
You must be signed in to change notification settings - Fork 10
/
mouseEvents.ts
53 lines (41 loc) · 1.37 KB
/
mouseEvents.ts
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
43
44
45
46
47
48
49
50
51
52
53
import * as R from 'ramda';
export function onMouseEnter() {
const win = require('electron').remote.getCurrentWindow();
win.setIgnoreMouseEvents(false);
}
export function onMouseLeave() {
const win = require('electron').remote.getCurrentWindow();
win.setIgnoreMouseEvents(true, {
forward: true
});
}
export function toTopZIndex(target: HTMLElement) {
const { parentElement } = target;
const { children } = parentElement as HTMLElement;
const tools = Array.from(children);
const maxIndex = Math.max.apply(
Math,
tools.map((t: HTMLElement) => parseInt(t.style.zIndex || '0', 10))
);
const nextIndex = maxIndex + 1;
const top = R.find(R.equals(target), tools) as HTMLElement;
top.style.zIndex = nextIndex;
}
export function onMouseDown(e: MouseEvent) {
const { currentTarget } = e;
toTopZIndex(currentTarget as HTMLElement);
}
export function startListeningToIgnoreMouseEvents(el) {
el.addEventListener('mouseenter', onMouseEnter);
el.addEventListener('mouseleave', onMouseLeave);
}
export function stopListeningToIgnoreMouseEvents(el) {
el.removeEventListener('mouseenter', onMouseEnter);
el.removeEventListener('mouseleave', onMouseLeave);
}
export function startListeningAndSwapZIndex(el) {
el.addEventListener('mousedown', onMouseDown);
}
export function stopListeningAndSwapZIndex(el) {
el.addEventListener('mousedown', onMouseDown);
}