-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
106 lines (91 loc) · 2.51 KB
/
menu.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const overlay = document.getElementById("overlay");
function showMenu() {
overlay.style = "transform: translate(150vw)";
}
function hideMenu() {
overlay.style = "";
}
const cancelButton = document.getElementById("cancel");
cancelButton.onclick = function () { hideMenu(); }
const newBingoButton = document.getElementById("new");
newBingoButton.onclick = function () {
startNew();
hideMenu();
}
const resetButton = document.getElementById("reset");
resetButton.onclick = function () {
reset();
hideMenu();
}
const shareButton = document.getElementById("share");
shareButton.onclick = async function () {
if (navigator.share) {
try {
await navigator.share({
"title": "Monty Bingo",
"url": getShareUrl(),
"text": "My Monty Bingo"
});
} catch (err) { }
hideMenu();
} else {
await navigator.clipboard.writeText(getShareUrl());
shareButton.innerHTML = "Copied"
setTimeout(function () {
hideMenu();
const shareButton = document.getElementById("share");
shareButton.innerHTML = "Share"
}, 2000);
}
}
const autoSaveButton = document.getElementById("autosave");
if (isAutoSave()) {
autoSaveButton.innerHTML = "Autosave off"
} else {
autoSaveButton.innerHTML = "Autosave on"
}
autoSaveButton.onclick = function() {
toggleAutoSave();
hideMenu();
}
document.addEventListener('keyup', function (ev) {
if (ev.code === 'KeyM') {
showMenu();
}
});
let slideEnabled = false;
let currentSlideX = 0;
document.addEventListener('touchstart', function (ev) {
currentSlideX = ev.targetTouches[0].pageX;
let maxX = window.outerWidth;
if (currentSlideX < maxX / 5) {
slideEnabled = true;
overlay.classList.remove("slideAnimation");
} else {
slideEnabled = false;
}
});
document.addEventListener('touchmove', function (ev) {
if (!slideEnabled) {
return
}
currentSlideX = ev.targetTouches[0].pageX;
let maxX = window.outerWidth;
if (currentSlideX < maxX) {
overlay.style = "transform: translate(calc(50vw + " + currentSlideX + "px))";
}
});
document.addEventListener('touchend', function (ev) {
if (!slideEnabled) {
return
}
let maxX = window.outerWidth;
overlay.classList.add("slideAnimation");
if (currentSlideX < maxX / 3) {
hideMenu();
} else {
showMenu();
}
slideEnabled = false;
currentSlideX = 0;
});