mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
tes
This commit is contained in:
+60
-7
@@ -2444,6 +2444,8 @@ function initIconPicker() {
|
|||||||
if (!iconInput || !iconDropdown) return;
|
if (!iconInput || !iconDropdown) return;
|
||||||
|
|
||||||
let isDropdownOpen = false;
|
let isDropdownOpen = false;
|
||||||
|
let isMouseOverDropdown = false;
|
||||||
|
let isMouseOverInput = false;
|
||||||
|
|
||||||
// Position dropdown relative to input
|
// Position dropdown relative to input
|
||||||
function positionDropdown() {
|
function positionDropdown() {
|
||||||
@@ -2454,8 +2456,12 @@ function initIconPicker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Toggle dropdown
|
// Toggle dropdown
|
||||||
function toggleDropdown() {
|
function toggleDropdown(open) {
|
||||||
|
if (open !== undefined) {
|
||||||
|
isDropdownOpen = open;
|
||||||
|
} else {
|
||||||
isDropdownOpen = !isDropdownOpen;
|
isDropdownOpen = !isDropdownOpen;
|
||||||
|
}
|
||||||
iconDropdown.classList.toggle('hidden', !isDropdownOpen);
|
iconDropdown.classList.toggle('hidden', !isDropdownOpen);
|
||||||
|
|
||||||
if (isDropdownOpen) {
|
if (isDropdownOpen) {
|
||||||
@@ -2470,10 +2476,27 @@ function initIconPicker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle mouse enter/leave events
|
||||||
|
iconInput.addEventListener('mouseenter', () => {
|
||||||
|
isMouseOverInput = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
iconInput.addEventListener('mouseleave', () => {
|
||||||
|
isMouseOverInput = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
iconDropdown.addEventListener('mouseenter', () => {
|
||||||
|
isMouseOverDropdown = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
iconDropdown.addEventListener('mouseleave', () => {
|
||||||
|
isMouseOverDropdown = false;
|
||||||
|
});
|
||||||
|
|
||||||
// Handle click outside
|
// Handle click outside
|
||||||
function handleClickOutside(e) {
|
function handleClickOutside(e) {
|
||||||
if (isDropdownOpen && !iconDropdown.contains(e.target) && e.target !== iconInput) {
|
if (isDropdownOpen && !isMouseOverDropdown && !isMouseOverInput) {
|
||||||
toggleDropdown();
|
toggleDropdown(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2481,14 +2504,14 @@ function initIconPicker() {
|
|||||||
iconInput.addEventListener('click', (e) => {
|
iconInput.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
toggleDropdown();
|
toggleDropdown(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Close dropdown handlers
|
// Close dropdown handlers
|
||||||
if (closeButton) {
|
if (closeButton) {
|
||||||
closeButton.addEventListener('click', (e) => {
|
closeButton.addEventListener('click', (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
toggleDropdown();
|
toggleDropdown(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2503,7 +2526,7 @@ function initIconPicker() {
|
|||||||
const iconClass = iconOption.getAttribute('data-icon');
|
const iconClass = iconOption.getAttribute('data-icon');
|
||||||
if (iconClass) {
|
if (iconClass) {
|
||||||
selectIcon(iconClass);
|
selectIcon(iconClass);
|
||||||
toggleDropdown(); // Close dropdown after selection
|
toggleDropdown(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2527,7 +2550,7 @@ function initIconPicker() {
|
|||||||
// Close on Escape
|
// Close on Escape
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Escape' && isDropdownOpen) {
|
if (e.key === 'Escape' && isDropdownOpen) {
|
||||||
toggleDropdown();
|
toggleDropdown(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2544,6 +2567,36 @@ function initIconPicker() {
|
|||||||
positionDropdown();
|
positionDropdown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clean up event listeners when component is removed
|
||||||
|
const cleanup = () => {
|
||||||
|
iconInput.removeEventListener('mouseenter', () => {
|
||||||
|
isMouseOverInput = true;
|
||||||
|
});
|
||||||
|
iconInput.removeEventListener('mouseleave', () => {
|
||||||
|
isMouseOverInput = false;
|
||||||
|
});
|
||||||
|
iconDropdown.removeEventListener('mouseenter', () => {
|
||||||
|
isMouseOverDropdown = true;
|
||||||
|
});
|
||||||
|
iconDropdown.removeEventListener('mouseleave', () => {
|
||||||
|
isMouseOverDropdown = false;
|
||||||
|
});
|
||||||
|
document.removeEventListener('click', handleClickOutside);
|
||||||
|
window.removeEventListener('scroll', () => {
|
||||||
|
if (isDropdownOpen) {
|
||||||
|
positionDropdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.removeEventListener('resize', () => {
|
||||||
|
if (isDropdownOpen) {
|
||||||
|
positionDropdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add cleanup to window beforeunload
|
||||||
|
window.addEventListener('beforeunload', cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render icons based on search term
|
// Render icons based on search term
|
||||||
|
|||||||
Reference in New Issue
Block a user