Skip to content

Golf a bit internal/ui/static/js/modal_handler.js #3060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
sudo npm install -g [email protected] [email protected]
- name: Run jshint
run: jshint internal/ui/static/js/*.js
run: jshint --config .jshintrc internal/ui/static/js/*.js
- name: Run ESLint
run: eslint internal/ui/static/js/*.js

Expand Down
6 changes: 6 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"esversion": 11,
"nonew": true,
"nocomma": true,
"browser": true
}
20 changes: 5 additions & 15 deletions internal/ui/static/js/modal_handler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
class ModalHandler {
static exists() {
return document.getElementById("modal-container") !== null;
}

static getModalContainer() {
return document.getElementById("modal-container");
}

static getFocusableElements() {
const container = this.getModalContainer();

const container = document.getElementById("modal-container");
if (container === null) {
return null;
}
Expand All @@ -19,15 +10,14 @@ class ModalHandler {

static setupFocusTrap() {
const focusableElements = this.getFocusableElements();

if (focusableElements === null) {
return;
}

const firstFocusableElement = focusableElements[0];
const lastFocusableElement = focusableElements[focusableElements.length - 1];
const lastFocusableElement = focusableElements.at(-1);

this.getModalContainer().onkeydown = (e) => {
document.getElementById("modal-container").onkeydown = (e) => {
if (e.key !== 'Tab') {
return;
}
Expand All @@ -51,7 +41,7 @@ class ModalHandler {
}

static open(fragment, initialFocusElementId) {
if (ModalHandler.exists()) {
if (document.getElementById("modal-container") !== null) {
return;
}

Expand Down Expand Up @@ -89,7 +79,7 @@ class ModalHandler {
}

static close() {
const container = this.getModalContainer();
const container = document.getElementById("modal-container");
if (container !== null) {
container.parentNode.removeChild(container);
}
Expand Down
Loading