From: Mischa POSLAWSKY Date: Mon, 6 Jun 2022 19:40:14 +0000 (+0200) Subject: word/quiz: generic page container setup X-Git-Tag: v1.14~64 X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/0ef06cdf3844c0899ea9f64670c41668301dfcc5 word/quiz: generic page container setup --- diff --git a/word.plp b/word.plp index 5571299..0635161 100644 --- a/word.plp +++ b/word.plp @@ -18,7 +18,7 @@ if ($Request and $Request =~ m{\A([^/]+)}) { lang => $lang, }); say '

Words

'; - say ''; + say '
'; say ""; } exit; diff --git a/word/finder.js b/word/finder.js index 734e4b0..e842d06 100644 --- a/word/finder.js +++ b/word/finder.js @@ -41,11 +41,11 @@ class WordFinder extends WordQuiz { } setup() { - this.gallery = document.getElementById('gallery'); - this.gallery.innerHTML = ''; - put(this.gallery, 'p', 'Under construction.'); + super.setup(); + this.form.innerHTML = ''; + put(this.form, 'p', 'Under construction.'); for (let cat of this.preset.cat || this.data[''][3]) { - this.add(put(this.gallery, 'ul.gallery'), [cat]); + this.add(put(this.form, 'ul.gallery'), [cat]); } } diff --git a/word/memory.js b/word/memory.js index 99e76e8..a70ec06 100644 --- a/word/memory.js +++ b/word/memory.js @@ -42,6 +42,7 @@ class WordMemory extends WordQuiz { } load() { + this.configure(); if (this.preset.pairs) { this.dataurl = '/data/wordpairs.json'; fetch(this.dataurl).then(res => res.json()).then(pairs => { @@ -55,8 +56,10 @@ class WordMemory extends WordQuiz { } setup() { + super.setup(); this.turned = []; - this.form = document.getElementById('quiz'); + this.form.innerHTML = ''; + this.form.className = ''; let cards; if (this.words) { diff --git a/word/multichoice.js b/word/multichoice.js index 58ed7b7..680cf0d 100644 --- a/word/multichoice.js +++ b/word/multichoice.js @@ -25,7 +25,7 @@ class WordMultiChoice extends WordQuiz { } setup() { - this.form = document.getElementById('quiz'); + super.setup(); this.next(); } }; diff --git a/word/quiz.js b/word/quiz.js index 68c2ee8..3243b19 100644 --- a/word/quiz.js +++ b/word/quiz.js @@ -62,7 +62,7 @@ class WordQuiz { return selection; } - configure(params) { + configure(params = window.location.hash.split('#')) { const opts = new Map(params.map(arg => arg.split(/[:=](.*)/))); for (let [query, val] of opts) { if (query.match(/^\d+$/)) { @@ -78,8 +78,12 @@ class WordQuiz { this.preset.dataurl = `/data/wordlist.${this.preset.lang}.json` } + setup() { + this.form = document.getElementById('quiz'); + } + load() { - this.configure(window.location.hash.split('#')); + this.configure(); fetch(this.preset.dataurl).then(res => res.json()).then(json => { this.words = this.dataselect(json) this.setup(); diff --git a/word/wijzer.js b/word/wijzer.js index 7446cc9..2f73052 100644 --- a/word/wijzer.js +++ b/word/wijzer.js @@ -28,7 +28,8 @@ class WordWijzer extends WordQuiz { } setup() { - this.form = document.getElementById('quiz'); + super.setup(); + this.form.innerHTML = ''; this.question = put(this.form, 'figure'); this.words.splice(9)