Skip to content

Commit

Permalink
Use sound static URL with alt+click on share link
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Feb 27, 2024
1 parent ea3b1e4 commit 877a12e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions freesound/static/bw-frontend/src/pages/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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";
}
Expand All @@ -52,7 +60,7 @@ const toggleShareLink = () => {
}

toggleEmbedCodeElement.addEventListener('click', toggleEmbedCode);
toggleShareLinkElement.addEventListener('click', toggleShareLink);
toggleShareLinkElement.addEventListener('click', evt => toggleShareLink(evt));


const generateEmbedCode = (size) => {
Expand Down
6 changes: 6 additions & 0 deletions general/templatetags/absurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions templates/sounds/sound.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ <h6 class="text-26 no-margins ">Comments</h6>
</ol>
</div>

<div id="share-link" class="v-spacing-top-5">
<span class="text-grey">Share url: </span><br><input class="w-100" type="text" readonly value="{% absurl 'short-sound-link' sound.id %}" />
<div id="share-link" class="v-spacing-top-5" data-static-file-url="{{ sound.locations.preview.HQ.mp3.url|url2absurl }}" data-sound-page-url="{% absurl 'short-sound-link' sound.id %}">
<span class="text-grey">Share url: </span><br><input class="w-100" type="text" readonly />
</div>

<div id="embed-links" class="v-spacing-top-5 bw-form">
Expand Down

0 comments on commit 877a12e

Please sign in to comment.