const instead of let where possible
This commit is contained in:
parent
0de54d15d4
commit
b2e2db77dd
3 changed files with 39 additions and 41 deletions
|
@ -18,30 +18,30 @@ function fillSets(): [Set<string>, Set<string>] {
|
|||
}
|
||||
|
||||
function updateItems() {
|
||||
let [reqTags, excTags] = fillSets();
|
||||
let anyReq = reqTags.size > 0;
|
||||
const [reqTags, excTags] = fillSets();
|
||||
const anyReq = reqTags.size > 0;
|
||||
|
||||
for (let [year, items] of itemsByYear) {
|
||||
for (const [year, items] of itemsByYear) {
|
||||
let hide = true;
|
||||
|
||||
for (let item of items) {
|
||||
let req = tags.get(item)?.some(x => reqTags.has(x)) ?? false;
|
||||
let exc = tags.get(item)?.some(x => excTags.has(x)) ?? false;
|
||||
let hidden = exc || (anyReq && !req);
|
||||
for (const item of items) {
|
||||
const req = tags.get(item)?.some(x => reqTags.has(x)) ?? false;
|
||||
const exc = tags.get(item)?.some(x => excTags.has(x)) ?? false;
|
||||
const hidden = exc || (anyReq && !req);
|
||||
|
||||
item.hidden = hidden;
|
||||
hide &&= hidden;
|
||||
}
|
||||
|
||||
let marker = document.getElementById(`marker-${year}`);
|
||||
const marker = document.getElementById(`marker-${year}`);
|
||||
if (marker !== null) marker.hidden = hide;
|
||||
}
|
||||
|
||||
function disp(pfx: string, tags: Iterable<string>) {
|
||||
return [...tags].map(x => pfx + x).join('\u2003'); // em space
|
||||
}
|
||||
let plus = disp('+\u2009', Array.from(reqTags)); // thin space
|
||||
let minus = disp('-\u2009', Array.from(excTags));
|
||||
const plus = disp('+\u2009', reqTags); // thin space
|
||||
const minus = disp('-\u2009', excTags);
|
||||
document.getElementById('filters-details')!.dataset.filters =
|
||||
`${plus}\u2003${minus}`.trim();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ function converseId(id: string) {
|
|||
|
||||
function toggle(checkbox: HTMLInputElement) {
|
||||
if (checkbox.checked) {
|
||||
let converse = document.getElementById(converseId(checkbox.id)) as HTMLInputElement;
|
||||
const converse = document.getElementById(converseId(checkbox.id)) as HTMLInputElement;
|
||||
converse.checked = false;
|
||||
}
|
||||
update();
|
||||
|
@ -81,10 +81,10 @@ function clear(e: Event) {
|
|||
function toggleSingles(e: Event) {
|
||||
showSingles = !showSingles;
|
||||
|
||||
let elems = Array.from(document.querySelectorAll('.filterlist li'));
|
||||
for (let li of elems) {
|
||||
let countStr = li.querySelector('label')?.dataset.count;
|
||||
let count = countStr ? +countStr : 0;
|
||||
const elems = Array.from(document.querySelectorAll('.filterlist li')) as HTMLElement[];
|
||||
for (const li of elems) {
|
||||
const countStr = li.querySelector('label')?.dataset.count;
|
||||
const count = countStr ? +countStr : 0;
|
||||
if (count <= 1 && li instanceof HTMLElement) {
|
||||
li.hidden = !showSingles;
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ function toggleSingles(e: Event) {
|
|||
|
||||
|
||||
function makeFragment() {
|
||||
let allBoxesArr = Array.from(allBoxes);
|
||||
let ids = allBoxesArr.filter(b => b.checked).map(b => b.id);
|
||||
const allBoxesArr = Array.from(allBoxes);
|
||||
const ids = allBoxesArr.filter(b => b.checked).map(b => b.id);
|
||||
if (ids.length == 0) {
|
||||
return '#all';
|
||||
} else if (allBoxesArr.every(b => b.checked == b.defaultChecked)) {
|
||||
|
@ -107,8 +107,8 @@ function makeFragment() {
|
|||
}
|
||||
|
||||
function useFragment() {
|
||||
let frag = decodeURIComponent(location.hash).replace(/^#/, '');
|
||||
let details = document.getElementById('filters-details') as HTMLDetailsElement;
|
||||
const frag = decodeURIComponent(location.hash).replace(/^#/, '');
|
||||
const details = document.getElementById('filters-details') as HTMLDetailsElement;
|
||||
|
||||
if (!frag) {
|
||||
clearForm();
|
||||
|
@ -116,8 +116,8 @@ function useFragment() {
|
|||
allBoxes.forEach(b => b.checked = false);
|
||||
details.open = false;
|
||||
} else {
|
||||
let set = new Set(frag.split(';'));
|
||||
let re = /^(require|exclude)_|hide_filters/;
|
||||
const set = new Set(frag.split(';'));
|
||||
const re = /^(require|exclude)_|hide_filters/;
|
||||
if (Array.from(set).every(x => re.test(x))) {
|
||||
allBoxes.forEach(b => b.checked = set.has(b.id));
|
||||
details.open = !frag.match(/hide_filters|example\b/);
|
||||
|
@ -130,12 +130,12 @@ function useFragment() {
|
|||
|
||||
function sortFilters(cmp: (a: Node, b: Node) => number) {
|
||||
function sort1(id: string) {
|
||||
let elt = document.getElementById(id);
|
||||
const elt = document.getElementById(id);
|
||||
if (elt === null) return;
|
||||
|
||||
let children = Array.from(elt.childNodes);
|
||||
const children = Array.from(elt.childNodes);
|
||||
children.sort(cmp);
|
||||
for (let c of children) {
|
||||
for (const c of children) {
|
||||
elt.removeChild(c);
|
||||
elt.appendChild(c);
|
||||
}
|
||||
|
@ -175,15 +175,15 @@ function sortFiltersUses(e: Event) {
|
|||
|
||||
function setup() {
|
||||
function inputs(id: string): Boxes {
|
||||
let iter = document.getElementById(id)!.getElementsByTagName('input');
|
||||
const iter = document.getElementById(id)!.getElementsByTagName('input');
|
||||
return new Set(Array.from(iter));
|
||||
}
|
||||
|
||||
let items = Array.from(document.getElementsByClassName('post')) as HTMLElement[];
|
||||
const items = Array.from(document.getElementsByClassName('post')) as HTMLElement[];
|
||||
|
||||
itemsByYear = new Map;
|
||||
for (let item of items) {
|
||||
let year = item.dataset.year;
|
||||
for (const item of items) {
|
||||
const year = item.dataset.year;
|
||||
if (year !== undefined) {
|
||||
if (!itemsByYear.has(year)) {
|
||||
itemsByYear.set(year, new Set([item]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue