summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-05-05 20:23:06 -0700
committerAlex Yatskov <alex@foosoft.net>2016-05-05 20:23:06 -0700
commit22cbafb7b731be5cc70dbd0b0ad3372e8efdc1f0 (patch)
treeb9d8759e518159840be39eacefea2248363a9a65
parent9cb099e5f6aad33c70d986bd6a48668e54ee211c (diff)
Cleanup
-rw-r--r--ext/fg/js/client.js7
-rw-r--r--ext/fg/js/frame.js25
2 files changed, 18 insertions, 14 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index aea2d607..11190869 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -112,7 +112,9 @@ class Client {
(content) => {
this.definitions = definitions;
this.showPopup(range, content);
- canAddNotes(definitions, (states) => this.popup.sendMessage('setActionStates', states));
+ canAddNotes(definitions, (states) => {
+ states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state}));
+ });
}
);
}
@@ -120,7 +122,10 @@ class Client {
}
actionAddNote(mode, index, callback) {
+ const state = {};
+ state[mode] = false;
+ this.popup.sendMessage('setActionState', {index: index, state: state});
}
actionDisplayKanji(kanji) {
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js
index 5a910dfc..38848bfc 100644
--- a/ext/fg/js/frame.js
+++ b/ext/fg/js/frame.js
@@ -43,19 +43,18 @@ function onDomContentLoaded() {
function onMessage(e) {
const {action, params} = e.data, handlers = {
- setActionStates: (states) => {
- for (let i = 0, count = states.length; i < count; ++i) {
- const state = states[i];
- for (const mode in state) {
- const matches = document.querySelectorAll(`.action-link[data-index="${i}"][data-mode="${mode}"]`);
- if (matches.length > 0) {
- const classes = matches[0].classList;
- if (state[mode]) {
- classes.remove('disabled');
- } else {
- classes.add('disabled');
- }
- }
+ setActionState: ({index, state}) => {
+ for (const mode in state) {
+ const matches = document.querySelectorAll(`.action-link[data-index="${index}"][data-mode="${mode}"]`);
+ if (matches.length === 0) {
+ return;
+ }
+
+ const classes = matches[0].classList;
+ if (state[mode]) {
+ classes.remove('disabled');
+ } else {
+ classes.add('disabled');
}
}
}