From a73271c0b5d37a822cf2e7ba916a74ff0d0a0495 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Sun, 16 Aug 2020 11:31:07 +0200 Subject: [PATCH] rearrange some element lookup stuff --- script/gallery.js | 11 ++++++++--- script/single.js | 10 ++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/script/gallery.js b/script/gallery.js index 8399a75..d9cadbd 100644 --- a/script/gallery.js +++ b/script/gallery.js @@ -98,10 +98,15 @@ function useFragment() { function setup() { - items = Array.from(document.querySelectorAll('.item.post')); + items = Array.from(document.getElementsByClassName('post')); - reqBoxes = Array.from(document.querySelectorAll('#require input')); - excBoxes = Array.from(document.querySelectorAll('#exclude input')); + function inputs(id) { + let iter = document.getElementById(id).getElementsByTagName('input'); + return Array.from(iter); + } + + reqBoxes = inputs('require'); + excBoxes = inputs('exclude'); allBoxes = [...reqBoxes, ...excBoxes]; tags = new Map(items.map(item => [item, item.dataset.tags.split(';')])); diff --git a/script/single.js b/script/single.js index a40d5b0..3d30537 100644 --- a/script/single.js +++ b/script/single.js @@ -4,6 +4,7 @@ let mainfig; let mainimg; let mainlink; +let altButtons; let opened = new Set; @@ -58,12 +59,12 @@ function activateButton(button, doPush = true, firstLoad = false) { } function useFragment(firstLoad = false) { - let button = document.querySelector('#alts input'); + let button; let frag = location.hash.replace(/^#/, ''); if (frag) { - let button0 = document.getElementById(frag); - if (button0) button = button0; + let selected = document.getElementById(frag); + button = selected ? selected : altButtons[0]; } let id; @@ -81,8 +82,9 @@ function setup() { mainfig = document.getElementById('mainfig'); mainimg = document.getElementById('mainimg'); 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); }; }