intisync.ex/assets/js/nativeShareHook.js
Victor Martinez 4a41b4eee3 some cleanup
2024-03-30 01:49:31 +01:00

27 lines
722 B
JavaScript

const NativeShare = () => {
return {
mounted() {
this.el.addEventListener("click", async () => {
// Check if sharing is supported
if (!navigator.canShare) {
this.pushEvent("url_share_error", {
error: "Unfortunately, sharing is not supported",
});
return;
}
try {
await navigator.share({
title: this.el.dataset.title,
text: this.el.dataset.text,
url: this.el.dataset.url,
});
this.pushEvent("url_shared", {});
} catch (error) {
this.pushEvent("url_share_error", { error: error.message });
}
});
},
};
};
export default NativeShare;