forked from johnggli/linktree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
079b391
commit 34c2d93
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |
34c2d93
There was a problem hiding this comment.
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