diff --git a/content/showArticle.php b/content/showArticle.php index 9ea6287..90bd4d3 100644 --- a/content/showArticle.php +++ b/content/showArticle.php @@ -382,4 +382,5 @@ if ($replyAuthor === null) { - \ No newline at end of file + + \ No newline at end of file diff --git a/js/comments.js b/js/comments.js index c531e78..7cccc5d 100644 --- a/js/comments.js +++ b/js/comments.js @@ -11,7 +11,7 @@ document.addEventListener("DOMContentLoaded", function () { const parentCommentInput = document.getElementById("parent-comment-id"); const replyInfo = document.getElementById("reply-info"); - if (!form || !commentsList || !commentContent || !parentCommentInput || !replyInfo) { + if (!form || !commentsList || !commentContent || !parentCommentInput) { return; } @@ -29,8 +29,13 @@ document.addEventListener("DOMContentLoaded", function () { event.preventDefault(); parentCommentInput.value = replyLink.dataset.commentId; - replyInfo.textContent = "Antwort auf " + replyLink.dataset.author; - replyInfo.style.display = "block"; + + if (replyInfo) { + replyInfo.textContent = + "Antwort auf " + replyLink.dataset.author; + replyInfo.style.display = "block"; + } + commentContent.focus(); }); } @@ -58,14 +63,22 @@ document.addEventListener("DOMContentLoaded", function () { "X-Requested-With": "XMLHttpRequest" } }) - .then(response => response.json()) - .then(data => { + .then(function (response) { + if (!response.ok) { + throw new Error("Fehlerhafte Serverantwort."); + } + + return response.json(); + }) + .then(function (data) { if (!data.success) { alert(data.message); return; } - const emptyMessage = commentsList.querySelector(".no-comments-message"); + const emptyMessage = commentsList.querySelector( + ".no-comments-message" + ); if (emptyMessage) { emptyMessage.remove(); @@ -73,8 +86,9 @@ document.addEventListener("DOMContentLoaded", function () { const commentElement = document.createElement("div"); commentElement.classList.add("comment-item"); + commentElement.dataset.commentId = data.commentId; - if (parentCommentId) { + if (parentCommentId !== "") { commentElement.classList.add("comment-reply"); commentElement.innerHTML = ` @@ -85,17 +99,16 @@ document.addEventListener("DOMContentLoaded", function () {
${escapeHtml(data.content).replace(/\n/g, "
")}
${escapeHtml(data.author)} @@ -103,11 +116,13 @@ document.addEventListener("DOMContentLoaded", function () {
${escapeHtml(data.content).replace(/\n/g, "
")}