word/finder: move html formatting into common method
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 20 Dec 2023 22:51:03 +0000 (23:51 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 28 Dec 2023 07:19:58 +0000 (08:19 +0100)
word/finder.js
word/quiz.js

index ed8905462a098fb43e4029dddb0d468baacd8284..3dca29b8711061be90d9cbe5193fbca7c8329c7e 100644 (file)
@@ -1,14 +1,4 @@
 class WordFinder extends WordQuiz {
-       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;
@@ -19,7 +9,7 @@ class WordFinder extends WordQuiz {
                        }
                        if (word.title) {
                                put(figitem, 'figcaption', {
-                                       innerHTML: this.namehtml(word.title),
+                                       innerHTML: word.html,
                                });
                        }
                        if (this.preset.debug) {
index 5498809f67ceb2bbb0ce9a7d31ab8205217b6277..44703948f369b7cb09f4ad9c2b0466ef3b9a1b0f 100644 (file)
@@ -83,6 +83,15 @@ class Words {
                        get label() {
                                return row[0].replace(/\/.*/, ''); // primary form
                        },
+                       get html() {
+                               let aliases = this.title.split('/');
+                               let html = aliases.shift();
+                               html = html.replace(/\((.+)\)/, '<small>$1</small>');
+                               for (let alias of aliases) {
+                                       html += ` <small>(${alias})</small>`;
+                               }
+                               return html;
+                       },
                        level: row[1],
                        imgid: row[2],
                        thumb(size = 32) {