let ids = new Set(Object.keys(json));
const selection = {...json}; // clone
+ for (let cat of selection[''][3]) {
+ if (selection[cat])
+ selection[cat][1] = 0; // keep root categories
+ }
+
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) {
selection[id][3] = function subresolve(subs) {
//console.log(subs);
return (subs || []).flatMap(sub =>
- sub in selection ? [sub] : subresolve(json[sub][3])
+ sub in selection ? [sub] : json[sub] ? subresolve(json[sub][3]) : []
);
}(selection[id][3]);
}
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 => {