diff --git a/src/htmx.js b/src/htmx.js index 7792941d3..e71e1445c 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -4910,23 +4910,30 @@ var htmx = (function() { * @returns {HtmxExtension[]} */ function getExtensions(elt, extensionsToReturn, extensionsToIgnore) { - if (extensionsToReturn == undefined) { + const isParentScan = !!extensionsToReturn + if (!extensionsToReturn) { extensionsToReturn = [] } - if (elt == undefined) { + if (!elt) { return extensionsToReturn } - if (extensionsToIgnore == undefined) { + if (!extensionsToIgnore) { extensionsToIgnore = [] } const extensionsForElement = getAttributeValue(elt, 'hx-ext') if (extensionsForElement) { forEach(extensionsForElement.split(','), function(extensionName) { - extensionName = extensionName.replace(/ /g, '') - if (extensionName.slice(0, 7) == 'ignore:') { + extensionName = extensionName.trim() + if (extensionName.indexOf('ignore:') === 0) { extensionsToIgnore.push(extensionName.slice(7)) return } + if (extensionName.indexOf('this-only:') === 0) { + if (isParentScan) { + return + } + extensionName = extensionName.slice(10) + } if (extensionsToIgnore.indexOf(extensionName) < 0) { const extension = extensions[extensionName] if (extension && extensionsToReturn.indexOf(extension) < 0) { diff --git a/test/attributes/hx-ext.js b/test/attributes/hx-ext.js index b573c4ddf..c00592e65 100644 --- a/test/attributes/hx-ext.js +++ b/test/attributes/hx-ext.js @@ -156,4 +156,28 @@ describe('hx-ext attribute', function() { ext5Calls.should.equal(1) }) + + it('Extensions can be applied to this element only properly', function() { + this.server.respondWith('GET', '/test', 'Clicked!') + + make('