use DOMContentLoaded

This commit is contained in:
Rhiannon Morris 2020-08-04 19:14:12 +02:00
parent 752dbbd1c4
commit 07d71de471
4 changed files with 24 additions and 18 deletions

View file

@ -32,7 +32,7 @@ make' (GalleryInfo {title, prefix, filters, hidden}) infos = [b|@0
<link rel=stylesheet href=/style/shiny/gallery.css title=shiny>
<link rel=alternate href=rss.xml type=application/rss+xml>
<script async src=/script/gallery.js></script>
<script src=/script/gallery.js></script>
<title>$*title</title>

View file

@ -34,7 +34,7 @@ make' nsfw dir info@(Info {date, title, artist}) = [b|@0
<meta name=viewport content="width=1200,viewport-fit=cover">
<link rel=stylesheet href=/style/shiny/single.css title=shiny>
<script async src=/script/single.js></script>
<script src=/script/single.js></script>
$0.prefetches

View file

@ -1,13 +1,11 @@
(function() {
'use strict';
let items = Array.from(document.querySelectorAll('.item.post'));
let reqBoxes = Array.from(document.querySelectorAll('#require input'));
let excBoxes = Array.from(document.querySelectorAll('#exclude input'));
let allBoxes = [...reqBoxes, ...excBoxes];
let tags = new Map(items.map(item => [item, item.dataset.tags.split(';')]));
let items;
let reqBoxes;
let excBoxes;
let allBoxes;
let tags;
function fillSets() {
@ -104,15 +102,25 @@ function useFragment(firstLoad) {
function setup() {
items = Array.from(document.querySelectorAll('.item.post'));
reqBoxes = Array.from(document.querySelectorAll('#require input'));
excBoxes = Array.from(document.querySelectorAll('#exclude input'));
allBoxes = [...reqBoxes, ...excBoxes];
tags = new Map(items.map(item => [item, item.dataset.tags.split(';')]));
allBoxes.forEach(b => b.addEventListener('change', () => toggle(b)));
document.getElementById('clear').addEventListener('click', clear);
document.getElementById('reset').addEventListener('click', reset);
window.addEventListener('popstate', () => useFragment(false));
useFragment(true);
}
window.addEventListener('load', setup);
window.addEventListener('DOMContentLoaded', setup);
})();

View file

@ -1,11 +1,9 @@
(function() {
'use strict';
function getById(id) { return document.getElementById(id); }
let mainfig = getById('mainfig');
let mainimg = getById('mainimg');
let mainlink = getById('mainlink');
let mainfig = document.getElementById('mainfig');
let mainimg = document.getElementById('mainimg');
let mainlink = document.getElementById('mainlink');
function openCW(caption, focusLink) {
mainfig.removeChild(caption);
@ -22,7 +20,7 @@ function addCWListeners(caption) {
}
function setImage(src, href, cw) {
let caption = getById('cw');
let caption = document.getElementById('cw');
let cwText = `<span id=cw-text>cw: <b>${cw}</b></span>`;
if (cw && caption) {
@ -54,9 +52,9 @@ function setup() {
button.onchange = e => { if (button.checked) activateButton(button); };
}
addCWListeners(getById('cw'));
addCWListeners(document.getElementById('cw'));
}
window.addEventListener('load', setup);
window.addEventListener('DOMContentLoaded', setup);
})();