Basic kanji output

This commit is contained in:
Alex Yatskov 2016-04-24 18:59:29 -07:00
parent a192a8d8b5
commit cac6fc1427
5 changed files with 38 additions and 19 deletions

View File

@ -74,11 +74,16 @@ class Dictionary {
findKanji(kanji) {
const results = [];
for (const name in this.termDicts) {
const def = this.termDicts[name][kanji];
for (const name in this.kanjiDicts) {
const def = this.kanjiDicts[name][kanji];
if (def) {
const [c, k, o, g] = def;
results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
const [k, o, g] = def;
results.push({
character: kanji,
kunyomi: k.split(' '),
onyomi: o.split(' '),
glossary: g
});
}
}

View File

@ -34,6 +34,19 @@ templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":functi
+ container.escapeExpression(((helper = (helper = helpers.kanji || (depth0 != null ? depth0.kanji : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"kanji","hash":{},"data":data}) : helper)))
+ "</a>\n";
},"useData":true});
templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1;
return "<div class=\"definition\">\n"
+ ((stack1 = container.invokePartial(partials["kanji.html"],depth0,{"name":"kanji.html","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ "</div>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"usePartial":true,"useData":true});
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
"<div class=\"term\"><ruby>";

View File

@ -132,10 +132,10 @@ class Translator {
findKanji(text) {
let results = [];
const processed = {};
for (const c of text) {
if (!processed.has(c)) {
if (!processed[c]) {
results = results.concat(this.dictionary.findKanji(c));
processed[c] = true;
}

View File

@ -50,7 +50,7 @@ class Yomichan {
onMessage(request, sender, callback) {
const {action, data} = request, handlers = {
findKanji: ({text}) => this.translator.onFindKanji(text),
findKanji: ({text}) => this.translator.findKanji(text),
findTerm: ({text}) => this.translator.findTerm(text),
getState: () => this.state,
getOptions: () => this.options,

View File

@ -26,6 +26,7 @@ class Client {
this.activateBtn = 2;
this.enabled = false;
this.options = {};
this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
window.addEventListener('message', this.onFrameMessage.bind(this));
@ -101,14 +102,8 @@ class Client {
this.hidePopup();
} else {
range.setLength(length);
const params = {
defs: results,
root: chrome.extension.getURL('fg')
};
renderText(
params,
{defs: results, root: this.fgRoot},
'term-list.html',
(content) => this.showPopup(range, content)
);
@ -116,6 +111,16 @@ class Client {
});
}
displayKanji(kanji) {
findKanji(kanji, (results) => {
renderText(
{defs: results, root: this.fgRoot},
'kanji-list.html',
(content) => this.popup.setContent(content)
);
});
}
showPopup(range, content) {
this.popup.showNextTo(range.getRect(), content);
@ -136,10 +141,6 @@ class Client {
this.lastRange = null;
}
displayKanji(kanji) {
this.popup.setContent(kanji);
}
setEnabled(enabled) {
if (!(this.enabled = enabled)) {
this.hidePopup();