Add share

This commit is contained in:
Fundor333
2025-08-22 23:35:06 +02:00
parent d7bfe0cc23
commit b7c5abdcd5
7 changed files with 75 additions and 26 deletions

View File

@@ -8,3 +8,4 @@
@import "mastodon";
@import "link";
@import "weeknote";
@import "share-button";

View File

@@ -0,0 +1,43 @@
$color_1: #fff;
$background-color_1: #0c9;
share-button {
position: fixed;
width: 60px;
height: 60px;
bottom: 40px;
left: 40px;
color: $color_1;
background-color: $background-color_1;
border-radius: 50px;
text-align: center;
button {
background-color: transparent;
border: none;
margin: 0;
padding: 0;
text-align: inherit;
font: inherit;
border-radius: 0;
appearance: none;
}
&:not(:defined) {
button {
display: none;
}
display: none;
}
&:defined {
a {
display: none;
}
display: none;
}
}
.my-float {
margin-top: 22px;
}

View File

@@ -1,4 +1,3 @@
<share-button>
<button>Share</button>
<button><i class="fa-regular fa-share-from-square my-float"></i></button>
</share-button>

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"Target":"add.min.27a96df35c167150b7cf7fde3dc822fc02b0e56f3beecf3d9a3bd150bfb8ae6a.css","MediaType":"text/css","Data":{"Integrity":"sha256-J6lt81wWcVC3z3/ePcgi/AKw5W877s89mjvRUL+4rmo="}}
{"Target":"add.min.168b9365a8bd3efdf631db70449d0d34d06f982a0790c1b777f8239b84888165.css","MediaType":"text/css","Data":{"Integrity":"sha256-FouTZai9Pv32MdtwRJ0NNNBvmCoHkMG3d/gjm4SIgWU="}}

View File

@@ -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
View 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();