word/finder: fix debug id references
[sheet.git] / word / finder.js
index 9f56a2c28c553ff7f5690278c46ec6cc0937ae71..9d2b6cf321ba4f3534ac31857df856b5d31a21ce 100644 (file)
@@ -1,6 +1,5 @@
 class WordFinder extends WordQuiz {
        namehtml(name) {
-               //let wbr = new RegExp('\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)', 'g');
                let aliases = name.split('/');
                let html = aliases.shift();
                html = html.replace(/\((.+)\)/, '<small>$1</small>');
@@ -11,35 +10,51 @@ class WordFinder extends WordQuiz {
        }
 
        add(catitem, rows) {
-               rows.forEach(ref => {
-                       const [title, level, imgid, subs] = this.data[ref];
+               rows.forEach(word => {
+                       if (!word) return;
                        const worditem = put(catitem, 'li');
                        const figitem = put(worditem, 'figure');
-                       if (imgid) {
-                               put(figitem, 'img[src=$]', `/data/word/32/${imgid}.jpg`);
+                       if (word.imgid) {
+                               put(figitem, 'img[src=$]', word.thumb());
                        }
-                       if (title) {
+                       if (word.title) {
                                put(figitem, 'figcaption', {
-                                       innerHTML: this.namehtml(title),
+                                       innerHTML: this.namehtml(word.title),
                                });
                        }
-                       if (level <= 1 && subs.length >= 2) {
+                       put(worditem, '.level' + word.level);
+                       if (word.level <= 1 && word.subs.length >= 4) {
                                put(worditem, '.large');
                        }
-                       if (subs.length) {
+                       if (word.subs.length) {
                                // delve into subcategory
                                put(worditem, '.parent');
-                               this.add(put(worditem, 'ul'), subs);
+                               const expansion = put(worditem, 'ul');
+                               //expansion.style.display = 'none';
+                               this.add(expansion, word.subs);
+                               //worditem.onclick = () => expansion.style.display = '';
+                       }
+                       if (this.preset.debug) {
+                               put(figitem, '[title=$]', `id ${word.id} level ${word.level}`);
                        }
                });
        }
 
+       configure(input) {
+               this.preset.level = 3;
+               this.preset.images = false;
+               return super.configure(input);
+       }
+
        setup() {
-               this.gallery = document.getElementById('gallery');
-               this.gallery.innerHTML = '';
-               put(this.gallery, 'p', 'Under construction.');
-               for (let cat of this.preset.cat ? [this.preset.cat] : this.data[''][3]) {
-                       this.add(put(this.gallery, 'ul.gallery'), [cat]);
+               super.setup();
+               if (this.preset.debug) {
+                       put(document.head, 'link', {rel: 'stylesheet', href: '/word/debug.css'});
+               }
+               this.form.innerHTML = '';
+               put(this.form, 'p', 'Under construction.');
+               for (let cat of this.data.root()) {
+                       this.add(put(this.form, 'ul.gallery'), [cat]);
                }
        }