Change icon on individual checkbox toggle
| @@ -28,6 +28,18 @@ export function getRegexScripts() { | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | + * Toggle the icon for the "select all" checkbox in the regex settings. | |
| 32 | + * - Use `fa-check-double` when the checkbox is unchecked (indicating all scripts are not selected). | |
| 33 | + * - Use `fa-minus` when the checkbox is checked (indicating all scripts are selected). | |
| 34 | + * @param {boolean} allAreChecked Should the "select all" icon be in the checked state? | |
| 35 | + */ | |
| 36 | +function setToggleAllIcon(allAreChecked) { | |
| 37 | + const selectAllIcon = $('#bulk_select_all_toggle').find('i'); | |
| 38 | + selectAllIcon.toggleClass('fa-check-double', !allAreChecked); | |
| 39 | + selectAllIcon.toggleClass('fa-minus', allAreChecked); | |
| 40 | +} | |
| 41 | + | |
| 42 | +/** | |
| 31 | 43 | * Saves a regex script to the extension settings or character data. |
| 32 | 44 | * @param {import('../../char-data.js').RegexScriptData} regexScript |
| 33 | 45 | * @param {number} existingScriptIndex Index of the existing script |
| @@ -183,6 +195,11 @@ async function loadRegexScripts() { | ||
| 183 | 195 | await deleteRegexScript({ id: script.id, isScoped }); |
| 184 | 196 | await reloadCurrentChat(); |
| 185 | 197 | }); |
| 198 | + scriptHtml.find('.regex_bulk_checkbox').on('change', function () { | |
| 199 | + const checkboxes = $('#regex_container .regex_bulk_checkbox'); | |
| 200 | + const allAreChecked = checkboxes.length === checkboxes.filter(':checked').length; | |
| 201 | + setToggleAllIcon(allAreChecked); | |
| 202 | + }); | |
| 186 | 203 | |
| 187 | 204 | $(container).append(scriptHtml); |
| 188 | 205 | } |
| @@ -624,11 +641,7 @@ jQuery(async () => { | ||
| 624 | 641 | const newState = !allAreChecked; // true if we just checked all, false if we just unchecked all |
| 625 | 642 | |
| 626 | 643 | checkboxes.prop('checked', newState); |
| 627 | - | |
| 644 | + setToggleAllIcon(newState); | |
| 628 | - const icon = $(this).find('i'); | |
| 629 | - // Toggle the icon shapes | |
| 630 | - icon.toggleClass('fa-check-double', !newState); // Add 'fa-square-check' when deselected | |
| 631 | - icon.toggleClass('fa-minus', newState); // Add 'fa-square-minus' when selected | |
| 632 | 645 | }); |
| 633 | 646 | |
| 634 | 647 | $('#bulk_enable_regex').on('click', async function () { |