From 0d1e694b59b98bf869170c739d71fe1b837ef69a Mon Sep 17 00:00:00 2001 From: ari melody Date: Wed, 17 Apr 2024 18:29:39 +0100 Subject: [PATCH] fixed event order issues with swapping Signed-off-by: ari melody --- public/script/music-gateway.js | 9 ++++++++- public/script/swap.js | 5 +++-- public/style/music-gateway.css | 6 ++++++ views/base.html | 2 +- views/index.html | 2 +- views/music-gateway.html | 4 ++-- views/music.html | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/public/script/music-gateway.js b/public/script/music-gateway.js index 989f21b..b625caf 100644 --- a/public/script/music-gateway.js +++ b/public/script/music-gateway.js @@ -51,7 +51,14 @@ function bind_go_back_btn() { function bind_share_btn() { const share_btn = document.getElementById("share"); - share_btn.onclick = (e) => { + if (navigator.clipboard === undefined) { + share_btn.onclick = event => { + console.error("clipboard is not supported by this browser!"); + }; + return; + } + share_btn.onclick = event => { + event.preventDefault(); navigator.clipboard.writeText(window.location.href); share_btn.classList.remove('active'); void share_btn.offsetWidth; diff --git a/public/script/swap.js b/public/script/swap.js index ccc834d..ac74646 100644 --- a/public/script/swap.js +++ b/public/script/swap.js @@ -4,7 +4,6 @@ let caches = {}; async function cached_fetch(url) { let cached = caches[url]; - console.log("cache: " + cached); const res = cached === undefined ? await fetch(url) : await fetch(url, { headers: { @@ -113,4 +112,6 @@ window.addEventListener("popstate", event => { swap(event.state, false); }); -bind(document.body); +document.addEventListener("DOMContentLoaded", () => { + bind(document.body); +}); diff --git a/public/style/music-gateway.css b/public/style/music-gateway.css index f5dc07b..c3a519d 100644 --- a/public/style/music-gateway.css +++ b/public/style/music-gateway.css @@ -358,11 +358,17 @@ ul#links a:hover { #share { margin: 0; + padding: 0; display: inline-block; + color: inherit; + font-family: inherit; + font-size: inherit; line-height: 1em; text-shadow: 0 .05em 2px #0004; cursor: pointer; opacity: .5; + background: none; + border: none; transition: opacity .1s linear; } diff --git a/views/base.html b/views/base.html index 1842e27..9846691 100644 --- a/views/base.html +++ b/views/base.html @@ -13,7 +13,7 @@ - + diff --git a/views/index.html b/views/index.html index 0572f8e..466e86b 100644 --- a/views/index.html +++ b/views/index.html @@ -20,7 +20,7 @@ {{define "content"}}
- +

# hello, world! diff --git a/views/music-gateway.html b/views/music-gateway.html index 3de307e..ba4971e 100644 --- a/views/music-gateway.html +++ b/views/music-gateway.html @@ -30,7 +30,7 @@ {{define "content"}}
- +
@@ -79,7 +79,7 @@

{{end}} -

share

+ {{if .Credits}} diff --git a/views/music.html b/views/music.html index cf60e5e..79ec32d 100644 --- a/views/music.html +++ b/views/music.html @@ -18,7 +18,7 @@ {{define "content"}}
- +

# my music