aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-03-20 12:26:10 -0700
committerAlex Yatskov <alex@foosoft.net>2016-03-20 12:26:10 -0700
commit4f19856f44237bf596321b7e6ef3e442a4276599 (patch)
treeb3b3e833c97538904d47010226ca2cfaf9cd4a9d /ext
parent6f256ec25aeafa366b1af8bd628b81741d8ac40d (diff)
Loading in all the json blobs
Diffstat (limited to 'ext')
-rw-r--r--ext/jp/translator.js40
1 files changed, 28 insertions, 12 deletions
diff --git a/ext/jp/translator.js b/ext/jp/translator.js
index fabbc2b7..be15c397 100644
--- a/ext/jp/translator.js
+++ b/ext/jp/translator.js
@@ -17,21 +17,32 @@
*/
class Translator {
- constructor(paths) {
- this.paths = paths
- this.rules = {}
+ constructor() {
+ this.rules = {};
+ this.edict = {};
+ this.enamdict = {};
+ this.kanjidic = {};
this.initialized = false;
}
- initialize(callback) {
+ initialize(paths, callback) {
if (this.initialized) {
return;
}
- $.when(
- $.getJSON(chrome.extension.getURL(this.paths['rules']))
- ).done(rules => {
- this.rules = rules;
+ const loaders = [];
+ for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
+ loaders.push(
+ $.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;
if (callback) {
@@ -41,8 +52,13 @@ class Translator {
}
}
-let trans = new Translator({
- rules: 'jp/data/rules.json'
-});
+const trans = new Translator();
-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');
+});