From de268e73a613b963ea982f34ca7439d57694facd Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Apr 2016 18:42:44 -0700 Subject: [PATCH] Rethinking dictionary switching --- ext/bg/js/templates.js | 2 +- ext/fg/css/popup.css | 20 -------------------- ext/fg/js/client.js | 37 ++++++++++++++----------------------- util/tmpl/header.html | 3 --- 4 files changed, 15 insertions(+), 47 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index ca743e00..f571195d 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -12,7 +12,7 @@ templates['header.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(c return "\n\n \n \n \n \n \n \n
\n \n
\n"; + + "/css/popup.css\">\n \n \n"; },"useData":true}); 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; diff --git a/ext/fg/css/popup.css b/ext/fg/css/popup.css index 4e8dc5f7..250b64f8 100644 --- a/ext/fg/css/popup.css +++ b/ext/fg/css/popup.css @@ -50,26 +50,6 @@ body { 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 { padding-left: 1.2em; } diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 271caa58..09bd7d14 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -19,11 +19,11 @@ class Client { constructor() { - this.lastMosePos = null; - this.popupQuery = ''; - this.popupOffset = 10; - this.enabled = false; - this.options = null; + this.popupMousePos = null; + this.popupQuery = ''; + this.popupOffset = 10; + this.enabled = false; + this.options = {}; this.popup = document.createElement('iframe'); this.popup.classList.add('yomichan-popup'); @@ -40,29 +40,28 @@ class Client { window.addEventListener('resize', (e) => this.hidePopup()); getOptions((opts) => { - this.setDict('edict'); this.setOptions(opts); getState((state) => this.setEnabled(state === 'enabled')); }); } onKeyDown(e) { - if (this.enabled && this.lastMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) { - this.searchAtPoint(this.lastMousePos); + if (this.enabled && this.popupMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) { + this.searchAtPoint(this.popupMousePos); } } 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)) { - this.searchAtPoint(this.lastMousePos); + this.searchAtPoint(this.popupMousePos); } } 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)) { - this.searchAtPoint(this.lastMousePos); + this.searchAtPoint(this.popupMousePos); } else { this.hidePopup(); } @@ -82,12 +81,9 @@ class Client { } onFrameMessage(e) { - const {action, data} = e.data; - switch (action) { - case 'selectDict': - this.setDict(data); - break; - } + // const {action, data} = e.data; + // switch (action) { + // } } searchAtPoint(point) { @@ -167,11 +163,6 @@ class Client { setOptions(opts) { this.options = opts; } - - setDict(dict) { - this.dict = dict; - alert(dict); - } } window.yomiClient = new Client(); diff --git a/util/tmpl/header.html b/util/tmpl/header.html index 03504d79..cb9ec67c 100644 --- a/util/tmpl/header.html +++ b/util/tmpl/header.html @@ -6,6 +6,3 @@ -
- -