diff options
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/display-frame.js | 12 | ||||
| -rw-r--r-- | ext/fg/js/driver.js | 31 | 
2 files changed, 32 insertions, 11 deletions
| diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 8f15b1bc..41c2fb53 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(); @@ -54,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 fbe89ab8..036dc2d8 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));      } @@ -45,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();          }      } @@ -101,14 +102,30 @@ window.driver = new class {          }      } +    onFrameMessage(e) { +        const handlers = { +            popupClose: () => { +                this.searchClear(); +            } +        }; + +        const handler = handlers[e.data]; +        if (handler) { +            handler(); +        } +    } +      onBgMessage({action, params}, sender, callback) {          const handlers = new class { -            api_optionsSet(options) { +            optionsSet(options) {                  this.options = options; +                if (!this.options.enable) { +                    this.searchClear(); +                }              }          }; -        const method = handlers[`api_${action}`]; +        const method = handlers[action];          if (typeof(method) === 'function') {              method.call(this, params);          } @@ -122,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;          } @@ -200,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();          } |