From 50f0dd83857d824ebf808ef252d3c614428c9dfb Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Sat, 5 Nov 2022 18:04:22 +0100 Subject: Add stories filter form JS --- docs/index.html | 3 +++ docs/stories.html | 21 ++++++++++----------- docs/stories.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 docs/stories.js (limited to 'docs') diff --git a/docs/index.html b/docs/index.html index cd7df22..4a16d7c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -25,6 +25,9 @@ + + + diff --git a/docs/stories.html b/docs/stories.html index e48400d..720a6ee 100644 --- a/docs/stories.html +++ b/docs/stories.html @@ -22,7 +22,7 @@
- @@ -30,8 +30,8 @@ - - @@ -39,8 +39,6 @@ - -
@@ -52,8 +50,8 @@
7 Pages - German - Shortstory + German + Shortstory
@@ -64,8 +62,8 @@
2 Pages - German - Shortstory + German + Shortstory
@@ -76,8 +74,8 @@
2 Pages - English - Screenplay + English + Screenplay
@@ -87,6 +85,7 @@ + diff --git a/docs/stories.js b/docs/stories.js new file mode 100644 index 0000000..e5a57ec --- /dev/null +++ b/docs/stories.js @@ -0,0 +1,34 @@ +// every story card +const workCards = document.querySelectorAll(".work-card"); + +// story type select input +const storyTypeSelect = document.querySelector("#story-type-select"); +// language select input +const languageSelect = document.querySelector("#language-select"); +// copy of works with all work cards +const works = Array.from(document.querySelector(".works").children); + +// filter cards based on storytype and language filter +function filterWorkCards() { + // restore initial state with all cards + // (TODO: Explore more efficient solutions without another loop) + document.querySelector(".works").replaceChildren(); + works.forEach((card) => { + document.querySelector(".works").appendChild(card); + }) + + // filter card if language or story type filter doesn't match + workCards.forEach((card) => { + if (languageSelect.value != "*" && card.querySelector(".story-language").innerHTML != languageSelect.value) { + document.querySelector(".works").removeChild(card); + } else if (storyTypeSelect.value != "*" && card.querySelector(".story-type").innerHTML != storyTypeSelect.value) { + document.querySelector(".works").removeChild(card); + } + }) +} + +// filter cards when +// story type selection changes +storyTypeSelect.addEventListener("change", filterWorkCards); +// language selection changes +languageSelect.addEventListener("change", filterWorkCards); -- cgit v1.2.3