FIX_ISSUE_DROPDOW_CLICK

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

View File

@ -308,15 +308,51 @@
function handleItemClick(e, item) { function handleItemClick(e, item) {
e.preventDefault(); e.preventDefault();
// Execute the stored onclick handler
const onclickAttr = item.getAttribute('data-onclick'); const onclickAttr = item.getAttribute('data-onclick');
if (onclickAttr) { 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];
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 href navigation // Handle standard navigation if it's a link
const href = item.getAttribute('href'); const href = item.getAttribute('href');
if (href && href !== '#') { if (href && href !== '#' && !href.includes('javascript:void(0)')) {
window.location.href = href; window.location.href = href;
} }