summaryrefslogtreecommitdiff
path: root/ext/fg/js/frame.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-09-15 21:03:58 -0700
committerAlex Yatskov <alex@foosoft.net>2016-09-15 21:03:58 -0700
commitb969e8952c551fdc7c150dcc111eccdc90ac7408 (patch)
tree2fa21a903155412870c1807f5cc2ee8cab07f47f /ext/fg/js/frame.js
parentb87611cfddf5ca0e1529b88ed1610ebe0d4657e6 (diff)
Cleanup
Diffstat (limited to 'ext/fg/js/frame.js')
-rw-r--r--ext/fg/js/frame.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js
index 590646d5..8a99a405 100644
--- a/ext/fg/js/frame.js
+++ b/ext/fg/js/frame.js
@@ -17,11 +17,15 @@
*/
+function invokeApi(action, params, target) {
+ target.postMessage({action, params}, '*');
+}
+
function registerKanjiLinks() {
for (const link of Array.from(document.getElementsByClassName('kanji-link'))) {
link.addEventListener('click', e => {
e.preventDefault();
- window.parent.postMessage({action: 'displayKanji', params: e.target.innerHTML}, '*');
+ invokeApi('displayKanji', e.target.innerHTML, window.parent);
});
}
}
@@ -31,7 +35,7 @@ function registerAddNoteLinks() {
link.addEventListener('click', e => {
e.preventDefault();
const ds = e.currentTarget.dataset;
- window.parent.postMessage({action: 'addNote', params: {index: ds.index, mode: ds.mode}}, '*');
+ invokeApi('addNote', {index: ds.index, mode: ds.mode}, window.parent);
});
}
}
@@ -41,7 +45,7 @@ function registerAudioLinks() {
link.addEventListener('click', e => {
e.preventDefault();
const ds = e.currentTarget.dataset;
- window.parent.postMessage({action: 'playAudio', params: ds.index}, '*');
+ invokeApi('playAudio', ds.index, window.parent);
});
}
}