From b8cf945a5f54cc726b0e795e9f0e3fba1e6fd39b Mon Sep 17 00:00:00 2001 From: Carson Gross Date: Sat, 18 Mar 2023 17:03:10 -0600 Subject: [PATCH] set up event symbol correctly --- src/htmx.js | 16 ++++++++++------ test/scratch/scratch.html | 11 ++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 0d0da69e..7c3c0dd0 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1922,26 +1922,26 @@ return (function () { var kebabedEvent = makeEvent(kebabName, event.detail); eventResult = eventResult && elt.dispatchEvent(kebabedEvent) } - eventResult = eventResult && triggerInlineHandlers(elt, kebabName); + eventResult = eventResult && triggerInlineHandlers(elt, event, kebabName); withExtensions(elt, function (extension) { eventResult = eventResult && (extension.onEvent(eventName, event) !== false) }); return eventResult; } - function triggerInlineHandlers(elt, kebabbedEvent, noBubble) { + function triggerInlineHandlers(elt, evt, kebabbedEvent, noBubble) { var strippedEventName = kebabbedEvent.replace('htmx:', '').replace(":", "\\:").replace(".", "\\."); var hxOnAttributeNameForEvent = "hx-on-" + strippedEventName; var selector = "[" + hxOnAttributeNameForEvent + "]"; if (noBubble) { if (matches(elt, selector)) { - return evalAttrValue(elt, hxOnAttributeNameForEvent); + return evalAttrValue(elt, evt, hxOnAttributeNameForEvent); } } else { var closestMatch = closest(elt, selector); while (closestMatch != null) { // terminate simulated bubbling if handler returns false - if(evalAttrValue(closestMatch, hxOnAttributeNameForEvent) === false) { + if(evalAttrValue(closestMatch, evt, hxOnAttributeNameForEvent) === false) { return false; } var parentOfMatch = parentElt(closestMatch); @@ -1951,10 +1951,14 @@ return (function () { } } - function evalAttrValue(elt, attributeName) { + function evalAttrValue(elt, evt, attributeName) { var attrValue = elt.getAttribute(attributeName); try { - return eval(attrValue) + return maybeEval(elt, + function () { + return Function("event", attrValue + "; return true;")(evt); + }, + true) } catch(e) { console.error("Error evaluating " + attributeName + " on", elt, ":", e); } diff --git a/test/scratch/scratch.html b/test/scratch/scratch.html index 07e9f084..fdb153e6 100644 --- a/test/scratch/scratch.html +++ b/test/scratch/scratch.html @@ -63,11 +63,20 @@ Autorespond: - + + -- + +