aboutsummaryrefslogtreecommitdiffstats
path: root/loggedin.js
diff options
context:
space:
mode:
authorAlex Vitkov <alexvitkov98@gmail.com>2021-02-12 16:27:47 +0200
committerAlex Vitkov <alexvitkov98@gmail.com>2021-02-12 16:27:47 +0200
commite9d94ce6144746fe69a3d9f26e12a8fab9d4a534 (patch)
treee29bc7533a7e8c2f2dfdcec8e40cb38bcee147ac /loggedin.js
parentd682faeaeea940ab8ab6bcb59245a2116bcc80b1 (diff)
downloadfileup-e9d94ce6144746fe69a3d9f26e12a8fab9d4a534.tar.gz
right click context menu on files
Diffstat (limited to 'loggedin.js')
-rw-r--r--loggedin.js48
1 files changed, 46 insertions, 2 deletions
diff --git a/loggedin.js b/loggedin.js
index 1affb09..d80c734 100644
--- a/loggedin.js
+++ b/loggedin.js
@@ -12,6 +12,8 @@ the_file.onchange = on_file_added;
var pwd = [];
const pending_uploads = [];
+var context_menu = null;
+
class FileView {
constructor(filename, visuals, mimetype, is_directory) {
this.filename = filename;
@@ -127,11 +129,27 @@ function add_file_visuals(name, is_directory, mimetype) {
pwd.push(name);
load_dir();
}
- }
- else {
+ } else {
img.src=`/mimeicons/${mimetype.replace("/", "-")}.png`;
}
+ fileDiv.oncontextmenu = (e) => {
+ context(e, [
+ ['Open', () => {
+ if (is_directory) {
+ pwd.push(name);
+ load_dir();
+ } else {
+ alert('not implemented');
+ }
+ }],
+ ['Rename', () => {alert('not implemented')}],
+ ['Share', () => {alert('not implemented')}],
+ ['Delete', () => {alert('not implemented')}],
+ ]);
+ e.preventDefault();
+ }
+
fileDiv.classList.add('file');
filename.classList.add('filename');
filename.innerText = name;
@@ -153,4 +171,30 @@ function begin_upload() {
the_file.click();
}
+function context(e, entries) {
+ if (context_menu)
+ context_menu.remove();
+
+ context_menu = document.createElement('ul');
+ context_menu.classList.add('context');
+
+ 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);
+ }
+
+ document.body.appendChild(context_menu);
+}
+
+document.body.onclick = () => {
+ if (context_menu)
+ context_menu.remove();
+}
+
load_dir();