diff --git a/src/js/file.js b/src/js/file.js
index 2202376..0b8302c 100644
--- a/src/js/file.js
+++ b/src/js/file.js
@@ -1,4 +1,4 @@
-/* global swal, axios */
+/* global swal, axios, ClipboardJS */
const lsKeys = {
token: 'token'
@@ -14,13 +14,15 @@ const page = {
messageElement: document.querySelector('#message'),
fileinfoContainer: document.querySelector('#fileinfo'),
- downloadBtn: document.querySelector('#downloadBtn'),
+ clipboardBtn: document.querySelector('#clipboardBtn'),
playerBtn: document.querySelector('#playerBtn'),
+ downloadBtn: document.querySelector('#downloadBtn'),
deleteBtn: document.querySelector('#deleteBtn'),
uploadRoot: null,
titleFormat: null,
- file: null
+ file: null,
+ clipboardJS: null
}
page.updateMessageBody = content => {
@@ -161,9 +163,9 @@ page.loadFileinfo = () => {
`
- if (page.downloadBtn) {
- page.downloadBtn.setAttribute('href', `${page.uploadRoot}/${page.file.name}`)
- }
+ const fileUrl = `${page.uploadRoot}/${page.file.name}`
+ page.downloadBtn.setAttribute('href', fileUrl)
+ page.clipboardBtn.dataset.clipboardText = fileUrl
const isimage = page.file.type.startsWith('image/')
const isvideo = page.file.type.startsWith('video/')
@@ -227,6 +229,17 @@ window.addEventListener('DOMContentLoaded', () => {
// eslint-disable-next-line compat/compat
page.urlParams = new URLSearchParams(window.location.search)
+ page.clipboardJS = new ClipboardJS('.clipboard-js')
+
+ page.clipboardJS.on('success', () => {
+ return swal('', 'The link has been copied to clipboard.', 'success', {
+ buttons: false,
+ timer: 1500
+ })
+ })
+
+ page.clipboardJS.on('error', page.onError)
+
page.deleteBtn.addEventListener('click', page.deleteFile)
page.loadFileinfo()
diff --git a/views/file.njk b/views/file.njk
index 174177d..511e3d9 100644
--- a/views/file.njk
+++ b/views/file.njk
@@ -19,6 +19,7 @@
+
{# We assign an ID for this so that the script can find out proper root URL of uploaded files #}