mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Lexical: Added color picker controls
This commit is contained in:
34
resources/js/wysiwyg/ui/framework/helpers/dropdowns.ts
Normal file
34
resources/js/wysiwyg/ui/framework/helpers/dropdowns.ts
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
|
||||
export function handleDropdown(toggle: HTMLElement, menu: HTMLElement, onOpen: Function|undefined = undefined, onClose: Function|undefined = undefined) {
|
||||
let clickListener: Function|null = null;
|
||||
|
||||
const hide = () => {
|
||||
menu.hidden = true;
|
||||
if (clickListener) {
|
||||
window.removeEventListener('click', clickListener as EventListener);
|
||||
}
|
||||
if (onClose) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
const show = () => {
|
||||
menu.hidden = false
|
||||
clickListener = (event: MouseEvent) => {
|
||||
if (!toggle.contains(event.target as HTMLElement) && !menu.contains(event.target as HTMLElement)) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
window.addEventListener('click', clickListener as EventListener);
|
||||
if (onOpen) {
|
||||
onOpen();
|
||||
}
|
||||
};
|
||||
|
||||
toggle.addEventListener('click', event => {
|
||||
menu.hasAttribute('hidden') ? show() : hide();
|
||||
});
|
||||
menu.addEventListener('mouseleave', hide);
|
||||
}
|
Reference in New Issue
Block a user