From e89970d33957e9a39a39839f4a82217c87d793af Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sun, 7 Jul 2024 21:41:25 +0200 Subject: [PATCH] instanceof instead of nodeType --- script/gallery.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/script/gallery.ts b/script/gallery.ts index 1671a9d..6fd4f2d 100644 --- a/script/gallery.ts +++ b/script/gallery.ts @@ -146,10 +146,9 @@ function sortFilters(cmp: (a: Node, b: Node) => number) { } function sortFiltersAlpha(e: Event) { - function getName(node: Node) { - if (node.nodeType == Node.ELEMENT_NODE) { - let elt = node as Element; - return elt.getElementsByTagName('input')[0].value; + function getName(node: Node): string { + if (node instanceof Element) { + return node.getElementsByTagName('input')[0].value; } else { return ''; } @@ -160,9 +159,8 @@ function sortFiltersAlpha(e: Event) { function sortFiltersUses(e: Event) { function getUses(node: Node) { - if (node.nodeType == Node.ELEMENT_NODE) { - let elt = node as Element; - let countStr = elt.getElementsByTagName('label')[0].dataset.count; + if (node instanceof Element) { + const countStr = node.getElementsByTagName('label')[0].dataset.count; return countStr ? +countStr : 0; } else { return 0;