website/js/customElements/newComment.js

42 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-04-12 20:33:24 +02:00
class newComment extends HTMLElement {
constructor() {
super();
this.innerHTML = `
<button class="bigButton" id="showCommentButton">Neues Kommentar verfassen</button>
`;
document.getElementById("showCommentButton").onclick = this.setupForm;
2021-04-12 20:33:24 +02:00
}
2021-09-10 21:22:24 +02:00
async setupForm() {
2021-04-12 20:33:24 +02:00
let sitekey = await (await fetch("/API/config.php?name=sitekey")).text();
2021-09-10 21:22:24 +02:00
let script = document.createElement('script');
script.src = "https://hCaptcha.com/1/api.js";
script.type = 'text/javascript';
script.onload = () => {
2021-11-09 12:22:31 +01:00
let pageName = window.location.pathname.split("/").pop();
2021-09-10 21:22:24 +02:00
this.parentElement.innerHTML = `
<form action="/API/newComment.php" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br><br>
<label for="email">E-Mail: (wird nicht ver&ouml;ffentlicht)</label><br>
<input type="text" id="email" name="email"><br><br>
<label for="comment">Kommentar:</label><br>
<textarea name="comment" id="comment"></textarea><br><br>
<div class="h-captcha" data-theme="dark" data-sitekey="${sitekey}"></div><br>
<input type="hidden" name="pagename" id="pagename" value="${pageName}">
2021-09-10 21:22:24 +02:00
<input type="submit" value="Kommentar ver&ouml;ffentlichen"><br>
<p>Mit dem Klick auf den obigen Button erkl&auml;ren sie sich mit der <a href="/datenschutzerklaerung.html">Datenschutzerkl&auml;rung</a> einverstanden.</p>
</form>
`;
}
document.body.append(script);
2021-04-12 20:33:24 +02:00
}
}
customElements.define("jl-new_comment", newComment);