summaryrefslogtreecommitdiffstatshomepage
path: root/src/htmx.js
diff options
context:
space:
mode:
authorCarson Gross <carson@bigsky.software>2024-04-17 05:25:28 -0600
committerCarson Gross <carson@bigsky.software>2024-04-17 05:25:28 -0600
commit01cb5e0d8dd497c0a5f24afb7d00753e84b408e4 (patch)
tree3a47d3c7984293d9e92ba5f0df2b561299837ffe /src/htmx.js
parent81afe922d7aa2fadc1d303a0f14dc7ab83a2d25e (diff)
downloadhtmx-01cb5e0d8dd497c0a5f24afb7d00753e84b408e4.tar.gz
htmx-01cb5e0d8dd497c0a5f24afb7d00753e84b408e4.zip
support hx-on in shadowroot
Diffstat (limited to 'src/htmx.js')
-rw-r--r--src/htmx.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/htmx.js b/src/htmx.js
index a24926aa..6d55eec8 100644
--- a/src/htmx.js
+++ b/src/htmx.js
@@ -2602,19 +2602,29 @@ var htmx = (function() {
* @param {Node} elt
* @returns {Element[]}
*/
+ const HX_ON_QUERY = new XPathEvaluator()
+ .createExpression('.//*[@*[ starts-with(name(), "hx-on:") or starts-with(name(), "data-hx-on:") or' +
+ ' starts-with(name(), "hx-on-") or starts-with(name(), "data-hx-on-") ]]');
+
+ function processHXOnRoot(elt, elements) {
+ if (shouldProcessHxOn(elt)) {
+ elements.push(asElement(elt))
+ }
+ const iter = HX_ON_QUERY.evaluate(elt)
+ let node = null;
+ while (node = iter.iterateNext()) elements.push(asElement(node))
+ }
+
function findHxOnWildcardElements(elt) {
let node = null
/** @type {Element[]} */
const elements = []
-
- if (!(elt instanceof ShadowRoot)) {
- if (shouldProcessHxOn(elt)) {
- elements.push(asElement(elt))
+ if (elt instanceof DocumentFragment) {
+ for (const child of elt.childNodes) {
+ processHXOnRoot(child, elements);
}
-
- const iter = document.evaluate('.//*[@*[ starts-with(name(), "hx-on:") or starts-with(name(), "data-hx-on:") or' +
- ' starts-with(name(), "hx-on-") or starts-with(name(), "data-hx-on-") ]]', elt)
- while (node = iter.iterateNext()) elements.push(asElement(node))
+ } else {
+ processHXOnRoot(elt, elements);
}
return elements
}