aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-12-28 17:41:59 -0500
committerGitHub <noreply@github.com>2020-12-28 17:41:59 -0500
commitb6038c87b66630b341e431a4722856c9a3a282ed (patch)
tree721c26ef99b1e953904c10060c2a1bace281335e /ext/mixed/js/display.js
parentc03340c4aa77c0a84b28bf18407aa79972697213 (diff)
Improve document focus control (#1167)
* Improve styles for #content-scroll-focus * Create new class to manage and control document focus * Use new focus class * Add a check to prevent redundant .blur calls
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js28
1 files changed, 3 insertions, 25 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 7491cd60..b9ea3802 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -35,10 +35,11 @@
*/
class Display extends EventDispatcher {
- constructor(pageType, japaneseUtil) {
+ constructor(pageType, japaneseUtil, documentFocusController) {
super();
this._pageType = pageType;
this._japaneseUtil = japaneseUtil;
+ this._documentFocusController = documentFocusController;
this._container = document.querySelector('#definitions');
this._definitions = [];
this._optionsContext = {depth: 0, url: window.location.href};
@@ -95,7 +96,6 @@ class Display extends EventDispatcher {
this._updateAdderButtonsPromise = Promise.resolve();
this._contentScrollElement = document.querySelector('#content-scroll');
this._contentScrollBodyElement = document.querySelector('#content-body');
- this._contentScrollFocusElement = document.querySelector('#content-scroll-focus');
this._windowScroll = new WindowScroll(this._contentScrollElement);
this._contentSidebar = document.querySelector('#content-sidebar');
this._closeButton = document.querySelector('#close-button');
@@ -218,7 +218,6 @@ class Display extends EventDispatcher {
['popupMessage', {async: 'dynamic', handler: this._onDirectMessage.bind(this)}]
]);
window.addEventListener('message', this._onWindowMessage.bind(this), false);
- window.addEventListener('focus', this._onWindowFocus.bind(this), false);
if (this._pageType === 'popup' && documentElement !== null) {
documentElement.addEventListener('mouseup', this._onDocumentElementMouseUp.bind(this), false);
@@ -241,9 +240,6 @@ class Display extends EventDispatcher {
if (this._frameResizeHandle !== null) {
this._frameResizeHandle.addEventListener('mousedown', this._onFrameResizerMouseDown.bind(this), false);
}
-
- // Final preparation
- this._updateFocusedElement();
}
initializeState() {
@@ -457,8 +453,7 @@ class Display extends EventDispatcher {
}
blurElement(element) {
- element.blur();
- this._updateFocusedElement();
+ this._documentFocusController.blurElement(element);
}
searchLast() {
@@ -711,10 +706,6 @@ class Display extends EventDispatcher {
}
}
- _onWindowFocus() {
- this._updateFocusedElement();
- }
-
async _onKanjiLookup(e) {
try {
e.preventDefault();
@@ -1633,19 +1624,6 @@ class Display extends EventDispatcher {
await this.setOptionsContext(optionsContext);
}
- _updateFocusedElement() {
- const target = this._contentScrollFocusElement;
- if (target === null) { return; }
- const {activeElement} = document;
- if (
- activeElement === null ||
- activeElement === document.documentElement ||
- activeElement === document.body
- ) {
- target.focus({preventScroll: true});
- }
- }
-
_setContentScale(scale) {
const body = document.body;
if (body === null) { return; }