From bf382652a7be949d0bbfe176bb2876af2d0f7fa2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 2 Oct 2019 20:46:35 -0400 Subject: Use static object for float message handlers --- ext/fg/js/float.js | 69 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'ext') 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(); -- cgit v1.2.3