moved toggleelement to register_new_elements() (#111)

We currently cannot see (toggle the dropdown/button) reports that are hidden behind the "show more" (comments) button. This PR fixes that.

Example of what is happening without this PR:
1. open megathread. The thread is long includes hundreds of comments implying need to click "show more" (comments) button
2. without clicking any "show more" (comments) button, click the flaggers button on one of the first comments
3. flaggers are presented as expected
4. click the "show more" (comments) button at the end
5. click the flaggers button on one of the comments that was hidden behind the "show more" (comments) button
6. the button does nothing and has no event listenner associated

With this PR:
1. all flaggers buttons work regardless if hidden behind "Show More" (comments) or not. Tested up to two "Show More" (comments) buttons

I did the PR this way because the view_more button calls register_new_elements() and not bottom.js as a whole

There are other things using data-toggleelement like the undelete button on comments and the Preview button on /submit. Both of those still work as expected

Reviewed-on: #111
Co-authored-by: mummified-corroding-granny <mummified-corroding-granny@noreply.fsdfsd.net>
Co-committed-by: mummified-corroding-granny <mummified-corroding-granny@noreply.fsdfsd.net>
pull/113/head
mummified-corroding-granny 2023-02-06 02:07:18 +00:00 committed by Aevann
parent 1238756b66
commit 786ba6aa56
1 changed files with 8 additions and 7 deletions

View File

@ -99,13 +99,6 @@ for (const element of TH) {
element.addEventListener('click', () => {sort_table(element)});
}
const toggleelement = document.querySelectorAll('[data-toggleelement]');
for (const element of toggleelement) {
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) {
@ -144,6 +137,14 @@ function register_new_elements(e) {
for (const element of expandable) {
element.onclick = () => {expandImage()};
}
const toggleelement = e.querySelectorAll('[data-toggleelement]');
for (const element of toggleelement) {
element.addEventListener('click', () => {
document.getElementById(element.dataset.toggleelement).classList.toggle(element.dataset.toggleattr);
});
}
}
register_new_elements(document);