Add share
This commit is contained in:
@@ -1,29 +1,33 @@
|
||||
class ShareButton extends HTMLElement {
|
||||
static register(tagName) {
|
||||
if ("customElements" in window && window.navigator.share) {
|
||||
customElements.define(tagName || "share-button", ShareButton);
|
||||
}
|
||||
}
|
||||
static register(tagName) {
|
||||
if ("customElements" in window && window.navigator.share) {
|
||||
customElements.define(
|
||||
tagName || "share-button",
|
||||
ShareButton
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.button.addEventListener("click", this.share);
|
||||
}
|
||||
connectedCallback() {
|
||||
this.button.addEventListener("click", this.share);
|
||||
}
|
||||
|
||||
get button() {
|
||||
return this.querySelector("button");
|
||||
}
|
||||
get button() {
|
||||
return this.querySelector("button");
|
||||
}
|
||||
|
||||
share = () => {
|
||||
const root = this.getRootNode();
|
||||
window.navigator
|
||||
.share({
|
||||
title: root.title,
|
||||
text: root.title,
|
||||
url: window.location.href,
|
||||
})
|
||||
.then(() => console.log("Page was succesffuly shared"))
|
||||
.catch((error) => console.log(error));
|
||||
};
|
||||
share = () => {
|
||||
console.log("Clicked");
|
||||
const root = this.getRootNode();
|
||||
window.navigator
|
||||
.share({
|
||||
title: root.title,
|
||||
text: root.title,
|
||||
url: window.location.href,
|
||||
})
|
||||
.then(() => console.log("Page was succesffuly shared"))
|
||||
.catch((error) => console.log(error));
|
||||
};
|
||||
}
|
||||
|
||||
ShareButton.register();
|
||||
|
||||
2
static/js/share-button.min.js
vendored
Normal file
2
static/js/share-button.min.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// @ts-nocheck
|
||||
class ShareButton extends HTMLElement{static register(t){"customElements"in window&&window.navigator.share&&customElements.define(t||"share-button",ShareButton)}connectedCallback(){this.button.addEventListener("click",this.share)}get button(){return this.querySelector("button")}share=()=>{console.log("Clicked");const t=this.getRootNode();window.navigator.share({title:t.title,text:t.title,url:window.location.href}).then((()=>console.log("Page was succesffuly shared"))).catch((t=>console.log(t)))}}ShareButton.register();
|
||||
Reference in New Issue
Block a user