-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from innogames/servershell_dismiss_by_esc
Dismiss alerts by <ESC> keyboard shortcut
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Dismiss by ESC keyboard shortcut, Copyright (c) 2021 InnoGames GmbH | ||
* | ||
* Allows to dismiss (delete) HTML elements that have the class dismissible | ||
* by pressing escape. | ||
*/ | ||
$(document).ready(function() { | ||
$(document).keydown(function (event) { | ||
// ESC | ||
if (event.key === "Escape") { | ||
let dismissible = $('.dismissible'); | ||
|
||
if (dismissible.length < 1) { | ||
return; | ||
} | ||
|
||
// Pressing ESC on elements such as inputs makes them loose focus. | ||
// To avoid this we remember the focused element to restore it. | ||
let input = document.activeElement; | ||
|
||
dismissible.remove(); | ||
|
||
if (input) { | ||
input.focus(); | ||
} | ||
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters