Skip to content

Commit

Permalink
Created "share-button.js"
Browse files Browse the repository at this point in the history
  • Loading branch information
paramedicspecialist authored Sep 16, 2023
1 parent 079b391 commit 34c2d93
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mods/share-button.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
});
});
});

1 comment on commit 34c2d93

@paramedicspecialist
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from separate js file into index.html
a290e4e

Please sign in to comment.