FIX_ISSUE_DROPDOW_CLICK

This commit is contained in:
VENKATESHWARAN 2026-02-10 11:23:32 +05:30
parent 4a66b3a67e
commit c41934a574

View File

@ -306,17 +306,53 @@
}
function handleItemClick(e, item) {
e.preventDefault();
// Execute the stored onclick handler
e.preventDefault();
const onclickAttr = item.getAttribute('data-onclick');
if (onclickAttr) {
eval(onclickAttr);
}
// Regex to separate function name from the inside of the parentheses
// Example: myFunc(this, '123') -> match[1]="myFunc", match[2]="this, '123'"
const match = onclickAttr.match(/^(\w+)\((.*)\)$/);
if (match) {
const funcName = match[1];
const argsRaw = match[2];
// Handle href navigation
if (typeof window[funcName] === 'function') {
// Parse the arguments string into a real array
const args = argsRaw.split(',').map(arg => {
let cleaned = arg.trim();
// 1. Handle the 'this' keyword
if (cleaned === 'this') return item;
// 2. Handle 'event' keyword
if (cleaned === 'event') return e;
// 3. Handle strings (remove single or double quotes)
if ((cleaned.startsWith("'") && cleaned.endsWith("'")) ||
(cleaned.startsWith('"') && cleaned.endsWith('"'))) {
return cleaned.substring(1, cleaned.length - 1);
}
// 4. Handle numbers
if (!isNaN(cleaned) && cleaned !== "") {
return Number(cleaned);
}
return cleaned;
});
// Execute function:
// .apply(item, args) sets the 'this' inside the function to the clicked element
window[funcName].apply(item, args);
}
}
}
// Handle standard navigation if it's a link
const href = item.getAttribute('href');
if (href && href !== '#') {
if (href && href !== '#' && !href.includes('javascript:void(0)')) {
window.location.href = href;
}
@ -324,7 +360,7 @@
activeDropdown.style.display = 'none';
activeDropdown = null;
}
e.stopPropagation();
}