});
}
+ configure(input) {
+ this.preset.level = 3;
+ this.preset.images = false;
+ return super.configure(input);
+ }
+
setup() {
this.gallery = document.getElementById('gallery');
this.gallery.innerHTML = '';
put(this.gallery, 'p', 'Under construction.');
- for (let cat of this.preset.cat ? [this.preset.cat] : this.data[''][3]) {
+ for (let cat of this.preset.cat || this.data[''][3]) {
this.add(put(this.gallery, 'ul.gallery'), [cat]);
}
}
if (this.words) {
const aspect = this.form.clientWidth / window.innerHeight;
//TODO image ratio
- let count = 35;
+ let count = parseInt(this.preset.n) || 35;
let cols = Math.round(Math.sqrt(count) * aspect**.5);
count = cols * Math.ceil(count / cols);
this.form.style['grid-template-columns'] = `repeat(${cols}, 1fr)`;
next() {
if (this.words.length < 4) return;
let word = this.words.shift();
- if (!word[2]) return this.next();
let form = put(this.form,
'+img[src=$]+ul', `/data/word/32/${word[2]}.jpg`,
);
if (this.preset.cat !== undefined) {
ids.clear();
- let children = [this.preset.cat];
+ let children = this.preset.cat;
for (let loop = 0; children.length && loop < 20; loop++) {
for (let child of children) ids.add(child.toString());
children = children.map(cat => json[cat][3]).filter(is => is).flat()
}
}
- if (this.preset.image) {
+ if (this.preset.images) {
ids = ids.filter(id => json[id][2]);
}
if (this.preset.level !== undefined) {
return selection;
}
- load(dataurl) {
- this.preset = {};
- let input;
- if (input = window.location.hash.match(/\d+/)) {
- this.preset.cat = parseInt(input[0]);
- }
- if (window.location.hash.match(/a/)) {
- this.preset.level = 3;
+ configure(params) {
+ const opts = new Map(params.map(arg => arg.split(/[:=](.*)/)));
+ for (let [query, val] of opts) {
+ if (query.match(/^\d+$/)) {
+ this.preset.cat = [parseInt(query)];
+ }
+ else if (query === 'level') {
+ this.preset.level = parseInt(val);
+ }
+ else {
+ this.preset[query] = val;
+ }
}
+ }
+ load(dataurl) {
+ this.configure(window.location.hash.split('#'));
fetch(dataurl).then(res => res.json()).then(json => {
this.words = this.dataselect(json)
this.setup();
}
constructor(dataurl) {
+ this.preset = {images: true};
this.load(dataurl);
this.history = [];
window.onbeforeunload = e => {