rearrange some element lookup stuff

This commit is contained in:
Rhiannon Morris 2020-08-16 11:31:07 +02:00
parent 069a65ab71
commit a73271c0b5
2 changed files with 14 additions and 7 deletions

View file

@ -98,10 +98,15 @@ function useFragment() {
function setup() { function setup() {
items = Array.from(document.querySelectorAll('.item.post')); items = Array.from(document.getElementsByClassName('post'));
reqBoxes = Array.from(document.querySelectorAll('#require input')); function inputs(id) {
excBoxes = Array.from(document.querySelectorAll('#exclude input')); let iter = document.getElementById(id).getElementsByTagName('input');
return Array.from(iter);
}
reqBoxes = inputs('require');
excBoxes = inputs('exclude');
allBoxes = [...reqBoxes, ...excBoxes]; allBoxes = [...reqBoxes, ...excBoxes];
tags = new Map(items.map(item => [item, item.dataset.tags.split(';')])); tags = new Map(items.map(item => [item, item.dataset.tags.split(';')]));

View file

@ -4,6 +4,7 @@
let mainfig; let mainfig;
let mainimg; let mainimg;
let mainlink; let mainlink;
let altButtons;
let opened = new Set; let opened = new Set;
@ -58,12 +59,12 @@ function activateButton(button, doPush = true, firstLoad = false) {
} }
function useFragment(firstLoad = false) { function useFragment(firstLoad = false) {
let button = document.querySelector('#alts input'); let button;
let frag = location.hash.replace(/^#/, ''); let frag = location.hash.replace(/^#/, '');
if (frag) { if (frag) {
let button0 = document.getElementById(frag); let selected = document.getElementById(frag);
if (button0) button = button0; button = selected ? selected : altButtons[0];
} }
let id; let id;
@ -81,8 +82,9 @@ function setup() {
mainfig = document.getElementById('mainfig'); mainfig = document.getElementById('mainfig');
mainimg = document.getElementById('mainimg'); mainimg = document.getElementById('mainimg');
mainlink = document.getElementById('mainlink'); mainlink = document.getElementById('mainlink');
altButtons = document.getElementById('alts').getElementsByTagName('input');
for (let button of document.querySelectorAll('#alts input')) { for (let button of altButtons) {
button.onchange = e => { if (button.checked) activateButton(button); }; button.onchange = e => { if (button.checked) activateButton(button); };
} }