From 34c2d935a0e982bc4b298c1342756fbfcbb9a60a Mon Sep 17 00:00:00 2001 From: Darkhorse <73045479+paramedicspecialist@users.noreply.github.com> Date: Sat, 16 Sep 2023 10:10:28 -0700 Subject: [PATCH] Created "share-button.js" Adding some JS for a "Share" buttton based on inspiration from LinkStack. https://github.com/LinkStackOrg/LinkStack/blob/ccf5e7ad13560882d2de3654b7cebdefa5be6e86/resources/views/littlelink.blade.php#L227C1-L227C2 --- mods/share-button.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 mods/share-button.js diff --git a/mods/share-button.js b/mods/share-button.js new file mode 100644 index 00000000..f90c9819 --- /dev/null +++ b/mods/share-button.js @@ -0,0 +1,31 @@ +// Share Button from LinkStack - https://github.com/LinkStackOrg/LinkStack/blob/ccf5e7ad13560882d2de3654b7cebdefa5be6e86/resources/views/littlelink.blade.php#L227C1-L227C2 + +document.addEventListener('DOMContentLoaded', function () { + // Get the current URL + var currentUrl = window.location.href; + + const shareButtons = document.querySelectorAll('.share-button'); + shareButtons.forEach(button => { + // Update the data-share attribute with the current URL + button.setAttribute('data-share', currentUrl); + + button.addEventListener('click', () => { + const valueToShare = button.dataset.share; + if (navigator.share) { + navigator.share({ + title: "Share this page", + url: valueToShare + }) + .catch(err => console.error('Error:', err)); + } else { + navigator.clipboard.writeText(valueToShare) + .then(() => { + alert("URL has been copied to your clipboard!"); + }) + .catch(err => { + alert('Error', err); + }); + } + }); + }); +});