630db8e8f8ff21af26f979f17742658e32f91988
[sheet.git] / word / finder.js
1 class WordFinder extends WordQuiz {
2         namehtml(name) {
3                 let aliases = name.split('/');
4                 let html = aliases.shift();
5                 html = html.replace(/\((.+)\)/, '<small>$1</small>');
6                 for (let alias of aliases) {
7                         html += ` <small>(${alias})</small>`;
8                 }
9                 return html;
10         }
11
12         add(catitem, rows) {
13                 rows.forEach(word => {
14                         if (!word) return;
15                         const worditem = put(catitem, 'li');
16                         const figitem = put(worditem, 'figure');
17                         if (word.imgid) {
18                                 put(figitem, 'img[src=$]', word.thumb());
19                         }
20                         if (word.title) {
21                                 put(figitem, 'figcaption', {
22                                         innerHTML: this.namehtml(word.title),
23                                 });
24                         }
25                         put(worditem, '.level' + word.level);
26                         if (word.level <= 1 && word.subs.length >= 4) {
27                                 put(worditem, '.large');
28                         }
29                         if (word.subs.length) {
30                                 // delve into subcategory
31                                 put(worditem, '.parent');
32                                 this.add(put(worditem, 'ul'), word.subs);
33                         }
34                         if (this.preset.debug) {
35                                 put(figitem, '[title=$]', `id ${ref} level ${word.level}`);
36                         }
37                 });
38         }
39
40         configure(input) {
41                 this.preset.level = 3;
42                 this.preset.images = false;
43                 return super.configure(input);
44         }
45
46         setup() {
47                 super.setup();
48                 if (this.preset.debug) {
49                         put(document.head, 'link', {rel: 'stylesheet', href: '/word/debug.css'});
50                 }
51                 this.form.innerHTML = '';
52                 put(this.form, 'p', 'Under construction.');
53                 for (let cat of this.data.root()) {
54                         this.add(put(this.form, 'ul.gallery'), [cat]);
55                 }
56         }
57
58         stop() {}
59 };