word: category references (recursive selection)
[sheet.git] / word / finder.js
index a45dee4a06db6e3c7fc1c6fc4b808d4759dd9755..ea1781d16ad3d5ee528d7b027a79ee62a0a8d648 100644 (file)
@@ -2,7 +2,7 @@ class WordFinder extends WordQuiz {
        add(parentitem, rows) {
                const catitem = put(parentitem, 'ul');
                rows.forEach(ref => {
-                       const [title, level, imgid] = this.data[ref];
+                       const [title, level, imgid, subs] = this.data[ref];
                        const worditem = put(catitem, 'li');
                        const figitem = put(worditem, 'figure');
                        if (imgid) {
@@ -14,18 +14,13 @@ class WordFinder extends WordQuiz {
                                        innerHTML: html,
                                });
                        }
-                       let levelpart = level <= 1 && this.cats[ref] && this.cats[ref].length > 1;
-                       if (levelpart) {
+                       if (level <= 1 && subs.length >= 2) {
                                put(worditem, '.large');
                        }
-                       if (this.cats[ref]) {
+                       if (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]);
-                               }));
+                               this.add(worditem, subs);
                        }
                });
        }
@@ -33,7 +28,7 @@ class WordFinder extends WordQuiz {
        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]);
+               this.add(this.gallery, this.preset.cat ? [this.preset.cat] : this.data[''][3]);
        }
 
        stop() {}