Skip to content

Commit 56ed569

Browse files
committed
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
2 parents 9760e32 + 12e62ce commit 56ed569

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

src/ext/sse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
155155
}, timeout);
156156
}
157157
};
158+
159+
source.onopen = function (evt) {
160+
api.triggerEvent(elt, "htmx::sseOpen", {source: source});
161+
}
158162

159163
// Add message handlers for every `sse-swap` attribute
160164
queryAttributeOnThisOrChildren(elt, "sse-swap").forEach(function(child) {

src/htmx.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,23 @@ return (function () {
433433
}
434434
}
435435

436+
function normalizePath(path) {
437+
try {
438+
var url = new URL(path);
439+
if (url) {
440+
path = url.pathname + url.search;
441+
}
442+
// remove trailing slash, unless index page
443+
if (!path.match('^/$')) {
444+
path = path.replace(/\/+$/, '');
445+
}
446+
return path;
447+
} catch (e) {
448+
// be kind to IE11, which doesn't support URL()
449+
return path;
450+
}
451+
}
452+
436453
//==========================================================================================
437454
// public API
438455
//==========================================================================================
@@ -1301,7 +1318,7 @@ return (function () {
13011318
var verb, path;
13021319
if (elt.tagName === "A") {
13031320
verb = "get";
1304-
path = getRawAttribute(elt, 'href');
1321+
path = elt.href; // DOM property gives the fully resolved href of a relative link
13051322
} else {
13061323
var rawAttribute = getRawAttribute(elt, "method");
13071324
verb = rawAttribute ? rawAttribute.toLowerCase() : "get";
@@ -2037,6 +2054,8 @@ return (function () {
20372054
return;
20382055
}
20392056

2057+
url = normalizePath(url);
2058+
20402059
var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
20412060
for (var i = 0; i < historyCache.length; i++) {
20422061
if (historyCache[i].url === url) {
@@ -2066,6 +2085,8 @@ return (function () {
20662085
return null;
20672086
}
20682087

2088+
url = normalizePath(url);
2089+
20692090
var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
20702091
for (var i = 0; i < historyCache.length; i++) {
20712092
if (historyCache[i].url === url) {

test/attributes/hx-disinherit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ describe("hx-disinherit attribute", function() {
100100
var div = make('<div hx-boost="true" hx-disinherit="false"><a id="a1" href="/test">Click me</a></div>');
101101
var link = byId("a1");
102102
link.click();
103-
should.equal(request.detail.requestConfig.path, '/test');
103+
// should match the fully resolved href of the boosted element
104+
should.equal(request.detail.requestConfig.path, request.detail.elt.href);
104105
should.equal(request.detail.elt["htmx-internal-data"].boosted, true);
105106
} finally {
106107
htmx.off("htmx:beforeRequest", handler);

www/themes/htmx-theme/templates/base.html

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<script src="/js/class-tools.js"></script>
1414
<script src="/js/preload.js"></script>
1515
<script src="/js/_hyperscript.js"></script>
16-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css">
1716
<meta name="generator" content="Zola v.TODO">
1817
</head>
1918
<body hx-ext="class-tools, preload">
@@ -50,12 +49,11 @@
5049
<div>
5150
<a href="/essays/">essays</a>
5251
</div>
53-
<div>
54-
<input _="on keyup[key is 'Escape'] or click elsewhere
55-
blur() then set my.value to ''
56-
on keyup[key is '/'] from <body/>
57-
focus()"
58-
placeholder="&#128269;" type="text" id="search"/>
52+
<div hx-disable>
53+
<form action="https://google.com/search">
54+
<input type="hidden" name="q" value="site:htmx.org">
55+
<label><span style="display:none;">Search</span><input type="text" name="q" placeholder="🔍️" class="search-box"></label>
56+
</form>
5957
</div>
6058
</div>
6159
<div class="github-stars">
@@ -118,13 +116,5 @@ <h2>haiku</h2>
118116
</div>
119117
</footer>
120118

121-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
122-
<script type="text/javascript"> docsearch({
123-
apiKey: '47070108e6ce8dfee6beee94b83bee7d',
124-
indexName: 'htmx',
125-
inputSelector: '#search',
126-
debug: false // Set debug to true if you want to inspect the dropdown
127-
});
128-
</script>
129119
</body>
130120
</html>

0 commit comments

Comments
 (0)