aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom/document-focus-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-09-26 19:37:14 -0400
committerGitHub <noreply@github.com>2022-09-26 19:37:14 -0400
commitbe7855bad2e3b452ca0700246a376f107a75e79e (patch)
treedf73805af15c5bd98a370ccbded679125d98e46d /ext/js/dom/document-focus-controller.js
parent38c3d1b98c269739b7be3b3c8b33a58a65af5e52 (diff)
More API documentation (#2238)
* Document TextSourceRange * Document TextSourceElement * Document DocumentUtil * Document DocumentFocusController
Diffstat (limited to 'ext/js/dom/document-focus-controller.js')
-rw-r--r--ext/js/dom/document-focus-controller.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/js/dom/document-focus-controller.js b/ext/js/dom/document-focus-controller.js
index bc6c61b9..d6c24646 100644
--- a/ext/js/dom/document-focus-controller.js
+++ b/ext/js/dom/document-focus-controller.js
@@ -22,11 +22,19 @@
* focus a dummy element inside the main content, which gives keyboard scroll focus to that element.
*/
class DocumentFocusController {
+ /**
+ * Creates a new instance of the class.
+ * @param {?string} autofocusElementSelector A selector string which can be used to specify an element which
+ * should be automatically focused on prepare.
+ */
constructor(autofocusElementSelector=null) {
this._autofocusElement = (autofocusElementSelector !== null ? document.querySelector(autofocusElementSelector) : null);
this._contentScrollFocusElement = document.querySelector('#content-scroll-focus');
}
+ /**
+ * Initializes the instance.
+ */
prepare() {
window.addEventListener('focus', this._onWindowFocus.bind(this), false);
this._updateFocusedElement(false);
@@ -35,6 +43,10 @@ class DocumentFocusController {
}
}
+ /**
+ * Removes focus from a given element.
+ * @param {Element} element The element to remove focus from.
+ */
blurElement(element) {
if (document.activeElement !== element) { return; }
element.blur();