From 25a4dafd73890a8181bd072d0b514ec9668ecfea Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 29 Sep 2019 13:00:32 -0400 Subject: Fix tab focus being changed due to settings changes --- ext/fg/js/popup.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 08965084..64da9aef 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -105,7 +105,7 @@ class Popup { container.style.height = `${height}px`; container.style.visibility = 'visible'; - this.hideChildren(); + this.hideChildren(true); } static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) { @@ -206,16 +206,21 @@ class Popup { this.invokeApi('orphaned'); } - hide() { - this.hideChildren(); + hide(changeFocus) { + if (this.isContainerHidden()) { + changeFocus = false; + } + this.hideChildren(changeFocus); this.hideContainer(); - this.focusParent(); + if (changeFocus) { + this.focusParent(); + } } - hideChildren() { - // recursively hides all children - if (this.child && !this.child.isContainerHidden()) { - this.child.hide(); + hideChildren(changeFocus) { + // Recursively hides all children. + if (this.child !== null && !this.child.isContainerHidden()) { + this.child.hide(changeFocus); } } -- cgit v1.2.3 From fa7ee468c0b8b877bb6d94a031464525b1a87c6b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 2 Oct 2019 21:11:06 -0400 Subject: Simplify float initialization --- ext/fg/js/float.js | 45 +++++++++++++++++---------------------------- ext/fg/js/popup.js | 20 +++++++++++--------- 2 files changed, 28 insertions(+), 37 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8f561fec..88842eef 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -96,6 +96,18 @@ class DisplayFloat extends Display { } } + initialize(options, popupInfo, url) { + const css = options.general.customPopupCss; + if (css) { + this.setStyle(css); + } + + const {id, depth, parentFrameId} = popupInfo; + this.optionsContext.depth = depth; + this.optionsContext.url = url; + popupNestedInitialize(id, depth, parentFrameId, url); + } + setStyle(css) { const parent = document.head; @@ -122,34 +134,11 @@ 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); - } + 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(), + initialize: (self, {options, popupInfo, url}) => self.initialize(options, popupInfo, url) }; window.yomichan_display = new DisplayFloat(); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 64da9aef..9dff6f28 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -56,17 +56,19 @@ class Popup { return new Promise((resolve) => { const parentFrameId = (typeof this.frameId === 'number' ? this.frameId : null); this.container.addEventListener('load', () => { - this.invokeApi('popupNestedInitialize', { - id: this.id, - depth: this.depth, - parentFrameId, + this.invokeApi('initialize', { + options: { + general: { + customPopupCss: options.general.customPopupCss + } + }, + popupInfo: { + id: this.id, + depth: this.depth, + parentFrameId + }, url: this.url }); - this.invokeApi('setOptions', { - general: { - customPopupCss: options.general.customPopupCss - } - }); resolve(); }); this.observeFullscreen(); -- cgit v1.2.3