mirror of
https://github.com/bigskysoftware/htmx.git
synced 2026-05-02 14:44:42 +00:00
initial inheritance disabling work
This commit is contained in:
20
src/htmx.js
20
src/htmx.js
@@ -75,7 +75,8 @@ return (function () {
|
||||
globalViewTransitions: false,
|
||||
methodsThatUseUrlParams: ["get"],
|
||||
selfRequestsOnly: false,
|
||||
scrollIntoViewOnBoost: true
|
||||
scrollIntoViewOnBoost: true,
|
||||
disableInheritance: false
|
||||
},
|
||||
parseInterval:parseInterval,
|
||||
_:internalEval,
|
||||
@@ -202,11 +203,20 @@ return (function () {
|
||||
function getAttributeValueWithDisinheritance(initialElement, ancestor, attributeName){
|
||||
var attributeValue = getAttributeValue(ancestor, attributeName);
|
||||
var disinherit = getAttributeValue(ancestor, "hx-disinherit");
|
||||
if (initialElement !== ancestor && disinherit && (disinherit === "*" || disinherit.split(" ").indexOf(attributeName) >= 0)) {
|
||||
return "unset";
|
||||
} else {
|
||||
return attributeValue
|
||||
var inherit = getAttributeValue(ancestor, "hx-inherit");
|
||||
if (initialElement !== ancestor) {
|
||||
if (htmx.config.disableInheritance) {
|
||||
if (inherit && (inherit === "*" || inherit.split(" ").indexOf(attributeName) >= 0)) {
|
||||
return attributeValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (disinherit && (disinherit === "*" || disinherit.split(" ").indexOf(attributeName) >= 0)) {
|
||||
return "unset";
|
||||
}
|
||||
}
|
||||
return attributeValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
72
test/attributes/hx-inherit.js
Normal file
72
test/attributes/hx-inherit.js
Normal file
@@ -0,0 +1,72 @@
|
||||
describe("hx-inherit attribute", function() {
|
||||
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
htmx.config.disableInheritance = true;
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
htmx.config.disableInheritance = false;
|
||||
});
|
||||
|
||||
it('can disable inheritance', function () {
|
||||
this.server.respondWith("GET", "/test", "Test");
|
||||
var div = make('<div hx-target="#cta">' +
|
||||
'<button id="btn1" hx-get="/test"></button>' +
|
||||
'<span id="cta">Click Me!</span>' +
|
||||
'</div>')
|
||||
var btn = byId("btn1");
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerText.should.equal("Test");
|
||||
})
|
||||
|
||||
it('can enable inheritance for all', function () {
|
||||
this.server.respondWith("GET", "/test", "Test");
|
||||
var div = make('<div hx-target="#cta" hx-inherit="*">' +
|
||||
'<button id="btn1" hx-get="/test"></button>' +
|
||||
'<span id="cta">Click Me!</span>' +
|
||||
'</div>')
|
||||
var btn = byId("btn1");
|
||||
var span = byId("cta");
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerText.should.equal("");
|
||||
span.innerText.should.equal("Test");
|
||||
})
|
||||
|
||||
it('can enable inheritance by name', function () {
|
||||
this.server.respondWith("GET", "/test", "Test");
|
||||
var div = make('<div hx-target="#cta" hx-inherit="hx-target">' +
|
||||
'<button id="btn1" hx-get="/test"></button>' +
|
||||
'<span id="cta">Click Me!</span>' +
|
||||
'</div>')
|
||||
var btn = byId("btn1");
|
||||
var span = byId("cta");
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerText.should.equal("");
|
||||
span.innerText.should.equal("Test");
|
||||
})
|
||||
|
||||
it('can enable inheritance by name 2', function () {
|
||||
this.server.respondWith("GET", "/test", "Test");
|
||||
var div = make('<div hx-target="#cta" hx-inherit="hx-swap">' +
|
||||
'<button id="btn1" hx-get="/test"></button>' +
|
||||
'<span id="cta">Click Me!</span>' +
|
||||
'</div>')
|
||||
var btn = byId("btn1");
|
||||
var span = byId("cta");
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
console.log(div.innerHTML)
|
||||
btn.innerText.should.equal("Test");
|
||||
span.innerText.should.equal("Click Me!");
|
||||
})
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
<script src="attributes/hx-include.js"></script>
|
||||
<script src="attributes/hx-indicator.js"></script>
|
||||
<script src="attributes/hx-disabled-elt.js"></script>
|
||||
<script src="attributes/hx-inherit.js"></script>
|
||||
<script src="attributes/hx-disinherit.js"></script>
|
||||
<script src="attributes/hx-on.js"></script>
|
||||
<script src="attributes/hx-on-wildcard.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user