word/quiz: dynamic lang(uage) option
[sheet.git] / word / quiz.js
index f47fde12f906aa6747dd6e071cd5b2a99c004c40..68c2ee81e69e1b7ccaaa34fa43e463cce76852bd 100644 (file)
@@ -75,11 +75,12 @@ class WordQuiz {
                                this.preset[query] = val;
                        }
                }
+               this.preset.dataurl = `/data/wordlist.${this.preset.lang}.json`
        }
 
-       load(dataurl) {
+       load() {
                this.configure(window.location.hash.split('#'));
-               fetch(dataurl).then(res => res.json()).then(json => {
+               fetch(this.preset.dataurl).then(res => res.json()).then(json => {
                        this.words = this.dataselect(json)
                        this.setup();
                });
@@ -95,15 +96,15 @@ class WordQuiz {
                fetch('/word/report', {method: 'POST', body: JSON.stringify(this.history)});
        }
 
-       constructor(dataurl) {
-               this.preset = {images: true};
-               this.load(dataurl);
+       constructor() {
+               this.preset = {images: true, lang: 'en'};
+               this.load();
                this.history = [];
                window.onbeforeunload = e => {
                        this.stop('abort');
                };
                window.onhashchange = e => {
-                       this.load(dataurl);
+                       this.load();
                };
        }
 }