Browse Source

implement copyToClipBoard functionality (main.js).

This feature copies the selected file in /storage/media and builds it full
URL. The intention is to make it easier for users to copy the URL when the need
to paster it into one of the 'edit' pages (I.E. Pages and Archive sections) text
areas.

At the minute the code assumes its only copying and building URL for the files
listed on the 'Storage Index' page (/storage/manage defroute). If the website's
features expand in the future in this area, this function/feature will need to
be refactored.
stable
Craig Oates 1 year ago
parent
commit
14586efa2a
  1. 19
      static/js/main.js

19
static/js/main.js

@ -1,4 +1,3 @@
console.log("Site Side Menu script loaded.");
function toggleSiteSideMenu() {
let displayStyle = document.getElementById("be-site-side-menu").style.display;
if (displayStyle === "flex") {
@ -30,3 +29,21 @@ function closeAlert() {
}
};
});
function copyToClipBoard (slug) {
let URL = location.protocol + "//" + location.host + "/storage/view/media/" + slug;
let popup = document.getElementById(slug + "-popup");
navigator.clipboard.writeText(URL).then(() => {
/* Resolved - text copied to clipboard */
console.log("Copied: " + URL + " to clipboard.");
popup.style.visibility = "visible";
setTimeout(function () {
popup.style.visibility = "hidden";
}, 2000);
},() => {
/* Rejected - clipboard failed */
console.log("Couldn't copy " + URL + " to clipboard");
});
}

Loading…
Cancel
Save