Script simplification: Less nesting

This commit is contained in:
Ali Khaleqi Yekta 2025-05-04 12:18:49 +03:30
parent b26fc15fa0
commit 5369144b64
No known key found for this signature in database
GPG key ID: 8CE90F8CC149DE8C

View file

@ -86,9 +86,6 @@
}; };
const handleClicks = () => { const handleClicks = () => {
document.addEventListener(
'click',
async e => {
const trackElement = async el => { const trackElement = async el => {
const attr = el.getAttribute.bind(el); const attr = el.getAttribute.bind(el);
const eventName = attr(eventNameAttribute); const eventName = attr(eventNameAttribute);
@ -103,7 +100,7 @@
return track(eventName, eventData); return track(eventName, eventData);
} }
}; };
const onClick = async e => {
const el = e.target; const el = e.target;
const parentElement = el.closest('a,button'); const parentElement = el.closest('a,button');
if (!parentElement) return trackElement(el); if (!parentElement) return trackElement(el);
@ -129,9 +126,8 @@
} }
}); });
} }
}, };
true, document.addEventListener('click', onClick, true);
);
}; };
/* Tracking functions */ /* Tracking functions */