word: reload page to apply changed location hash
[sheet.git] / word / finder.js
1 class WordFinder extends WordQuiz {
2         add(catitem, rows) {
3                 rows.forEach(ref => {
4                         const [title, level, imgid, subs] = this.data[ref];
5                         const worditem = put(catitem, 'li');
6                         const figitem = put(worditem, 'figure');
7                         if (imgid) {
8                                 put(figitem, 'img[src=$]', `/data/word/32/${imgid}.jpg`);
9                         }
10                         if (title) {
11                                 let html = title.replace(/\/(.*)/, ' <small>($1)</small>');
12                                 put(figitem, 'figcaption', {
13                                         innerHTML: html,
14                                 });
15                         }
16                         if (level <= 1 && subs.length >= 2) {
17                                 put(worditem, '.large');
18                         }
19                         if (subs.length) {
20                                 // delve into subcategory
21                                 put(worditem, '.parent');
22                                 this.add(put(worditem, 'ul'), subs);
23                         }
24                 });
25         }
26
27         setup() {
28                 this.gallery = document.getElementById('gallery');
29                 this.gallery.innerHTML = '';
30                 put(this.gallery, 'p', 'Under construction.');
31                 for (let cat of this.preset.cat ? [this.preset.cat] : this.data[''][3]) {
32                         this.add(put(this.gallery, 'ul.gallery'), [cat]);
33                 }
34         }
35
36         stop() {}
37 };