diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-07-23 15:14:13 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-07-23 15:14:13 -0700 |
commit | 22d73228ca2899047bcf39a6a2e7146d68c69e0a (patch) | |
tree | 51a95db8157688e16d6f877b9417a33ac68386b2 /ext/fg | |
parent | 6d9b4392e2cd78b5e76e3b47cc3b8ca76d37129b (diff) |
Cleanup
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/api.js | 8 | ||||
-rw-r--r-- | ext/fg/js/client.js | 27 |
2 files changed, 9 insertions, 26 deletions
diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index 5d060311..7316c604 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -33,14 +33,6 @@ function bgRenderText(data, template, callback) { bgSendMessage('renderText', {data, template}, callback); } -function bgGetOptions(callback) { - bgSendMessage('getOptions', {}, callback); -} - -function bgGetState(callback) { - bgSendMessage('getState', {}, callback); -} - function bgCanAddDefinitions(definitions, modes, callback) { bgSendMessage('canAddDefinitions', {definitions, modes}, callback); } diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 60aa6883..37377984 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -38,11 +38,6 @@ class Client { window.addEventListener('keydown', this.onKeyDown.bind(this)); window.addEventListener('scroll', (e) => this.hidePopup()); window.addEventListener('resize', (e) => this.hidePopup()); - - bgGetOptions((opts) => { - this.setOptions(opts); - bgGetState((state) => this.setEnabled(state === 'enabled')); - }); } onKeyDown(e) { @@ -67,14 +62,10 @@ class Client { } } - onBgMessage({name, value}, sender, callback) { - switch (name) { - case 'state': - this.setEnabled(value === 'enabled'); - break; - case 'options': - this.setOptions(value); - break; + onBgMessage({action, params}, sender, callback) { + const method = this['api_' + action]; + if (typeof(method) === 'function') { + method.call(this, params); } callback(); @@ -159,16 +150,16 @@ class Client { this.definitions = null; } - setEnabled(enabled) { + api_setOptions(opts) { + this.options = opts; + } + + api_setEnabled(enabled) { if (!(this.enabled = enabled)) { this.hidePopup(); } } - setOptions(opts) { - this.options = opts; - } - api_addNote({index, mode}) { const state = {}; state[mode] = false; |