This commit is contained in:
Alex Yatskov 2016-05-05 20:23:06 -07:00
parent 9cb099e5f6
commit 22cbafb7b7
2 changed files with 18 additions and 14 deletions

View File

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

View File

@ -43,12 +43,13 @@ 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];
setActionState: ({index, state}) => {
for (const mode in state) {
const matches = document.querySelectorAll(`.action-link[data-index="${i}"][data-mode="${mode}"]`);
if (matches.length > 0) {
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');
@ -57,8 +58,6 @@ function onMessage(e) {
}
}
}
}
}
};
if (handlers.hasOwnProperty(action)) {