-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
idiomorph stuff (hopefully this dont break)
- Loading branch information
1 parent
7fd8118
commit 89c472e
Showing
6 changed files
with
61 additions
and
36 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
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
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
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 |
---|---|---|
@@ -1,49 +1,65 @@ | ||
// Global JS ran on every page | ||
import * as htmx from "htmx.org"; | ||
import {browserInit as initHyperscript} from "hyperscript.org"; | ||
import Idiomorph from "idiomorph"; | ||
|
||
initHyperscript(); | ||
window.htmx = htmx; | ||
|
||
// copied from idiomorph/dist/idiomorh-ext.js | ||
htmx.defineExtension('morph', { | ||
isInlineSwap: function (swapStyle) { | ||
return swapStyle === 'morph'; | ||
}, | ||
handleSwap: function (swapStyle, target, fragment) { | ||
if (swapStyle === 'morph' || swapStyle === 'morph:outerHTML') { | ||
return Idiomorph.morph(target, fragment.children); | ||
} else if (swapStyle === 'morph:innerHTML') { | ||
return Idiomorph.morph(target, fragment.children, {morphStyle: 'innerHTML'}); | ||
} | ||
} | ||
}); | ||
|
||
|
||
async function webShare(url) { | ||
if (navigator.share) { | ||
try { | ||
await navigator.share({ | ||
url, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
if (navigator.share) { | ||
try { | ||
await navigator.share({ | ||
url, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} | ||
|
||
async function copyToClipboard(text) { | ||
try { | ||
await navigator.clipboard.writeText(text); | ||
} catch (err) { | ||
console.error(err.name, err.message); | ||
} | ||
try { | ||
await navigator.clipboard.writeText(text); | ||
} catch (err) { | ||
console.error(err.name, err.message); | ||
} | ||
} | ||
|
||
const shareButtons = document.querySelectorAll("button.share-button"); | ||
for (const button of shareButtons) { | ||
if (button.dataset.shareType === "webShare") { | ||
if (!navigator.share) { | ||
button.style.display = "none"; | ||
} | ||
button.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
window.plausible('Share', {props: {type: button.dataset.contentType, shareType: button.dataset.shareType}}); | ||
webShare(button.dataset.url); | ||
}); | ||
} else if (button.dataset.shareType === "clipboard") { | ||
button.addEventListener("click", async (event) => { | ||
event.preventDefault(); | ||
window.plausible('Share', {props: {type: button.dataset.contentType, shareType: button.dataset.shareType}}); | ||
await copyToClipboard(button.dataset.url); | ||
button.classList.add("copy-tooltipped"); | ||
}); | ||
button.addEventListener("mouseleave", () => button.classList.remove("copy-tooltipped")); | ||
button.addEventListener("blur", () => button.classList.remove("copy-tooltipped")); | ||
} | ||
if (button.dataset.shareType === "webShare") { | ||
if (!navigator.share) { | ||
button.style.display = "none"; | ||
} | ||
button.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
window.plausible('Share', {props: {type: button.dataset.contentType, shareType: button.dataset.shareType}}); | ||
webShare(button.dataset.url); | ||
}); | ||
} else if (button.dataset.shareType === "clipboard") { | ||
button.addEventListener("click", async (event) => { | ||
event.preventDefault(); | ||
window.plausible('Share', {props: {type: button.dataset.contentType, shareType: button.dataset.shareType}}); | ||
await copyToClipboard(button.dataset.url); | ||
button.classList.add("copy-tooltipped"); | ||
}); | ||
button.addEventListener("mouseleave", () => button.classList.remove("copy-tooltipped")); | ||
button.addEventListener("blur", () => button.classList.remove("copy-tooltipped")); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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