@proca/widget
Version:
Proca is an open-source campaign toolkit designed to empower activists and organisations in their digital advocacy efforts. It provides a flexible and customisable platform for creating and managing online petitions, email campaigns, and other forms of di
67 lines (64 loc) • 1.89 kB
HTML
<div class="proca-widget" id="proca-widget">...</div>
<script>
//widget={{actionPage.name}}?redir={{tracking.encodedLocation}}&media=twitter
const urlParams = new URLSearchParams(window.location.search);
const widget = urlParams.get("widget");
const media = urlParams.get("media");
const redir = urlParams.get("redir");
(() => {
if (widget) {
const script = document.createElement("script");
script.onload = function () {
//todo: check it loads
};
script.src = "https://widget.proca.app/d/" + widget;
document.head.appendChild(script);
} else {
if (redir) {
const url = new URL(redir);
url.searchParams.set("proca_go", "Share");
window.location.replace(url.toString());
return;
}
document.getElementById("proca-widget").textContent =
"error:we need the widget and the redirect as a param";
return;
}
})();
function gotoShare() {
if (proca) {
proca.set("component", {
share: {
url: redir,
open: false,
next: false,
},
});
proca.go("Share");
} else {
console.log("loading...");
setTimeout(gotoShare, 10);
}
}
window.addEventListener("proca", (e) => {
console.log(e.detail);
if (e.detail.message === "init") {
gotoShare();
}
if (e.detail.message === "share:init") {
console.log("click", media);
setTimeout(() => {
const button = document.getElementById("proca-share-" + media);
console.log(button);
if (!button) {
// document.getElementById("proca-widget").textContent =
// "error:we need a social media param";
return;
}
button.click();
}, 10);
}
});
//https://widget.proca.app/d/ha_test-one/hateaid/en
</script>