| 1 |
document.addEventListener('DOMContentLoaded', function() { |
| 2 |
// Add click event to each share link |
| 3 |
document.querySelectorAll('.wdk-block-share').forEach(link => { |
| 4 |
link.addEventListener('click', function(event) { |
| 5 |
event.preventDefault(); |
| 6 |
wdkBlockShareUrl(link.getAttribute('href')); |
| 7 |
}); |
| 8 |
}); |
| 9 |
}); |
| 10 |
|
| 11 |
|
| 12 |
// Share URL function |
| 13 |
var wdkBlockShareUrl = (url = window.location.href) => { |
| 14 |
// Check if the browser supports the Web Share API |
| 15 |
if (!navigator.share) { |
| 16 |
console.log("Web Share API not supported."); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
navigator.share({ |
| 21 |
url: url, // Share the current page URL |
| 22 |
}) |
| 23 |
.then(() => { |
| 24 |
console.log("Shared successfully!"); |
| 25 |
}) |
| 26 |
.catch((error) => { |
| 27 |
console.error("Sharing failed:", error); |
| 28 |
}); |
| 29 |
}; |
| 30 |
|
| 31 |
|