diff --git a/src/ext/sse.js b/src/ext/sse.js index 34571435..4088cd29 100644 --- a/src/ext/sse.js +++ b/src/ext/sse.js @@ -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) { diff --git a/src/htmx.js b/src/htmx.js index be02b740..1981a902 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -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) { diff --git a/test/attributes/hx-disinherit.js b/test/attributes/hx-disinherit.js index 6482f65e..f069a833 100644 --- a/test/attributes/hx-disinherit.js +++ b/test/attributes/hx-disinherit.js @@ -100,7 +100,8 @@ describe("hx-disinherit attribute", function() { var div = make('
Click me
'); 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); diff --git a/www/themes/htmx-theme/templates/base.html b/www/themes/htmx-theme/templates/base.html index ff4dc62d..5337ac97 100644 --- a/www/themes/htmx-theme/templates/base.html +++ b/www/themes/htmx-theme/templates/base.html @@ -13,7 +13,6 @@ - @@ -50,12 +49,11 @@
essays
-
- +
+
+ + +
@@ -118,13 +116,5 @@
- -