Wire the share button up
The button was rendered but nothing listened for it.
This commit is contained in:
parent
9801f1a8d1
commit
6dcbfbd035
1 changed files with 21 additions and 0 deletions
21
videos.html
21
videos.html
|
|
@ -109,6 +109,27 @@ async function load() {
|
|||
return;
|
||||
}
|
||||
out.innerHTML = '<div class="list">' + r.projects.map(card).join("") + '</div>';
|
||||
var byId = {};
|
||||
r.projects.forEach(function (p) { byId[p.id] = p; });
|
||||
[].forEach.call(out.querySelectorAll("[data-share]"), function (b) {
|
||||
b.onclick = async function () {
|
||||
var p = byId[decodeURIComponent(b.getAttribute("data-share"))];
|
||||
if (!p) return;
|
||||
var link = window.__shareUrl(p);
|
||||
if (!link) { showMsg("msg", "That one has no video yet."); return; }
|
||||
var title = p.title || ((p.pet_name || "Your pet") + " has something to say");
|
||||
// The native sheet is the shortest path into a text message on a phone.
|
||||
if (navigator.share) {
|
||||
try { await navigator.share({ title: title, text: title, url: link }); return; }
|
||||
catch (e) { if (e && e.name === "AbortError") return; }
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
b.textContent = "Copied";
|
||||
setTimeout(function () { b.textContent = "Share"; }, 1600);
|
||||
} catch (e) { showMsg("msg", "Copy this: " + link); }
|
||||
};
|
||||
});
|
||||
// Anything still being written will change shortly; refresh so the button appears.
|
||||
if (r.projects.some(function (p) { return p.status === "scripting"; })) setTimeout(load, 6000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue