diff options
| author | Alex Yatskov <alex@foosoft.net> | 2016-04-24 18:34:31 -0700 | 
|---|---|---|
| committer | Alex Yatskov <alex@foosoft.net> | 2016-04-24 18:34:31 -0700 | 
| commit | a192a8d8b549d5979a427d86c51f94bb5f4be907 (patch) | |
| tree | 9581777a8b5fb6832e18d5bcd9f3ea8a9a6bbdff | |
| parent | 8143e372cdb61012ec8683feb01688adfa39dde1 (diff) | |
Plumbing
| -rw-r--r-- | ext/bg/js/yomichan.js | 3 | ||||
| -rw-r--r-- | ext/fg/js/client.js | 12 | ||||
| -rw-r--r-- | ext/fg/js/frame.js | 6 | 
3 files changed, 11 insertions, 10 deletions
| diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 110fb403..7c802675 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -49,8 +49,7 @@ class Yomichan {      }      onMessage(request, sender, callback) { -        const {action, data} = request; -        const handlers = { +        const {action, data} = request, handlers = {              findKanji:  ({text}) => this.translator.onFindKanji(text),              findTerm:   ({text}) => this.translator.findTerm(text),              getState:   () => this.state, diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 44a3b84c..7f07d918 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -77,9 +77,11 @@ class Client {      }      onFrameMessage(e) { -        // const {action, data} = e.data; -        // switch (action) { -        // } +        const {action, data} = e.data, handlers = { +            displayKanji: this.displayKanji +        }; + +        handlers[action].call(this, data);      }      searchAt(point) { @@ -134,6 +136,10 @@ class Client {          this.lastRange = null;      } +    displayKanji(kanji) { +        this.popup.setContent(kanji); +    } +      setEnabled(enabled) {          if (!(this.enabled = enabled)) {              this.hidePopup(); diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index c8f8211e..66932c2c 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -17,15 +17,11 @@   */ -function onKanjiQuery(kanji) { -    alert(kanji); -} -  function registerKanjiLinks() {      for (const link of [].slice.call(document.getElementsByClassName('kanji-link'))) {          link.addEventListener('click', (e) => {              e.preventDefault(); -            onKanjiQuery(e.target.innerHTML); +            window.parent.postMessage({action: 'displayKanji', data: e.target.innerHTML}, '*');          });      }  } |