word/finder: fix debug id references
[sheet.git] / word / finder.js
index a45dee4a06db6e3c7fc1c6fc4b808d4759dd9755..9d2b6cf321ba4f3534ac31857df856b5d31a21ce 100644 (file)
@@ -1,39 +1,61 @@
 class WordFinder extends WordQuiz {
-       add(parentitem, rows) {
-               const catitem = put(parentitem, 'ul');
-               rows.forEach(ref => {
-                       const [title, level, imgid] = this.data[ref];
+       namehtml(name) {
+               let aliases = name.split('/');
+               let html = aliases.shift();
+               html = html.replace(/\((.+)\)/, '<small>$1</small>');
+               for (let alias of aliases) {
+                       html += ` <small>(${alias})</small>`;
+               }
+               return html;
+       }
+
+       add(catitem, rows) {
+               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) {
-                               let html = title.replace(/\/(.*)/, ' <small>($1)</small>');
+                       if (word.title) {
                                put(figitem, 'figcaption', {
-                                       innerHTML: html,
+                                       innerHTML: this.namehtml(word.title),
                                });
                        }
-                       let levelpart = level <= 1 && this.cats[ref] && this.cats[ref].length > 1;
-                       if (levelpart) {
+                       put(worditem, '.level' + word.level);
+                       if (word.level <= 1 && word.subs.length >= 4) {
                                put(worditem, '.large');
                        }
-                       if (this.cats[ref]) {
+                       if (word.subs.length) {
                                // delve into subcategory
                                put(worditem, '.parent');
-                               this.add(worditem, this.cats[ref].sort((a, b) => {
-                                       const [worda, wordb] = [this.data[a], this.data[b]];
-                                       return (worda[1] % 1) - (wordb[1] % 1)
-                                               || worda[0].localeCompare(wordb[0]);
-                               }));
+                               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');
-               put(this.gallery, '-p', 'Under construction.');
-               this.add(this.gallery, this.preset.cat ? [this.preset.cat] : this.cats[null]);
+               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]);
+               }
        }
 
        stop() {}