Add note links

This commit is contained in:
Alex Yatskov 2016-05-04 20:08:22 -07:00
parent 320d9bca0e
commit bc11e7cbe3
2 changed files with 21 additions and 1 deletions

View File

@ -80,6 +80,7 @@ class Client {
onFrameMessage(e) { onFrameMessage(e) {
const {action, data} = e.data, handlers = { const {action, data} = e.data, handlers = {
addNote: this.addNote,
displayKanji: this.displayKanji displayKanji: this.displayKanji
}; };
@ -117,6 +118,10 @@ class Client {
}); });
} }
addNote({mode, index}) {
console.log(mode, index);
}
displayKanji(kanji) { displayKanji(kanji) {
findKanji(kanji, (results) => { findKanji(kanji, (results) => {
renderText( renderText(

View File

@ -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);