Loading in all the json blobs
This commit is contained in:
parent
6f256ec25a
commit
4f19856f44
@ -17,21 +17,32 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Translator {
|
class Translator {
|
||||||
constructor(paths) {
|
constructor() {
|
||||||
this.paths = paths
|
this.rules = {};
|
||||||
this.rules = {}
|
this.edict = {};
|
||||||
|
this.enamdict = {};
|
||||||
|
this.kanjidic = {};
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(callback) {
|
initialize(paths, callback) {
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.when(
|
const loaders = [];
|
||||||
$.getJSON(chrome.extension.getURL(this.paths['rules']))
|
for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
|
||||||
).done(rules => {
|
loaders.push(
|
||||||
this.rules = rules;
|
$.getJSON(chrome.extension.getURL(paths[key]))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$.when.apply($, loaders).done((rules, edict, enamdict, kanjidic) => {
|
||||||
|
this.rules = rules;
|
||||||
|
this.edict = edict;
|
||||||
|
this.enamdict = enamdict;
|
||||||
|
this.kanjidic = kanjidic;
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -41,8 +52,13 @@ class Translator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let trans = new Translator({
|
const trans = new Translator();
|
||||||
rules: 'jp/data/rules.json'
|
|
||||||
});
|
|
||||||
|
|
||||||
trans.initialize();
|
trans.initialize({
|
||||||
|
rules: 'jp/data/rules.json',
|
||||||
|
edict: 'jp/data/edict.json',
|
||||||
|
enamdict: 'jp/data/enamdict.json',
|
||||||
|
kanjidic: 'jp/data/kanjidic.json',
|
||||||
|
}, function() {
|
||||||
|
alert('Loaded');
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user