Skip to content

Commit

Permalink
Tab key to switch between users & escape key to exit shutdown options…
Browse files Browse the repository at this point in the history
… overlay. Issue #6
  • Loading branch information
mshernandez5 committed Aug 25, 2021
1 parent 31be38e commit faf5e09
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,15 @@ function autologin_timer_expired()
*/

// Called When A User Listing In The Menu Is Selected
function setActiveUser(event)
function onUserClick(event)
{
setActiveUser(event.currentTarget);
}

// Sets A User Listing Element As The Active One
function setActiveUser(userListing)
{
// Get Information For The Selected User Listing
let userListing = event.currentTarget;
let userName = lightdm.users[userListing.getAttribute("data-user-index")].name;
// If Selected User Already Active, Do Nothing
if (userName === activeUserName)
Expand Down Expand Up @@ -213,6 +218,43 @@ function cancelShutdownPrompt()
overlay.classList.remove("active");
}

// Listen For Keys
const KEY_ESCAPE = 27;
const KEY_TAB = 9;
document.addEventListener("keydown", onKeyEvent);
function onKeyEvent(event)
{
// Remove Any Password Error Popup On Key Press
removePopup();
// Check If Shutdown Prompt Open
let shutdownPromptOpen = document.querySelector("#shutdown-prompt-overlay").classList.contains("active");
// Key Events For Shutdown Prompt
if (shutdownPromptOpen)
{
// Close Shutdown Prompt
if (event.keyCode === KEY_ESCAPE)
{
cancelShutdownPrompt();
}
}
// Key Events For General Login Screen
else
{
// Tab Between Users
if (event.keyCode === KEY_TAB)
{
event.preventDefault();
let next;
if (!activeUserListing || !(next = activeUserListing.parentElement.nextElementSibling))
{
next = document.querySelector("#userListings div:first-of-type");
console.log(next);
}
setActiveUser(next.firstElementChild);
}
}
}

/*
* These are the initialization procedures when
* the script execution begins.
Expand Down Expand Up @@ -262,7 +304,7 @@ function init()
// Associate Listing With Associated User Index
userClickBox.setAttribute("data-user-index", i);
// Add User Selection Listener
userClickBox.addEventListener("click", setActiveUser);
userClickBox.addEventListener("click", onUserClick);
// Add Login Form Listener
loginForm.addEventListener("submit", attemptLogin);
}
Expand Down

0 comments on commit faf5e09

Please sign in to comment.