Merge branch 'master' into dev

# Conflicts:
#	www/attributes/hx-target.md
#	www/css/site.css
#	www/reference.md
#	www/themes/htmx-theme/templates/base.html
This commit is contained in:
Carson Gross 2023-04-11 10:05:27 -06:00
commit 56ed5696e6
4 changed files with 33 additions and 17 deletions

View File

@ -155,6 +155,10 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
}, timeout);
}
};
source.onopen = function (evt) {
api.triggerEvent(elt, "htmx::sseOpen", {source: source});
}
// Add message handlers for every `sse-swap` attribute
queryAttributeOnThisOrChildren(elt, "sse-swap").forEach(function(child) {

View File

@ -433,6 +433,23 @@ return (function () {
}
}
function normalizePath(path) {
try {
var url = new URL(path);
if (url) {
path = url.pathname + url.search;
}
// remove trailing slash, unless index page
if (!path.match('^/$')) {
path = path.replace(/\/+$/, '');
}
return path;
} catch (e) {
// be kind to IE11, which doesn't support URL()
return path;
}
}
//==========================================================================================
// public API
//==========================================================================================
@ -1301,7 +1318,7 @@ return (function () {
var verb, path;
if (elt.tagName === "A") {
verb = "get";
path = getRawAttribute(elt, 'href');
path = elt.href; // DOM property gives the fully resolved href of a relative link
} else {
var rawAttribute = getRawAttribute(elt, "method");
verb = rawAttribute ? rawAttribute.toLowerCase() : "get";
@ -2037,6 +2054,8 @@ return (function () {
return;
}
url = normalizePath(url);
var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
for (var i = 0; i < historyCache.length; i++) {
if (historyCache[i].url === url) {
@ -2066,6 +2085,8 @@ return (function () {
return null;
}
url = normalizePath(url);
var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
for (var i = 0; i < historyCache.length; i++) {
if (historyCache[i].url === url) {

View File

@ -100,7 +100,8 @@ describe("hx-disinherit attribute", function() {
var div = make('<div hx-boost="true" hx-disinherit="false"><a id="a1" href="/test">Click me</a></div>');
var link = byId("a1");
link.click();
should.equal(request.detail.requestConfig.path, '/test');
// should match the fully resolved href of the boosted element
should.equal(request.detail.requestConfig.path, request.detail.elt.href);
should.equal(request.detail.elt["htmx-internal-data"].boosted, true);
} finally {
htmx.off("htmx:beforeRequest", handler);

View File

@ -13,7 +13,6 @@
<script src="/js/class-tools.js"></script>
<script src="/js/preload.js"></script>
<script src="/js/_hyperscript.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css">
<meta name="generator" content="Zola v.TODO">
</head>
<body hx-ext="class-tools, preload">
@ -50,12 +49,11 @@
<div>
<a href="/essays/">essays</a>
</div>
<div>
<input _="on keyup[key is 'Escape'] or click elsewhere
blur() then set my.value to ''
on keyup[key is '/'] from <body/>
focus()"
placeholder="&#128269;" type="text" id="search"/>
<div hx-disable>
<form action="https://google.com/search">
<input type="hidden" name="q" value="site:htmx.org">
<label><span style="display:none;">Search</span><input type="text" name="q" placeholder="🔍️" class="search-box"></label>
</form>
</div>
</div>
<div class="github-stars">
@ -118,13 +116,5 @@
</div>
</footer>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<script type="text/javascript"> docsearch({
apiKey: '47070108e6ce8dfee6beee94b83bee7d',
indexName: 'htmx',
inputSelector: '#search',
debug: false // Set debug to true if you want to inspect the dropdown
});
</script>
</body>
</html>