Plumbing
This commit is contained in:
parent
8143e372cd
commit
a192a8d8b5
@ -49,8 +49,7 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMessage(request, sender, callback) {
|
onMessage(request, sender, callback) {
|
||||||
const {action, data} = request;
|
const {action, data} = request, handlers = {
|
||||||
const handlers = {
|
|
||||||
findKanji: ({text}) => this.translator.onFindKanji(text),
|
findKanji: ({text}) => this.translator.onFindKanji(text),
|
||||||
findTerm: ({text}) => this.translator.findTerm(text),
|
findTerm: ({text}) => this.translator.findTerm(text),
|
||||||
getState: () => this.state,
|
getState: () => this.state,
|
||||||
|
@ -77,9 +77,11 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFrameMessage(e) {
|
onFrameMessage(e) {
|
||||||
// const {action, data} = e.data;
|
const {action, data} = e.data, handlers = {
|
||||||
// switch (action) {
|
displayKanji: this.displayKanji
|
||||||
// }
|
};
|
||||||
|
|
||||||
|
handlers[action].call(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
searchAt(point) {
|
searchAt(point) {
|
||||||
@ -134,6 +136,10 @@ class Client {
|
|||||||
this.lastRange = null;
|
this.lastRange = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayKanji(kanji) {
|
||||||
|
this.popup.setContent(kanji);
|
||||||
|
}
|
||||||
|
|
||||||
setEnabled(enabled) {
|
setEnabled(enabled) {
|
||||||
if (!(this.enabled = enabled)) {
|
if (!(this.enabled = enabled)) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
|
@ -17,15 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function onKanjiQuery(kanji) {
|
|
||||||
alert(kanji);
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerKanjiLinks() {
|
function registerKanjiLinks() {
|
||||||
for (const link of [].slice.call(document.getElementsByClassName('kanji-link'))) {
|
for (const link of [].slice.call(document.getElementsByClassName('kanji-link'))) {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onKanjiQuery(e.target.innerHTML);
|
window.parent.postMessage({action: 'displayKanji', data: e.target.innerHTML}, '*');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user