summaryrefslogtreecommitdiff
path: root/ext/fg/js/float.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-01-04 11:54:54 -0800
committerAlex Yatskov <alex@foosoft.net>2020-01-04 11:54:54 -0800
commit2a12036ca305044291f1f4105d6a8d249848b210 (patch)
tree5cfd4a3d837bf99730233a805d72395c8c61fc07 /ext/fg/js/float.js
parent9105cb5618cfdd14c2bc37cd22db2b360fe8cd52 (diff)
parent174b92366577b0a638003b15e2d73fdc91cd62c3 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r--ext/fg/js/float.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index ae54be00..513d246b 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2020 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -13,7 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
@@ -27,17 +27,24 @@ class DisplayFloat extends Display {
url: window.location.href
};
+ this._orphaned = false;
+
+ yomichan.on('orphaned', () => this.onOrphaned());
window.addEventListener('message', (e) => this.onMessage(e), false);
}
onError(error) {
- if (window.yomichan_orphaned) {
+ if (this._orphaned) {
this.setContentOrphaned();
} else {
logError(error, true);
}
}
+ onOrphaned() {
+ this._orphaned = true;
+ }
+
onSearchClear() {
window.parent.postMessage('popupClose', '*');
}
@@ -48,24 +55,22 @@ class DisplayFloat extends Display {
onMessage(e) {
const {action, params} = e.data;
- const handlers = DisplayFloat.messageHandlers;
- if (hasOwn(handlers, action)) {
- const handler = handlers[action];
- handler(this, params);
- }
+ const handler = DisplayFloat._messageHandlers.get(action);
+ if (typeof handler !== 'function') { return; }
+
+ handler(this, params);
}
onKeyDown(e) {
const key = Display.getKeyFromEvent(e);
- const handlers = DisplayFloat.onKeyDownHandlers;
- if (hasOwn(handlers, key)) {
- const handler = handlers[key];
+ const handler = DisplayFloat._onKeyDownHandlers.get(key);
+ if (typeof handler === 'function') {
if (handler(this, e)) {
e.preventDefault();
- return;
+ return true;
}
}
- super.onKeyDown(e);
+ return super.onKeyDown(e);
}
getOptionsContext() {
@@ -97,21 +102,21 @@ class DisplayFloat extends Display {
}
}
-DisplayFloat.onKeyDownHandlers = {
- 'C': (self, e) => {
+DisplayFloat._onKeyDownHandlers = new Map([
+ ['C', (self, e) => {
if (e.ctrlKey && !window.getSelection().toString()) {
self.onSelectionCopy();
return true;
}
return false;
- }
-};
+ }]
+]);
-DisplayFloat.messageHandlers = {
- setContent: (self, {type, details}) => self.setContent(type, details),
- clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
- setCustomCss: (self, {css}) => self.setCustomCss(css),
- initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)
-};
+DisplayFloat._messageHandlers = new Map([
+ ['setContent', (self, {type, details}) => self.setContent(type, details)],
+ ['clearAutoPlayTimer', (self) => self.clearAutoPlayTimer()],
+ ['setCustomCss', (self, {css}) => self.setCustomCss(css)],
+ ['initialize', (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)]
+]);
-window.yomichan_display = new DisplayFloat();
+DisplayFloat.instance = new DisplayFloat();