-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseshortcuts.js
46 lines (46 loc) · 1.43 KB
/
mouseshortcuts.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
43
44
45
46
class mouseShortcuts{
constructor(video){
this.clicks = 0;
this.doubleClickTime = 250
this.timer = false;
this.videoElement = video;
document.body.addEventListener('mousedown', this.clicked.bind(this));
}
singleClick(){
if (document.pointerLockElement === document.body) {
document.exitPointerLock()
}else{
document.body.requestPointerLock()
}
}
doubleClick(){
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
handleClickCount(){
if(this.clicks==1) this.singleClick();
if(this.clicks==2) this.doubleClick();
this.clicks = 0;
}
clicked(e){
if(e.target == this.videoElement || document.pointerLockElement === document.body){
this.clicks++;
this.timer = setTimeout(this.handleClickCount.bind(this), this.doubleClickTime);
}
}
}