diff --git a/freesound/static/bw-frontend/src/pages/sound.js b/freesound/static/bw-frontend/src/pages/sound.js index 71fac49df..53b03bdd4 100644 --- a/freesound/static/bw-frontend/src/pages/sound.js +++ b/freesound/static/bw-frontend/src/pages/sound.js @@ -17,8 +17,15 @@ const urlParams = new URLSearchParams(window.location.search); prepareAfterDownloadSoundModals(); -const copyShareUrlToClipboard = () => { +const copyShareUrlToClipboard = (useFileURL) => { var shareLinkInputElement = shareLinkElement.getElementsByTagName("input")[0]; + console.log(shareLinkElement.dataset.staticFileUrl + , shareLinkElement.dataset.soundPageUrl) + if (useFileURL) { + shareLinkInputElement.value = shareLinkElement.dataset.staticFileUrl; + } else { + shareLinkInputElement.value = shareLinkElement.dataset.soundPageUrl; + } shareLinkInputElement.select(); shareLinkInputElement.setSelectionRange(0, 99999); document.execCommand("copy"); @@ -38,10 +45,11 @@ const toggleEmbedCode = () => { } } -const toggleShareLink = () => { +const toggleShareLink = (evt) => { if (shareLinkElement.style.display === "none") { shareLinkElement.style.display = "block"; - copyShareUrlToClipboard(); + const useFileURL = evt.altKey; + copyShareUrlToClipboard(useFileURL); } else { shareLinkElement.style.display = "none"; } @@ -52,7 +60,7 @@ const toggleShareLink = () => { } toggleEmbedCodeElement.addEventListener('click', toggleEmbedCode); -toggleShareLinkElement.addEventListener('click', toggleShareLink); +toggleShareLinkElement.addEventListener('click', evt => toggleShareLink(evt)); const generateEmbedCode = (size) => { diff --git a/general/templatetags/absurl.py b/general/templatetags/absurl.py index 85f17e43f..aa04b6758 100644 --- a/general/templatetags/absurl.py +++ b/general/templatetags/absurl.py @@ -40,3 +40,9 @@ def absurl(parser, token, node_cls=AbsoluteURLNode): asvar=node_instance.asvar) absurl = register.tag(absurl) + + +@register.filter +def url2absurl(path): + domain = f"https://{Site.objects.get_current().domain}" + return urllib.parse.urljoin(domain, path) diff --git a/templates/sounds/sound.html b/templates/sounds/sound.html index 5afc69ed4..c9b936bcf 100644 --- a/templates/sounds/sound.html +++ b/templates/sounds/sound.html @@ -311,8 +311,8 @@