mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 23:35:13 +00:00
[2.0] Improve extension registration logic (#2505)
* add getSelectors to extension contract and extensionEnabled() to internal API * remove extensionEnabled method (it's useless)
This commit is contained in:
parent
f0bd28b438
commit
45d45c30af
1
src/htmx.d.ts
vendored
1
src/htmx.d.ts
vendored
@ -53,6 +53,7 @@ declare namespace htmx {
|
||||
const triggerSpecsCache: any | null;
|
||||
const disableInheritance: boolean;
|
||||
const responseHandling: HtmxResponseHandlingConfig[];
|
||||
const allowNestedOobSwaps: boolean;
|
||||
}
|
||||
const parseInterval: (str: string) => number;
|
||||
const _: (str: string) => any;
|
||||
|
16
src/htmx.js
16
src/htmx.js
@ -2635,8 +2635,21 @@ var htmx = (function() {
|
||||
function findElementsToProcess(elt) {
|
||||
if (elt.querySelectorAll) {
|
||||
const boostedSelector = ', [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]'
|
||||
|
||||
const extensionSelectors = []
|
||||
for (const e in extensions) {
|
||||
const extension = extensions[e]
|
||||
if (extension.getSelectors) {
|
||||
var selectors = extension.getSelectors()
|
||||
if (selectors) {
|
||||
extensionSelectors.push(selectors)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const results = elt.querySelectorAll(VERB_SELECTOR + boostedSelector + ", form, [type='submit']," +
|
||||
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]')
|
||||
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]' + extensionSelectors.flat().map(s => ', ' + s).join(''))
|
||||
|
||||
return results
|
||||
} else {
|
||||
return []
|
||||
@ -4754,6 +4767,7 @@ var htmx = (function() {
|
||||
function extensionBase() {
|
||||
return {
|
||||
init: function(api) { return null },
|
||||
getSelectors: function() { return null },
|
||||
onEvent: function(name, evt) { return true },
|
||||
transformResponse: function(text, xhr, elt) { return text },
|
||||
isInlineSwap: function(swapStyle) { return false },
|
||||
|
Loading…
x
Reference in New Issue
Block a user