-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e4b1bb
commit d8c5e56
Showing
3 changed files
with
36 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
let currentContext: HTMLElement | null = null; | ||
window.addEventListener("click", closeContext); | ||
|
||
/** | ||
* Handles clicking around the page. | ||
* | ||
* @param e The event. | ||
*/ | ||
export function closeContext(e: MouseEvent): void { | ||
// Check if the click was within the confines of the context menu. | ||
if (currentContext && !currentContext.contains(e.target as Node)) { | ||
currentContext.style.display = "none"; | ||
currentContext = null; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the current context menu. | ||
* | ||
* @param element The context menu to set. | ||
*/ | ||
export function openContext(element: HTMLElement): void { | ||
// Close any open context menus. | ||
if (currentContext) { | ||
currentContext.style.display = "none"; | ||
} | ||
|
||
// Set the current context menu. | ||
currentContext = element; | ||
} |