use addEventListener instead of onclick

master
Aevann 2023-01-28 16:27:52 +02:00
parent 47fdc8e870
commit 010f424756
10 changed files with 29 additions and 31 deletions

View File

@ -176,7 +176,7 @@ for (const element of data_url) {
console.log("Nonce check failed!")
continue
}
element.onclick = () => {
element.addEventListener('click', () => {
document.getElementById('giveaward').dataset.action = element.dataset.url
};
});
}

View File

@ -40,7 +40,7 @@ for (const element of onclick_submit) {
console.log("Nonce check failed!")
continue
}
element.onclick = () => {element.form.submit()};
element.addEventListener('click', () => {element.form.submit()});
}
const onchange_submit = document.querySelectorAll('[onchange_submit]');
@ -90,30 +90,30 @@ for (const element of setting_selects) {
const reload_page = document.getElementById('reload_page')
if (reload_page) {
reload_page.onclick = () => {location.reload()};
reload_page.addEventListener('click', () => {location.reload()});
}
const TH = document.getElementsByTagName('th')
for (const element of TH) {
element.onclick = () => {sort_table(element)};
element.addEventListener('click', () => {sort_table(element)});
}
const toggleelement = document.querySelectorAll('[data-toggleelement]');
for (const element of toggleelement) {
element.onclick = () => {
element.addEventListener('click', () => {
document.getElementById(element.dataset.toggleelement).classList.toggle(element.dataset.toggleattr);
};
});
}
function register_new_elements(e) {
const showmores = document.getElementsByClassName('showmore')
for (const element of showmores) {
element.onclick = () => {showmore(element)};
element.addEventListener('click', () => {showmore(element)});
}
const onclick = e.querySelectorAll('[data-onclick]');
for (const element of onclick) {
element.onclick = () => {execute(element, 'onclick')};
element.addEventListener('click', () => {execute(element, 'onclick')});
}
const oninput = e.querySelectorAll('[data-oninput]');
@ -133,12 +133,12 @@ function register_new_elements(e) {
const popover_triggers = document.getElementsByClassName('user-name');
for (const element of popover_triggers) {
element.onclick = (e) => {popclick(e)};
element.addEventListener('click', (e) => {popclick(e)});
}
const expandable = document.querySelectorAll('.in-comment-image, img[alt^="![]("]');
for (const element of expandable) {
element.onclick = () => {expandImage()};
element.addEventListener('click', () => {expandImage()});
}
}

View File

@ -25,7 +25,7 @@ function report_commentModal(id, author) {
reason_comment.focus()
}, 500);
reportCommentButton.onclick = function() {
reportCommentButton.addEventListener('click', function() {
this.innerHTML='Reporting comment';
postToast(this, `/report/comment/${id}`,
@ -34,8 +34,7 @@ function report_commentModal(id, author) {
},
() => {}
);
}
})
};
// Returns the selection text based on the range with the HTML
@ -87,7 +86,7 @@ function toggleEdit(id){
function delete_commentModal(t, id) {
document.getElementById("deleteCommentButton").onclick = function() {
document.getElementById("deleteCommentButton").addEventListener('click', function() {
postToast(t, `/delete/comment/${id}`,
{
},
@ -107,7 +106,7 @@ function delete_commentModal(t, id) {
}
}
);
};
});
}
function post_reply(id){

View File

@ -1,5 +1,5 @@
function delete_postModal(t, id) {
document.getElementById("deletePostButton").onclick = function() {
document.getElementById("deletePostButton").addEventListener('click', function() {
postToast(t, `/delete_post/${id}`,
{
},
@ -19,5 +19,5 @@ function delete_postModal(t, id) {
}
}
);
};
});
}

View File

@ -443,13 +443,13 @@ function populate_speed_emoji_modal(results, textbox)
if (current_word.includes("#")) result = `#${result}`
if (current_word.includes("!")) result = `!${result}`
emoji_option.onclick = (e) => {
emoji_option.addEventListener('click', () => {
selecting = false;
speed_carot_modal.style.display = "none";
textbox.value = textbox.value.replace(new RegExp(current_word+"(?=\\s|$)", "g"), `:${result}:`)
textbox.focus()
markdown(textbox)
};
});
// Pack
emoji_option.appendChild(emoji_option_img);
emoji_option.appendChild(emoji_option_text);

View File

@ -106,7 +106,7 @@ async function getGifs(form) {
const overlays = document.getElementsByClassName('gif-cat-overlay')
for (const element of overlays) {
element.onclick = () => {searchGifs(element.firstElementChild.innerHTML)};
element.addEventListener('click', () => {searchGifs(element.firstElementChild.innerHTML)});
}
}
@ -131,7 +131,7 @@ async function searchGifs(searchTerm) {
const giphy = document.getElementsByClassName('giphy')
for (const element of giphy) {
element.onclick = () => {insertGIF(element.src)};
element.addEventListener('click', () => {insertGIF(element.src)});
}
}
else {

View File

@ -2,7 +2,7 @@ if (!window.matchMedia('(display-mode: minimal-ui)')['matches']) {
if (window.innerWidth <= 737) {
const tt = bootstrap.Tooltip.getOrCreateInstance(document.getElementById('mobile-prompt'))
tt.show()
document.getElementsByClassName('tooltip')[0].onclick = function(e) {
document.getElementsByClassName('tooltip')[0].addEventListener('click', function(e) {
tt.hide()
const xhr = new XMLHttpRequest();
xhr.withCredentials=true;
@ -11,6 +11,6 @@ if (!window.matchMedia('(display-mode: minimal-ui)')['matches']) {
xhr.send();
if (!e.target.classList.contains('dismiss-beg'))
location.href = "/app"
}
})
}
}

View File

@ -1,3 +1,3 @@
const reload_page = document.getElementById('reload_page')
if (reload_page)
reload_page.onclick = () => {location.reload()};
reload_page.addEventListener('click', () => {location.reload()});

View File

@ -22,7 +22,7 @@ function report_postModal(id) {
reason_post.focus()
}, 500);
reportPostButton.onclick = function() {
reportPostButton.addEventListener('click', function() {
this.innerHTML='Reporting post';
this.disabled = true;
@ -45,6 +45,5 @@ function report_postModal(id) {
xhr.onerror=function(){alert(errortext)};
xhr.send(form);
}
};
})
};

View File

@ -28,7 +28,7 @@ if (!location.href.includes("?context")) {
const fake_textarea = document.querySelector('[data-href]')
if (fake_textarea) {
fake_textarea.onclick = () => {
fake_textarea.addEventListener('click', () => {
location.href = fake_textarea.dataset.href;
};
});
}