Rethinking dictionary switching
This commit is contained in:
parent
5bebf3ed2c
commit
de268e73a6
@ -12,7 +12,7 @@ templates['header.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(c
|
|||||||
|
|
||||||
return "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title></title>\n <link rel=\"stylesheet\" href=\""
|
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(depth0 != null ? depth0 : {},{"name":"root","hash":{},"data":data}) : helper)))
|
+ container.escapeExpression(((helper = (helper = helpers.root || (depth0 != null ? depth0.root : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"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";
|
+ "/css/popup.css\">\n </head>\n <body>\n";
|
||||||
},"useData":true});
|
},"useData":true});
|
||||||
templates['kanji.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
|
templates['kanji.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
|
||||||
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
||||||
|
@ -50,26 +50,6 @@ body {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dictionary {
|
|
||||||
position: fixed;
|
|
||||||
right: 0px;
|
|
||||||
bottom: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dictionary a {
|
|
||||||
background-color: #333;
|
|
||||||
color: #eee;
|
|
||||||
display: inline-block;
|
|
||||||
font-size: 16px;
|
|
||||||
opacity: 0.75;
|
|
||||||
padding: 0.3em;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dictionary a:hover {
|
|
||||||
opacity: 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ol {
|
ol {
|
||||||
padding-left: 1.2em;
|
padding-left: 1.2em;
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.lastMosePos = null;
|
this.popupMousePos = null;
|
||||||
this.popupQuery = '';
|
this.popupQuery = '';
|
||||||
this.popupOffset = 10;
|
this.popupOffset = 10;
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
this.options = null;
|
this.options = {};
|
||||||
|
|
||||||
this.popup = document.createElement('iframe');
|
this.popup = document.createElement('iframe');
|
||||||
this.popup.classList.add('yomichan-popup');
|
this.popup.classList.add('yomichan-popup');
|
||||||
@ -40,29 +40,28 @@ class Client {
|
|||||||
window.addEventListener('resize', (e) => this.hidePopup());
|
window.addEventListener('resize', (e) => this.hidePopup());
|
||||||
|
|
||||||
getOptions((opts) => {
|
getOptions((opts) => {
|
||||||
this.setDict('edict');
|
|
||||||
this.setOptions(opts);
|
this.setOptions(opts);
|
||||||
getState((state) => this.setEnabled(state === 'enabled'));
|
getState((state) => this.setEnabled(state === 'enabled'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
if (this.enabled && this.lastMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) {
|
if (this.enabled && this.popupMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) {
|
||||||
this.searchAtPoint(this.lastMousePos);
|
this.searchAtPoint(this.popupMousePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseMove(e) {
|
onMouseMove(e) {
|
||||||
this.lastMousePos = {x: e.clientX, y: e.clientY};
|
this.popupMousePos = {x: e.clientX, y: e.clientY};
|
||||||
if (this.enabled && (e.shiftKey || e.which === 2)) {
|
if (this.enabled && (e.shiftKey || e.which === 2)) {
|
||||||
this.searchAtPoint(this.lastMousePos);
|
this.searchAtPoint(this.popupMousePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseDown(e) {
|
onMouseDown(e) {
|
||||||
this.lastMousePos = {x: e.clientX, y: e.clientY};
|
this.popupMousePos = {x: e.clientX, y: e.clientY};
|
||||||
if (this.enabled && (e.shiftKey || e.which === 2)) {
|
if (this.enabled && (e.shiftKey || e.which === 2)) {
|
||||||
this.searchAtPoint(this.lastMousePos);
|
this.searchAtPoint(this.popupMousePos);
|
||||||
} else {
|
} else {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
}
|
}
|
||||||
@ -82,12 +81,9 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFrameMessage(e) {
|
onFrameMessage(e) {
|
||||||
const {action, data} = e.data;
|
// const {action, data} = e.data;
|
||||||
switch (action) {
|
// switch (action) {
|
||||||
case 'selectDict':
|
// }
|
||||||
this.setDict(data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchAtPoint(point) {
|
searchAtPoint(point) {
|
||||||
@ -167,11 +163,6 @@ class Client {
|
|||||||
setOptions(opts) {
|
setOptions(opts) {
|
||||||
this.options = opts;
|
this.options = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDict(dict) {
|
|
||||||
this.dict = dict;
|
|
||||||
alert(dict);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.yomiClient = new Client();
|
window.yomiClient = new Client();
|
||||||
|
@ -6,6 +6,3 @@
|
|||||||
<link rel="stylesheet" href="{{root}}/css/popup.css">
|
<link rel="stylesheet" href="{{root}}/css/popup.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="dictionary">
|
|
||||||
<a href="javascript:selectDict('edict');">単</a><a href="javascript:selectDict('enamdict')">名</a><a href="javascript:selectDict('kanjidic');">漢</a>
|
|
||||||
</div>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user