From bc11e7cbe3a3a3c57967f78933302f7a06dfde24 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 4 May 2016 20:08:22 -0700 Subject: [PATCH] Add note links --- ext/fg/js/client.js | 5 +++++ ext/fg/js/frame.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 8495a354..2d80b35e 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -80,6 +80,7 @@ class Client { onFrameMessage(e) { const {action, data} = e.data, handlers = { + addNote: this.addNote, displayKanji: this.displayKanji }; @@ -117,6 +118,10 @@ class Client { }); } + addNote({mode, index}) { + console.log(mode, index); + } + displayKanji(kanji) { findKanji(kanji, (results) => { renderText( diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index 66932c2c..c8528fe7 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -26,4 +26,19 @@ function registerKanjiLinks() { } } -document.addEventListener('DOMContentLoaded', registerKanjiLinks, false); +function registerActionLinks() { + for (const link of [].slice.call(document.getElementsByClassName('action-link'))) { + link.addEventListener('click', (e) => { + e.preventDefault(); + const ds = e.currentTarget.dataset; + window.parent.postMessage({action: 'addNote', data: {index: ds.index, mode: ds.mode}}, '*'); + }); + } +} + +function domContentLoaded() { + registerKanjiLinks(); + registerActionLinks(); +} + +document.addEventListener('DOMContentLoaded', domContentLoaded, false);