This commit is contained in:
Alex Yatskov 2016-04-17 17:36:15 -07:00
parent be43981e25
commit bcd34149ab
4 changed files with 26 additions and 6 deletions

View File

@ -7,13 +7,15 @@ templates['defs.html'] = template({"1":function(container,depth0,helpers,partial
+ ((stack1 = container.invokePartial(partials["term.html"],depth0,{"name":"term.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, helper, alias1=depth0 != null ? depth0 : {};
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title></title>\n <link rel=\"stylesheet\" href=\""
+ container.escapeExpression(((helper = (helper = helpers.root || (depth0 != null ? depth0.root : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"root","hash":{},"data":data}) : helper)))
+ alias4(((helper = (helper = helpers.root || (depth0 != null ? depth0.root : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"root","hash":{},"data":data}) : helper)))
+ "/css/popup.css\">\n </head>\n <body>\n <div class=\"dictionary\">\n <a href=\"javascript:selectDict('edict');\">単</a><a href=\"javascript:selectDict('enamdict')\">名</a><a href=\"javascript:selectDict('kanjidic');\">漢</a>\n </div>\n\n"
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </body>\n</html>\n";
+ "\n <script src=\""
+ alias4(((helper = (helper = helpers.root || (depth0 != null ? depth0.root : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"root","hash":{},"data":data}) : helper)))
+ "/js/popup.js\"></script>\n </body>\n</html>\n";
},"usePartial":true,"useData":true});
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;

View File

@ -31,7 +31,8 @@ class Client {
this.popup.addEventListener('scroll', (e) => e.stopPropagation());
document.body.appendChild(this.popup);
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
window.addEventListener('message', this.onFrameMessage.bind(this));
window.addEventListener('mousedown', this.onMouseDown.bind(this));
window.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('keydown', this.onKeyDown.bind(this));
@ -39,6 +40,7 @@ class Client {
window.addEventListener('resize', (e) => this.hidePopup());
getOptions((opts) => {
this.setDict('edict');
this.setOptions(opts);
getState((state) => this.setEnabled(state === 'enabled'));
});
@ -66,7 +68,7 @@ class Client {
}
}
onMessage({name, value}, sender, callback) {
onBgMessage({name, value}, sender, callback) {
switch (name) {
case 'state':
this.setEnabled(value === 'enabled');
@ -79,6 +81,15 @@ class Client {
callback();
}
onFrameMessage(e) {
const {action, data} = e.data;
switch (action) {
case 'selectDict':
this.setDict(data);
break;
}
}
searchAtPoint(point) {
const range = getRangeAtPoint(point, this.options.scanLength);
if (range === null) {
@ -156,6 +167,11 @@ class Client {
setOptions(opts) {
this.options = opts;
}
setDict(dict) {
this.dict = dict;
alert(dict);
}
}
window.yomiClient = new Client();

View File

@ -20,7 +20,7 @@
"background": {"page": "bg/background.html"},
"options_page": "bg/options.html",
"permissions": ["storage"],
"web_accessible_resources": ["fg/css/popup.css"],
"web_accessible_resources": ["fg/css/popup.css", "fg/js/popup.js"],
"content_scripts": [{
"matches": ["*://*/*"],

View File

@ -15,5 +15,7 @@
{{> term.html}}
</div>
{{/each}}
<script src="{{root}}/js/popup.js"></script>
</body>
</html>