word/finder: collapse categories until clicked
[sheet.git] / word / finder.js
index 9d2b6cf321ba4f3534ac31857df856b5d31a21ce..ed8905462a098fb43e4029dddb0d468baacd8284 100644 (file)
@@ -22,21 +22,37 @@ class WordFinder extends WordQuiz {
                                        innerHTML: this.namehtml(word.title),
                                });
                        }
+                       if (this.preset.debug) {
+                               put(figitem, '[title=$]', `id ${word.id} level ${word.level}`);
+                       }
                        put(worditem, '.level' + word.level);
+                       if (!word.subs.length) {
+                               return;
+                       }
                        if (word.level <= 1 && word.subs.length >= 4) {
                                put(worditem, '.large');
                        }
-                       if (word.subs.length) {
-                               // delve into subcategory
-                               put(worditem, '.parent');
-                               const expansion = put(worditem, 'ul');
-                               //expansion.style.display = 'none';
+                       put(worditem, '.parent.expand');
+
+                       put(figitem, '[data-sup=$]', word.subs.length);
+                       figitem.onclick = () => {
+                               let expansion;
+                               if (expansion = worditem.querySelector('ul')) {
+                                       put(expansion, '!');
+                                       put(worditem, '.expand');
+                                       return;
+                               }
+                               expansion = put(worditem, 'ul');
                                this.add(expansion, word.subs);
-                               //worditem.onclick = () => expansion.style.display = '';
-                       }
-                       if (this.preset.debug) {
-                               put(figitem, '[title=$]', `id ${word.id} level ${word.level}`);
-                       }
+                               put(worditem, '!expand');
+                       };
+                       return;
+
+                       // delve into subcategory
+                       const expansion = put(worditem, 'ul');
+                       //expansion.style.display = 'none';
+                       this.add(expansion, word.subs);
+                       //worditem.onclick = () => expansion.style.display = '';
                });
        }