mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-03 14:32:11 +02:00
Move event keys into constants
This commit is contained in:
parent
ff7cadbd85
commit
865f96d0da
|
@ -5,7 +5,7 @@ import Dropdown from './components/dropdown';
|
||||||
import Container from './components/container';
|
import Container from './components/container';
|
||||||
import Input from './components/input';
|
import Input from './components/input';
|
||||||
import List from './components/list';
|
import List from './components/list';
|
||||||
import { DEFAULT_CONFIG, DEFAULT_CLASSNAMES } from './constants';
|
import { DEFAULT_CONFIG, DEFAULT_CLASSNAMES, EVENTS } from './constants';
|
||||||
import {
|
import {
|
||||||
addItem,
|
addItem,
|
||||||
removeItem,
|
removeItem,
|
||||||
|
@ -120,7 +120,6 @@ class Choices {
|
||||||
|
|
||||||
// Assign preset choices from passed object
|
// Assign preset choices from passed object
|
||||||
this.presetChoices = this.config.choices;
|
this.presetChoices = this.config.choices;
|
||||||
|
|
||||||
// Assign preset items from passed object first
|
// Assign preset items from passed object first
|
||||||
this.presetItems = this.config.items;
|
this.presetItems = this.config.items;
|
||||||
|
|
||||||
|
@ -547,7 +546,7 @@ class Choices {
|
||||||
eventResponse.groupValue = group.value;
|
eventResponse.groupValue = group.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'highlightItem', eventResponse);
|
triggerEvent(this.passedElement, EVENTS.highlightItem, eventResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -581,7 +580,7 @@ class Choices {
|
||||||
highlightItem(id, false),
|
highlightItem(id, false),
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'highlightItem', eventResponse);
|
triggerEvent(this.passedElement, EVENTS.highlightItem, eventResponse);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -686,7 +685,7 @@ class Choices {
|
||||||
this.dropdown.show();
|
this.dropdown.show();
|
||||||
this.input.activate(focusInput);
|
this.input.activate(focusInput);
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'showDropdown', {});
|
triggerEvent(this.passedElement, EVENTS.showDropdown, {});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,7 +703,7 @@ class Choices {
|
||||||
this.dropdown.hide();
|
this.dropdown.hide();
|
||||||
this.input.deactivate(blurInput);
|
this.input.deactivate(blurInput);
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'hideDropdown', {});
|
triggerEvent(this.passedElement, EVENTS.hideDropdown, {});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,7 +1012,7 @@ class Choices {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'change', {
|
triggerEvent(this.passedElement, EVENTS.change, {
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1122,7 +1121,7 @@ class Choices {
|
||||||
// Update choice keyCode
|
// Update choice keyCode
|
||||||
choice.keyCode = passedKeyCode;
|
choice.keyCode = passedKeyCode;
|
||||||
|
|
||||||
triggerEvent(this.passedElement, 'choice', {
|
triggerEvent(this.passedElement, EVENTS.choice, {
|
||||||
choice,
|
choice,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1371,7 +1370,7 @@ class Choices {
|
||||||
if (value && value.length >= this.config.searchFloor) {
|
if (value && value.length >= this.config.searchFloor) {
|
||||||
const resultCount = this.config.searchChoices ? this._searchChoices(value) : 0;
|
const resultCount = this.config.searchChoices ? this._searchChoices(value) : 0;
|
||||||
// Trigger search event
|
// Trigger search event
|
||||||
triggerEvent(this.passedElement, 'search', {
|
triggerEvent(this.passedElement, EVENTS.search, {
|
||||||
value,
|
value,
|
||||||
resultCount,
|
resultCount,
|
||||||
});
|
});
|
||||||
|
@ -2064,7 +2063,7 @@ class Choices {
|
||||||
|
|
||||||
// Trigger change event
|
// Trigger change event
|
||||||
if (group && group.value) {
|
if (group && group.value) {
|
||||||
triggerEvent(this.passedElement, 'addItem', {
|
triggerEvent(this.passedElement, EVENTS.addItem, {
|
||||||
id,
|
id,
|
||||||
value: passedValue,
|
value: passedValue,
|
||||||
label: passedLabel,
|
label: passedLabel,
|
||||||
|
@ -2072,7 +2071,7 @@ class Choices {
|
||||||
keyCode: passedKeyCode,
|
keyCode: passedKeyCode,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
triggerEvent(this.passedElement, 'addItem', {
|
triggerEvent(this.passedElement, EVENTS.addItem, {
|
||||||
id,
|
id,
|
||||||
value: passedValue,
|
value: passedValue,
|
||||||
label: passedLabel,
|
label: passedLabel,
|
||||||
|
@ -2106,14 +2105,14 @@ class Choices {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (group && group.value) {
|
if (group && group.value) {
|
||||||
triggerEvent(this.passedElement, 'removeItem', {
|
triggerEvent(this.passedElement, EVENTS.removeItem, {
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
label,
|
label,
|
||||||
groupValue: group.value,
|
groupValue: group.value,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
triggerEvent(this.passedElement, 'removeItem', {
|
triggerEvent(this.passedElement, EVENTS.removeItem, {
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
label,
|
label,
|
||||||
|
|
|
@ -68,3 +68,14 @@ export const DEFAULT_CONFIG = {
|
||||||
callbackOnInit: null,
|
callbackOnInit: null,
|
||||||
callbackOnCreateTemplates: null,
|
callbackOnCreateTemplates: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const EVENTS = {
|
||||||
|
showDropdown: 'showDropdown',
|
||||||
|
hideDropdown: 'hideDropdown',
|
||||||
|
change: 'change',
|
||||||
|
choice: 'choice',
|
||||||
|
search: 'search',
|
||||||
|
addItem: 'addItem',
|
||||||
|
removeItem: 'removeItem',
|
||||||
|
highlightItem: 'highlightItem',
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue