From f3f6139c8ebe2ae02291e950f9cc6915ae45b6dc Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 13:46:56 -0700 Subject: update guide --- ext/fg/js/driver.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ext/fg/js') diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index fbe89ab8..16b12d5e 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -105,6 +105,9 @@ window.driver = new class { const handlers = new class { api_optionsSet(options) { this.options = options; + if (!this.options.enable) { + this.searchClear(); + } } }; -- cgit v1.2.3 From 90eaae1725511bbc039f84f684b7b080e0fa2d44 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 15:22:28 -0700 Subject: wip --- ext/fg/js/driver.js | 22 ++++++++++++++++++++++ ext/mixed/js/display.js | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'ext/fg/js') diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 16b12d5e..5e17537e 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -35,6 +35,7 @@ window.driver = new class { window.addEventListener('mouseup', this.onMouseUp.bind(this)); window.addEventListener('mousemove', this.onMouseMove.bind(this)); window.addEventListener('resize', e => this.searchClear()); + window.addEventListener('message', this.onFrameMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this)); }).catch(this.handleError.bind(this)); } @@ -101,6 +102,27 @@ window.driver = new class { } } + onFrameMessage(e) { + const handlers = { + popupClose: () => { + this.searchClear(); + }, + + scanLeft: () => { + + }, + + scanRight: () => { + + } + }; + + const handler = handlers[e.data]; + if (handler) { + handler(); + } + } + onBgMessage({action, params}, sender, callback) { const handlers = new class { api_optionsSet(options) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f3423878..30f703bb 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -207,6 +207,10 @@ class Display { } onKeyDown(e) { + const notifyParent = action => { + window.parent.postMessage(action, '*'); + }; + const handlers = { 36: /* home */ () => { this.entryScroll(0, true); @@ -246,6 +250,18 @@ class Display { 8: /* backspace */ () => { + }, + + 27: /* escape */ () => { + notifyParent('popupClose'); + }, + + 37: /* left */ () => { + notifyParent('scanLeft'); + }, + + 39: /* right */ () => { + notifyParent('scanRight'); } }; -- cgit v1.2.3 From b8d0788144974daab8d55c8de1af7515a291ba4f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 15:59:33 -0700 Subject: wip --- ext/bg/js/display-window.js | 4 ++++ ext/fg/js/display-frame.js | 4 ++++ ext/fg/js/driver.js | 18 +++++------------- ext/mixed/js/display.js | 42 +++++++++++++++++------------------------- 4 files changed, 30 insertions(+), 38 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js index 8c732ddd..ae97cd36 100644 --- a/ext/bg/js/display-window.js +++ b/ext/bg/js/display-window.js @@ -49,6 +49,10 @@ window.displayWindow = new class extends Display { window.alert(`Error: ${error}`); } + clearSearch() { + $('#query').focus().select(); + } + onSearch(e) { e.preventDefault(); $('#intro').slideUp(); diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 8f15b1bc..d930d325 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -47,6 +47,10 @@ window.displayFrame = new class extends Display { } } + clearSearch() { + window.parent.postMessage('popupClose', '*'); + } + showOrphaned() { $('#content').hide(); $('#orphan').show(); diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5e17537e..7a56dd9c 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -46,14 +46,14 @@ window.driver = new class { } popupTimerClear() { - if (this.popupTimer !== null) { + if (this.popupTimer) { window.clearTimeout(this.popupTimer); this.popupTimer = null; } } onMouseOver(e) { - if (e.target === this.popup.container && this.popuptimer !== null) { + if (e.target === this.popup.container && this.popupTimer) { this.popupTimerClear(); } } @@ -106,14 +106,6 @@ window.driver = new class { const handlers = { popupClose: () => { this.searchClear(); - }, - - scanLeft: () => { - - }, - - scanRight: () => { - } }; @@ -147,11 +139,11 @@ window.driver = new class { } const textSource = docRangeFromPoint(point, this.options.scanning.imposter); - if (textSource === null || !textSource.containsPoint(point)) { + if (!textSource || !textSource.containsPoint(point)) { return; } - if (this.lastTextSource !== null && this.lastTextSource.equals(textSource)) { + if (this.lastTextSource && this.lastTextSource.equals(textSource)) { return; } @@ -225,7 +217,7 @@ window.driver = new class { docImposterDestroy(); this.popup.hide(); - if (this.options.scanning.selectText && this.lastTextSource !== null) { + if (this.options.scanning.selectText && this.lastTextSource) { this.lastTextSource.deselect(); } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 30f703bb..140185cc 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -50,6 +50,10 @@ class Display { throw 'override me'; } + clearSearch() { + throw 'override me'; + } + showTermDefs(definitions, options, context) { window.focus(); @@ -207,17 +211,13 @@ class Display { } onKeyDown(e) { - const notifyParent = action => { - window.parent.postMessage(action, '*'); - }; - const handlers = { - 36: /* home */ () => { - this.entryScroll(0, true); + 8: /* backspace */ () => { + }, - 35: /* end */ () => { - this.entryScroll(this.definitions.length - 1, true); + 27: /* escape */ () => { + this.clearSearch(); }, 33: /* page up */ () => { @@ -228,6 +228,14 @@ class Display { this.entryScroll(this.index + 3, true); }, + 35: /* end */ () => { + this.entryScroll(this.definitions.length - 1, true); + }, + + 36: /* home */ () => { + this.entryScroll(0, true); + }, + 38: /* up */ () => { this.entryScroll(this.index - 1, true); }, @@ -240,28 +248,12 @@ class Display { }, - 221: /* ] */ () => { - - }, - 220: /* \ */ () => { this.audioPlay(this.definitions[this.index]); }, - 8: /* backspace */ () => { - - }, - - 27: /* escape */ () => { - notifyParent('popupClose'); - }, - - 37: /* left */ () => { - notifyParent('scanLeft'); - }, + 221: /* ] */ () => { - 39: /* right */ () => { - notifyParent('scanRight'); } }; -- cgit v1.2.3 From 218db0771fae0754a50cadc1891a042112b58699 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 16:45:43 -0700 Subject: cleanup, firefox scrolling --- ext/bg/js/yomichan.js | 14 +++++++------- ext/fg/js/display-frame.js | 8 ++++---- ext/fg/js/driver.js | 4 ++-- ext/mixed/js/display.js | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 1a34aba4..39105c54 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -192,32 +192,32 @@ window.yomichan = new class { onMessage(request, sender, callback) { const handlers = new class { - api_optionsGet({callback}) { + optionsGet({callback}) { promiseCallback(optionsLoad(), callback); } - api_kanjiFind({text, callback}) { + kanjiFind({text, callback}) { promiseCallback(this.kanjiFind(text), callback); } - api_termsFind({text, callback}) { + termsFind({text, callback}) { promiseCallback(this.termsFind(text), callback); } - api_templateRender({template, data, callback}) { + templateRender({template, data, callback}) { promiseCallback(this.templateRender(template, data), callback); } - api_definitionAdd({definition, mode, callback}) { + definitionAdd({definition, mode, callback}) { promiseCallback(this.definitionAdd(definition, mode), callback); } - api_definitionsAddable({definitions, modes, callback}) { + definitionsAddable({definitions, modes, callback}) { promiseCallback(this.definitionsAddable(definitions, modes), callback); } }; - const {action, params} = request, method = handlers[`api_${action}`]; + const {action, params} = request, method = handlers[action]; if (typeof(method) === 'function') { params.callback = callback; method.call(this, params); diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index d930d325..41c2fb53 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -58,20 +58,20 @@ window.displayFrame = new class extends Display { onMessage(e) { const handlers = new class { - api_showTermDefs({definitions, options, context}) { + showTermDefs({definitions, options, context}) { this.showTermDefs(definitions, options, context); } - api_showKanjiDefs({definitions, options, context}) { + showKanjiDefs({definitions, options, context}) { this.showKanjiDefs(definitions, options, context); } - api_showOrphaned() { + showOrphaned() { this.showOrphaned(); } }; - const {action, params} = e.originalEvent.data, method = handlers[`api_${action}`]; + const {action, params} = e.originalEvent.data, method = handlers[action]; if (typeof(method) === 'function') { method.call(this, params); } diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 7a56dd9c..036dc2d8 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -117,7 +117,7 @@ window.driver = new class { onBgMessage({action, params}, sender, callback) { const handlers = new class { - api_optionsSet(options) { + optionsSet(options) { this.options = options; if (!this.options.enable) { this.searchClear(); @@ -125,7 +125,7 @@ window.driver = new class { } }; - const method = handlers[`api_${action}`]; + const method = handlers[action]; if (typeof(method) === 'function') { method.call(this, params); } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 140185cc..50940e58 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -149,14 +149,14 @@ class Display { $('.current').hide().eq(index).show(); - const body = $('body').stop(); + const container = $('html,body').stop(); const entry = $('.entry').eq(index); const target = index === 0 ? 0 : entry.offset().top; if (smooth) { - body.animate({scrollTop: target}, 200); + container.animate({scrollTop: target}, 200); } else { - body.scrollTop(target); + container.scrollTop(target); } this.index = index; -- cgit v1.2.3