Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Telroshan committed Sep 19, 2024
1 parent 0573fc9 commit b6022a3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,22 +1136,23 @@ var htmx = (function() {
/**
* @param {Node|Element|Document|string} elt
* @param {string} selector
* @param {boolean=} global
* @returns {(Node|Window)[]}
*/
function querySelectorAllExt(elt, selector, global) {
function querySelectorAllExt(elt, selector) {
elt = resolveTarget(elt)

const parts = selector.split(',')
const result = []
const unprocessedParts = []
// Previous implementation of global would apply it to all selectors if put at the first position.
// With the multiple selectors support, had to maintain backwards compatibility, hence the outer global variable
let global = false
for (let i = 0; i < parts.length; i++) {
let selector = parts[i].trimStart()
let selector = normalizeSelector(parts[i])

if (selector.indexOf('global ') === 0) {
global = true
selector = selector.substring(7)
parts[i] = selector
}

if (selector.indexOf('closest ') === 0) {
Expand All @@ -1161,28 +1162,27 @@ var htmx = (function() {
} else if (selector === 'next' || selector === 'nextElementSibling') {
result.push(asElement(elt).nextElementSibling)
} else if (selector.indexOf('next ') === 0) {
result.push(scanForwardQuery(elt, normalizeSelector(selector.substr(5)), !!global))
result.push(scanForwardQuery(elt, normalizeSelector(selector.substr(5)), global))
} else if (selector === 'previous' || selector === 'previousElementSibling') {
result.push(asElement(elt).previousElementSibling)
} else if (selector.indexOf('previous ') === 0) {
result.push(scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)), !!global))
result.push(scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)), global))
} else if (selector === 'document') {
result.push(document)
} else if (selector === 'window') {
result.push(window)
} else if (selector === 'body') {
result.push(document.body)
} else if (selector === 'root') {
result.push(getRootNode(elt, !!global))
result.push(getRootNode(elt, global))
} else {
// Push back the unaltered string part, so that the standard selector fallback uses the exact initial string
unprocessedParts.push(parts[i])
unprocessedParts.push(selector)
}
}

if (unprocessedParts.length > 0) {
selector = unprocessedParts.join(',')
result.push(...toArray(asParentNode(getRootNode(elt, !!global)).querySelectorAll(normalizeSelector(selector))))
result.push(...toArray(asParentNode(getRootNode(elt, global)).querySelectorAll(selector)))
}

return result
Expand Down

0 comments on commit b6022a3

Please sign in to comment.