2021-04-12 20:06:21 +02:00
|
|
|
class commentsDisplay extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
let path = window.location.pathname;
|
|
|
|
let pageName = path.split("/").pop();
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.onreadystatechange = () => {
|
2021-04-18 21:49:25 +02:00
|
|
|
if (xhr.readyState === 4) {
|
|
|
|
if (xhr.status === 200) {
|
|
|
|
let comments = JSON.parse(xhr.responseText);
|
|
|
|
comments.forEach((element) => {
|
|
|
|
this.innerHTML += `
|
2021-04-12 20:06:21 +02:00
|
|
|
<h3 class="commentTitle">${element["name"]}</h3>
|
|
|
|
<div class="comment">
|
|
|
|
<img src="${element["gravatarURL"]}">
|
|
|
|
<article class="commentArticle">
|
|
|
|
<p class="commentText">${element["comment"]}</p>
|
|
|
|
</article>
|
|
|
|
</div>
|
|
|
|
`;
|
2021-04-18 21:49:25 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let p = document.createElement("p");
|
2021-10-30 09:16:47 +02:00
|
|
|
p.innerText = "Leider konnte dieser Inhalt nicht geladen werden, bitte versuche die Seite neu zu laden oder komme später wieder zurück.";
|
2021-04-18 21:49:25 +02:00
|
|
|
this.appendChild(p);
|
|
|
|
|
|
|
|
}
|
2021-04-12 20:06:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.open("GET", "/API/projectComments.php?article=" + pageName);
|
|
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("jl-comments_display", commentsDisplay);
|