summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-02 20:46:35 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-02 20:46:35 -0400
commitbf382652a7be949d0bbfe176bb2876af2d0f7fa2 (patch)
tree376f8ec113532978db8cbf63001ccd70ece73a8e /ext/fg/js
parent7d15213916355a806ba687803ca94209e29f142c (diff)
Use static object for float message handlers
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/float.js69
1 files changed, 35 insertions, 34 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 8a05aa70..8f561fec 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -63,41 +63,11 @@ class DisplayFloat extends Display {
}
onMessage(e) {
- const handlers = {
- termsShow: ({definitions, options, context}) => {
- this.termsShow(definitions, options, context);
- },
-
- kanjiShow: ({definitions, options, context}) => {
- this.kanjiShow(definitions, options, context);
- },
-
- clearAutoPlayTimer: () => {
- this.clearAutoPlayTimer();
- },
-
- orphaned: () => {
- this.onOrphaned();
- },
-
- setOptions: (options) => {
- const css = options.general.customPopupCss;
- if (css) {
- this.setStyle(css);
- }
- },
-
- popupNestedInitialize: ({id, depth, parentFrameId, url}) => {
- this.optionsContext.depth = depth;
- this.optionsContext.url = url;
- popupNestedInitialize(id, depth, parentFrameId, url);
- }
- };
-
const {action, params} = e.data;
- const handler = handlers[action];
- if (handler) {
- handler(params);
+ const handlers = DisplayFloat.messageHandlers;
+ if (handlers.hasOwnProperty(action)) {
+ const handler = handlers[action];
+ handler(this, params);
}
}
@@ -151,4 +121,35 @@ DisplayFloat.onKeyDownHandlers = {
}
};
+DisplayFloat.messageHandlers = {
+ termsShow: (self, {definitions, options, context}) => {
+ self.termsShow(definitions, options, context);
+ },
+
+ kanjiShow: (self, {definitions, options, context}) => {
+ self.kanjiShow(definitions, options, context);
+ },
+
+ clearAutoPlayTimer: (self) => {
+ self.clearAutoPlayTimer();
+ },
+
+ orphaned: (self) => {
+ self.onOrphaned();
+ },
+
+ setOptions: (self, options) => {
+ const css = options.general.customPopupCss;
+ if (css) {
+ self.setStyle(css);
+ }
+ },
+
+ popupNestedInitialize: (self, {id, depth, parentFrameId, url}) => {
+ self.optionsContext.depth = depth;
+ self.optionsContext.url = url;
+ popupNestedInitialize(id, depth, parentFrameId, url);
+ }
+};
+
window.yomichan_display = new DisplayFloat();