aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/js
diff options
context:
space:
mode:
authorMarvin Borner2019-04-16 14:57:33 +0200
committerMarvin Borner2019-04-16 14:57:33 +0200
commita32ec653bf2acc777d64803189a03a4b07b24096 (patch)
tree25f199a5b15df8d333434e40a49d73f5274b6a10 /src/main/resources/js
parent0177a6d90f3310d81eda66193ee4f4832b6e4bbd (diff)
Added file sharing feature
Diffstat (limited to 'src/main/resources/js')
-rw-r--r--src/main/resources/js/files.js31
-rw-r--r--src/main/resources/js/fileview.js5
2 files changed, 34 insertions, 2 deletions
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js
index 8b8bd87..f776165 100644
--- a/src/main/resources/js/files.js
+++ b/src/main/resources/js/files.js
@@ -33,7 +33,8 @@ drop.addEventListener('drop', e => {
row.insertCell(0).innerHTML = file.name;
row.insertCell(1).innerHTML = bytesToSize(file.size);
row.insertCell(2).innerHTML = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
- row.insertCell(3).innerHTML = "<td><button class='delete'><i class='icon ion-md-trash'></i></button></td>";
+ row.insertCell(3).innerHTML = "<td><button class='share'><i class='icon ion-md-share'></i></button></td>";
+ row.insertCell(4).innerHTML = "<td><button class='delete'><i class='icon ion-md-trash'></i></button></td>";
setListeners();
@@ -128,6 +129,34 @@ function setListeners() {
parent.remove();
})
});
+
+ // share button
+ document.querySelectorAll(".share").forEach(element => {
+ element.addEventListener("click", e => {
+ e.stopPropagation();
+ const request = new XMLHttpRequest();
+ const parent = e.target.closest("tr");
+ const fileName = parent.getAttribute("data-href") || parent.getAttribute("data-path");
+
+ request.open("POST", `/share/${path}/${fileName}`);
+ request.onload = () => {
+ if (request.readyState === 4) {
+ if (request.status === 200) {
+ const input = document.createElement('input');
+ input.setAttribute('value', request.responseText);
+ document.body.appendChild(input);
+ input.select();
+ document.execCommand('copy');
+ document.body.removeChild(input);
+ alert("Copied url to clipboard!")
+ } else {
+ alert("Something went wrong.");
+ }
+ }
+ };
+ request.send();
+ })
+ });
}
setListeners();
diff --git a/src/main/resources/js/fileview.js b/src/main/resources/js/fileview.js
index ace7884..d78c342 100644
--- a/src/main/resources/js/fileview.js
+++ b/src/main/resources/js/fileview.js
@@ -1,6 +1,7 @@
const preview = document.getElementById("preview");
const content = document.getElementById("content");
-const body = document.getElementsByTagName("body")[0];
+const html = document.getElementsByTagName("html")[0];
+const body = document.body;
// buttons
const raw = document.getElementById("raw");
@@ -23,12 +24,14 @@ if (extension === "md" || extension === "html") {
raw.addEventListener("click", () => {
if (preview.style.display === "block") {
+ html.style.overflow = "visible";
body.style.overflow = "visible";
raw.innerText = "Show preview";
preview.style.display = "none";
content.style.display = "block";
settings.style.display = "block";
} else {
+ html.style.overflow = "hidden";
body.style.overflow = "hidden";
raw.innerText = "Show raw";
preview.style.display = "block";