2021-04-12 19:45:30 +02:00
|
|
|
class BlogIndex extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
let ul = document.createElement("ul");
|
|
|
|
xhr.onreadystatechange = () => {
|
2021-04-18 21:49:25 +02:00
|
|
|
if (xhr.readyState === 4) {
|
|
|
|
if (xhr.status === 200) {
|
|
|
|
let blog = JSON.parse(xhr.responseText);
|
|
|
|
blog.forEach((element) => {
|
|
|
|
this.innerHTML += `
|
2021-04-12 19:45:30 +02:00
|
|
|
<article class="breakWord">
|
|
|
|
<h2>${element["title"]}</h2>
|
|
|
|
<p breakWord>${element["content"]}</p>
|
2021-04-13 10:17:35 +02:00
|
|
|
<p class="center"><a href="/post.html?id=${element["id"]}"><button>Mehr lesen</button></a></p>
|
2021-04-12 19:45:30 +02:00
|
|
|
</article>
|
|
|
|
`;
|
2021-04-18 21:49:25 +02:00
|
|
|
});
|
|
|
|
this.appendChild(ul);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
let p = document.createElement("p");
|
|
|
|
p.innerText = "Leider konnte dieser Inhalt nicht geladen werden, bitte versuche die Seite neu zu laden oder komme später wieder zurück";
|
|
|
|
this.appendChild(p);
|
|
|
|
|
|
|
|
}
|
2021-04-12 19:45:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.open("GET", "/API/getBlogElements.php?position=index");
|
|
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("jl-blog_index", BlogIndex);
|