Skip to content

Commit

Permalink
Minor renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfbyteHeroes committed Sep 5, 2024
1 parent ea0495a commit a975e14
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/ts/components/selectbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UIContainer } from './uicontainer';
import { PlayerUtils } from '../playerutils';
import { ViewMode } from './component';

const DocumentCancellingEvents = [
const DocumentDropdownClosedEvents = [
'mousemove',
'mouseenter',
'mouseleave',
Expand All @@ -22,13 +22,13 @@ const DocumentCancellingEvents = [
'blur',
];

const SelectCancellingEvents = [
const SelectDropdownClosedEvents = [
'change',
'keyup',
'mouseup',
];

const EnteringEvents: [string, (event: Event) => boolean][] = [
const DropdownOpenedEvents: [string, (event: Event) => boolean][] = [
['click', () => true],
['keydown', (event: KeyboardEvent) => [' ', 'ArrowUp', 'ArrowDown'].includes(event.key)],
['mousedown', () => true],
Expand Down Expand Up @@ -171,19 +171,21 @@ export class SelectBox extends ListSelector<ListSelectorConfig> {

clearTimeout(this.dropdownCloseListenerTimeoutId);

DocumentCancellingEvents.forEach(event => document.addEventListener(event, this.onDropdownClosed, true));
SelectCancellingEvents.forEach(event => this.selectElement.on(event, this.onDropdownClosed, true));
DocumentDropdownClosedEvents.forEach(event => document.addEventListener(event, this.onDropdownClosed, true));
SelectDropdownClosedEvents.forEach(event => this.selectElement.on(event, this.onDropdownClosed, true));

this.removeDropdownCloseListeners = () => {
DocumentCancellingEvents.forEach(event => document.removeEventListener(event, this.onDropdownClosed, true));
SelectCancellingEvents.forEach(event => this.selectElement.off(event, this.onDropdownClosed, true));
DocumentDropdownClosedEvents.forEach(event => document.removeEventListener(event, this.onDropdownClosed, true));
SelectDropdownClosedEvents.forEach(event => this.selectElement.off(event, this.onDropdownClosed, true));
};
}

private addDropdownOpenedListeners() {
const removeListenerFunctions: (() => void)[] = [];

for (const [event, filter] of EnteringEvents) {
this.removeDropdownOpenedListeners();

for (const [event, filter] of DropdownOpenedEvents) {
const listener = (event: Event) => {
if (filter(event)) {
this.onDropdownOpened();
Expand All @@ -194,7 +196,6 @@ export class SelectBox extends ListSelector<ListSelectorConfig> {
this.selectElement.on(event, listener, true);
}

this.removeDropdownOpenedListeners();
this.removeDropdownOpenedListeners = () => {
for (const remove of removeListenerFunctions) {
remove();
Expand Down

0 comments on commit a975e14

Please sign in to comment.