mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 04:22:58 +00:00
te
This commit is contained in:
+21
-18
@@ -2445,7 +2445,9 @@ function initIconPicker() {
|
|||||||
|
|
||||||
let isModalOpen = false;
|
let isModalOpen = false;
|
||||||
|
|
||||||
// Simple show/hide functions
|
|
||||||
|
|
||||||
|
// Improved modal toggle with cleanup
|
||||||
const toggleModal = () => {
|
const toggleModal = () => {
|
||||||
isModalOpen = !isModalOpen;
|
isModalOpen = !isModalOpen;
|
||||||
document.body.style.overflow = isModalOpen ? 'hidden' : '';
|
document.body.style.overflow = isModalOpen ? 'hidden' : '';
|
||||||
@@ -2455,9 +2457,17 @@ function initIconPicker() {
|
|||||||
// Focus search input only after modal is visible
|
// Focus search input only after modal is visible
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
if (iconSearch) {
|
if (iconSearch) {
|
||||||
|
iconSearch.value = '';
|
||||||
|
renderIcons('');
|
||||||
iconSearch.focus();
|
iconSearch.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// Reset search when closing
|
||||||
|
if (iconSearch) {
|
||||||
|
iconSearch.value = '';
|
||||||
|
renderIcons('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2470,19 +2480,13 @@ function initIconPicker() {
|
|||||||
|
|
||||||
// Close modal handlers
|
// Close modal handlers
|
||||||
if (closeButton) {
|
if (closeButton) {
|
||||||
closeButton.addEventListener('click', () => {
|
closeButton.addEventListener('click', toggleModal);
|
||||||
isModalOpen = false;
|
|
||||||
document.body.style.overflow = '';
|
|
||||||
iconPickerModal.style.display = 'none';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close when clicking outside the modal content
|
// Close when clicking outside the modal content
|
||||||
iconPickerModal.addEventListener('click', (e) => {
|
iconPickerModal.addEventListener('click', (e) => {
|
||||||
if (e.target === iconPickerModal) {
|
if (e.target === iconPickerModal && isModalOpen) {
|
||||||
isModalOpen = false;
|
toggleModal();
|
||||||
document.body.style.overflow = '';
|
|
||||||
iconPickerModal.style.display = 'none';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2490,19 +2494,20 @@ function initIconPicker() {
|
|||||||
if (iconList) {
|
if (iconList) {
|
||||||
iconList.addEventListener('click', (e) => {
|
iconList.addEventListener('click', (e) => {
|
||||||
const iconOption = e.target.closest('.icon-option');
|
const iconOption = e.target.closest('.icon-option');
|
||||||
if (iconOption) {
|
if (iconOption && isModalOpen) {
|
||||||
const iconClass = iconOption.getAttribute('data-icon');
|
const iconClass = iconOption.getAttribute('data-icon');
|
||||||
selectIcon(iconClass);
|
selectIcon(iconClass);
|
||||||
|
toggleModal(); // Close modal after selection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle search
|
// Handle search with improved debounce
|
||||||
if (iconSearch) {
|
if (iconSearch) {
|
||||||
|
let searchTimeout;
|
||||||
iconSearch.addEventListener('input', () => {
|
iconSearch.addEventListener('input', () => {
|
||||||
// Debounce search to prevent excessive re-renders
|
if (searchTimeout) clearTimeout(searchTimeout);
|
||||||
clearTimeout(iconSearch.dataset.searchTimeout);
|
searchTimeout = setTimeout(() => {
|
||||||
iconSearch.dataset.searchTimeout = setTimeout(() => {
|
|
||||||
renderIcons(iconSearch.value.toLowerCase());
|
renderIcons(iconSearch.value.toLowerCase());
|
||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
@@ -2514,9 +2519,7 @@ function initIconPicker() {
|
|||||||
// Close on Escape
|
// Close on Escape
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Escape' && isModalOpen) {
|
if (e.key === 'Escape' && isModalOpen) {
|
||||||
isModalOpen = false;
|
toggleModal();
|
||||||
document.body.style.overflow = '';
|
|
||||||
iconPickerModal.style.display = 'none';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user