|
| 1 | +/** |
| 2 | + * Category selection functionality for the search page |
| 3 | + * |
| 4 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 5 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 6 | + * obtain one at https://mozilla.org/MPL/2.0/. |
| 7 | + * |
| 8 | + * @package phpMyFAQ |
| 9 | + * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 10 | + * @copyright 2025 phpMyFAQ Team |
| 11 | + * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 12 | + * @link https://www.phpmyfaq.de |
| 13 | + * @since 2025-07-27 |
| 14 | + */ |
| 15 | + |
| 16 | +import Choices from 'choices.js'; |
| 17 | + |
| 18 | +export const handleCategorySelection = (): void => { |
| 19 | + const element: HTMLElement | null = document.getElementById('pmf-search-category'); |
| 20 | + if (element) { |
| 21 | + new Choices(element, { |
| 22 | + silent: false, |
| 23 | + items: [], |
| 24 | + choices: [], |
| 25 | + renderChoiceLimit: -1, |
| 26 | + maxItemCount: -1, |
| 27 | + closeDropdownOnSelect: 'auto', |
| 28 | + singleModeForMultiSelect: false, |
| 29 | + addChoices: false, |
| 30 | + addItems: true, |
| 31 | + addItemFilter: (value: string): boolean => !!value && value !== '', |
| 32 | + removeItems: true, |
| 33 | + removeItemButton: false, |
| 34 | + removeItemButtonAlignLeft: false, |
| 35 | + editItems: false, |
| 36 | + allowHTML: false, |
| 37 | + allowHtmlUserInput: false, |
| 38 | + duplicateItemsAllowed: true, |
| 39 | + delimiter: ',', |
| 40 | + paste: true, |
| 41 | + searchEnabled: true, |
| 42 | + searchChoices: true, |
| 43 | + searchFloor: 1, |
| 44 | + searchResultLimit: 4, |
| 45 | + searchFields: ['label', 'value'], |
| 46 | + position: 'auto', |
| 47 | + resetScrollPosition: true, |
| 48 | + shouldSort: true, |
| 49 | + shouldSortItems: false, |
| 50 | + shadowRoot: null, |
| 51 | + placeholder: true, |
| 52 | + placeholderValue: null, |
| 53 | + searchPlaceholderValue: 'Type to search categories', |
| 54 | + prependValue: null, |
| 55 | + appendValue: null, |
| 56 | + renderSelectedChoices: 'auto', |
| 57 | + loadingText: 'Loading...', |
| 58 | + noResultsText: 'No results found', |
| 59 | + noChoicesText: 'No choices to choose from', |
| 60 | + itemSelectText: 'Press to select', |
| 61 | + uniqueItemText: 'Only unique values can be added', |
| 62 | + customAddItemText: 'Only values matching specific conditions can be added', |
| 63 | + valueComparer: (value1: string, value2: string): boolean => { |
| 64 | + return value1 === value2; |
| 65 | + }, |
| 66 | + classNames: { |
| 67 | + containerOuter: ['choices'], |
| 68 | + containerInner: ['choices__inner'], |
| 69 | + input: ['choices__input'], |
| 70 | + inputCloned: ['choices__input--cloned'], |
| 71 | + list: ['choices__list'], |
| 72 | + listItems: ['choices__list--multiple'], |
| 73 | + listSingle: ['choices__list--single'], |
| 74 | + listDropdown: ['choices__list--dropdown'], |
| 75 | + item: ['choices__item'], |
| 76 | + itemSelectable: ['choices__item--selectable'], |
| 77 | + itemDisabled: ['choices__item--disabled'], |
| 78 | + itemChoice: ['choices__item--choice'], |
| 79 | + description: ['choices__description'], |
| 80 | + placeholder: ['choices__placeholder'], |
| 81 | + group: ['choices__group'], |
| 82 | + groupHeading: ['choices__heading'], |
| 83 | + button: ['choices__button'], |
| 84 | + activeState: ['is-active'], |
| 85 | + focusState: ['is-focused'], |
| 86 | + openState: ['is-open'], |
| 87 | + disabledState: ['is-disabled'], |
| 88 | + highlightedState: ['is-highlighted'], |
| 89 | + selectedState: ['is-selected'], |
| 90 | + flippedState: ['is-flipped'], |
| 91 | + loadingState: ['is-loading'], |
| 92 | + notice: ['choices__notice'], |
| 93 | + addChoice: ['choices__item--selectable', 'add-choice'], |
| 94 | + noResults: ['has-no-results'], |
| 95 | + noChoices: ['has-no-choices'], |
| 96 | + }, |
| 97 | + fuseOptions: { |
| 98 | + includeScore: true, |
| 99 | + }, |
| 100 | + labelId: '', |
| 101 | + callbackOnInit: null, |
| 102 | + callbackOnCreateTemplates: null, |
| 103 | + appendGroupInSearch: false, |
| 104 | + }); |
| 105 | + } |
| 106 | +}; |
0 commit comments