forked from rDrama/rDrama
1
0
Fork 0

dont put reporting event listener assignment inside a function

master
Aevann 2023-05-01 21:30:28 +03:00
parent fce0c5a92c
commit 3f63bb339b
2 changed files with 28 additions and 38 deletions

View File

@ -13,30 +13,32 @@ reason_comment.addEventListener('keydown', (e) => {
function report_commentModal(id, author) {
document.getElementById("comment-author").textContent = author;
reportCommentButton.innerHTML='Report comment';
reportCommentButton.disabled = false;
reportCommentButton.classList.remove('disabled');
reportCommentButton.dataset.id = id
reason_comment.value = ""
setTimeout(() => {
reason_comment.focus()
}, 500);
reportCommentButton.onclick = function() {
this.innerHTML='Reporting comment';
postToast(this, `/report/comment/${id}`,
{
"reason": reason_comment.value
},
() => {}
);
}
};
reportCommentButton.onclick = function() {
this.innerHTML='Reporting comment';
this.disabled = true;
this.classList.add('disabled');
postToast(this, '/report/comment/' + reportCommentButton.dataset.id,
{
"reason": reason_comment.value
},
() => {}
);
}
// Returns the selection text based on the range with the HTML
function getSelectionTextHtml() {
let html = "";

View File

@ -12,38 +12,26 @@ reason_post.addEventListener('keydown', (e) => {
});
function report_postModal(id) {
reportPostButton.disabled = false;
reportPostButton.classList.remove('disabled');
reportPostButton.innerHTML='Report post';
reportPostButton.dataset.id = id
reason_post.value = ""
setTimeout(() => {
reason_post.focus()
}, 500);
reportPostButton.onclick = function() {
this.innerHTML='Reporting post';
this.disabled = true;
this.classList.add('disabled');
const xhr = new XMLHttpRequest();
xhr.open("POST", '/report/post/'+id);
xhr.setRequestHeader('xhr', 'xhr');
const form = new FormData()
form.append("formkey", formkey());
form.append("reason", reason_post.value);
xhr.onload = function() {
let data
try {data = JSON.parse(xhr.response)}
catch(e) {console.error(e)}
success = xhr.status >= 200 && xhr.status < 300;
showToast(success, getMessageFromJsonData(success, data));
};
xhr.onerror=function(){alert(errortext)};
xhr.send(form);
}
};
reportPostButton.onclick = function() {
this.innerHTML='Reporting post';
this.disabled = true;
this.classList.add('disabled');
postToast(this, '/report/post/' + reportPostButton.dataset.id,
{
"reason": reason_post.value
},
() => {}
);
}