aboutsummaryrefslogtreecommitdiffstats
path: root/front/contextmenu.ts
diff options
context:
space:
mode:
authorAlex Vitkov <alexvitkov98@gmail.com>2021-03-20 10:58:25 +0200
committerAlex Vitkov <alexvitkov98@gmail.com>2021-03-20 10:58:25 +0200
commit0255b5f7f31c4c6caefc736c59ba6959d671a92d (patch)
tree0bdad18ce5a702b7133b5169fb40d7951a8c105e /front/contextmenu.ts
parentcb3949d974f30501281fd2546ef23c81ac0282b3 (diff)
downloadfileup-0255b5f7f31c4c6caefc736c59ba6959d671a92d.tar.gz
Broke up loggedin.js into modules
Diffstat (limited to 'front/contextmenu.ts')
-rw-r--r--front/contextmenu.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/front/contextmenu.ts b/front/contextmenu.ts
new file mode 100644
index 0000000..b5a6c3c
--- /dev/null
+++ b/front/contextmenu.ts
@@ -0,0 +1,51 @@
+import { mk } from './util';
+
+// Some elements have custom right click context menus
+// If there's a custom context menu active, this will be it
+var context_menu = null;
+
+// Create a right click context menu
+export function context(e, entries) {
+ if (context_menu)
+ context_menu.remove();
+
+ context_menu = mk(document.body, 'ul', 'context');
+
+ context_menu.onmousedown = (e) => {
+ e.stopPropagation();
+ }
+
+ context_menu.onclick = (_e) => {
+ context_menu.remove();
+ context_menu = null;
+ }
+
+
+ context_menu.style.left = e.clientX + "px";
+ context_menu.style.top = e.clientY + "px";
+
+ for (const e of entries) {
+ const li = document.createElement('li');
+ li.innerText = e[0];
+ li.onclick = e[1];
+ context_menu.appendChild(li);
+ }
+}
+
+// When we click anywhere, remove the context menu
+// The context menu itself has a onmousedown that prevents propagation so we can click its elements
+document.body.onmousedown = (_e) => {
+ if (context_menu) {
+ context_menu.remove();
+ context_menu = null;
+ }
+}
+
+
+
+export function oncontextmenu_hook(_e) {
+ if (context_menu) {
+ context_menu.remove();
+ context_menu = null;
+ }
+} \ No newline at end of file