diff options
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r-- | ext/fg/js/float.js | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8f21a9c5..bc459d23 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -33,8 +33,27 @@ class DisplayFloat extends Display { this._messageToken = null; this._messageTokenPromise = null; - yomichan.on('orphaned', () => this.onOrphaned()); - window.addEventListener('message', (e) => this.onMessage(e), false); + this._onKeyDownHandlers = new Map([ + ['C', (e) => { + if (e.ctrlKey && !window.getSelection().toString()) { + this.onSelectionCopy(); + return true; + } + return false; + }], + ...this._onKeyDownHandlers + ]); + + this._windowMessageHandlers = new Map([ + ['setContent', ({type, details}) => this.setContent(type, details)], + ['clearAutoPlayTimer', () => this.clearAutoPlayTimer()], + ['setCustomCss', ({css}) => this.setCustomCss(css)], + ['prepare', ({options, popupInfo, url, childrenSupported, scale, uniqueId}) => this.prepare(options, popupInfo, url, childrenSupported, scale, uniqueId)], + ['setContentScale', ({scale}) => this.setContentScale(scale)] + ]); + + yomichan.on('orphaned', this.onOrphaned.bind(this)); + window.addEventListener('message', this.onMessage.bind(this), false); } async prepare(options, popupInfo, url, childrenSupported, scale, uniqueId) { @@ -96,18 +115,6 @@ class DisplayFloat extends Display { } } - onKeyDown(e) { - const key = Display.getKeyFromEvent(e); - const handler = DisplayFloat._onKeyDownHandlers.get(key); - if (typeof handler === 'function') { - if (handler(this, e)) { - e.preventDefault(); - return true; - } - } - return super.onKeyDown(e); - } - async getMessageToken() { // this._messageTokenPromise is used to ensure that only one call to apiGetMessageToken is made. if (this._messageTokenPromise === null) { @@ -126,10 +133,10 @@ class DisplayFloat extends Display { return; } - const handler = DisplayFloat._messageHandlers.get(action); + const handler = this._windowMessageHandlers.get(action); if (typeof handler !== 'function') { return; } - handler(this, params); + handler(params); } getOptionsContext() { @@ -153,22 +160,4 @@ class DisplayFloat extends Display { } } -DisplayFloat._onKeyDownHandlers = new Map([ - ['C', (self, e) => { - if (e.ctrlKey && !window.getSelection().toString()) { - self.onSelectionCopy(); - return true; - } - return false; - }] -]); - -DisplayFloat._messageHandlers = new Map([ - ['setContent', (self, {type, details}) => self.setContent(type, details)], - ['clearAutoPlayTimer', (self) => self.clearAutoPlayTimer()], - ['setCustomCss', (self, {css}) => self.setCustomCss(css)], - ['prepare', (self, {options, popupInfo, url, childrenSupported, scale, uniqueId}) => self.prepare(options, popupInfo, url, childrenSupported, scale, uniqueId)], - ['setContentScale', (self, {scale}) => self.setContentScale(scale)] -]); - DisplayFloat.instance = new DisplayFloat(); |