if ($Request and $Request =~ m{\A([^/]+)}) {
my $name = $1;
my $page = "word/$name.plp";
- $wordlistbase .= ".$lang";
if (-e $page) {
utf8::downgrade($page); # unicode filename breaks contents encoding
Include $page;
});
say '<h1>Words</h1>';
say '<section id="gallery"></section>';
- say "<script>new Word\u$name('/$wordlistbase.json')</script>";
+ say "<script>new Word\u$name()</script>";
}
exit;
}
.forEach(card => put(card, '!.turn!.bad'));
}
- load(dataurl) {
- if (dataurl) {
- super.load(dataurl);
- }
- else {
+ load() {
+ if (this.preset.pairs) {
this.dataurl = '/data/wordpairs.json';
fetch(this.dataurl).then(res => res.json()).then(pairs => {
this.pairs = pairs;
this.setup();
});
}
+ else {
+ super.load();
+ }
}
setup() {
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();
});
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();
};
}
}