Skip to content

Commit

Permalink
prep 1.8.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
1cg committed Jan 10, 2023
1 parent 613f7b6 commit 15790c2
Show file tree
Hide file tree
Showing 201 changed files with 118,448 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [1.8.5] - ???
## [1.8.5] - 2023-01-??

## [1.8.4] - 2022-11-05

Expand Down
81 changes: 68 additions & 13 deletions www/js/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,24 @@ return (function () {
withCredentials:false,
timeout:0,
wsReconnectDelay: 'full-jitter',
wsBinaryType: 'blob',
disableSelector: "[hx-disable], [data-hx-disable]",
useTemplateFragments: false,
scrollBehavior: 'smooth',
defaultFocusScroll: false,
getCacheBusterParam: false,
},
parseInterval:parseInterval,
_:internalEval,
createEventSource: function(url){
return new EventSource(url, {withCredentials:true})
},
createWebSocket: function(url){
return new WebSocket(url, []);
var sock = new WebSocket(url, []);
sock.binaryType = htmx.config.wsBinaryType;
return sock;
},
version: "1.8.4"
version: "1.8.5"
};

/** @type {import("./htmx").HtmxInternalApi} */
Expand Down Expand Up @@ -417,6 +421,20 @@ return (function () {
}
}

function normalizePath(path) {
if (path.match(/^(http:\/\/|https:\/\/)/)) {
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;
}

//==========================================================================================
// public API
//==========================================================================================
Expand Down Expand Up @@ -509,12 +527,14 @@ return (function () {
if (elt.closest) {
return elt.closest(selector);
} else {
// TODO remove when IE goes away
do{
if (elt == null || matches(elt, selector)){
return elt;
}
}
while (elt = elt && parentElt(elt));
return null;
}
}

Expand Down Expand Up @@ -1252,7 +1272,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";
Expand All @@ -1261,7 +1281,7 @@ return (function () {
path = getRawAttribute(elt, 'action');
}
triggerSpecs.forEach(function(triggerSpec) {
addEventListener(elt, function(evt) {
addEventListener(elt, function(elt, evt) {
issueAjaxRequest(verb, path, elt, evt)
}, nodeData, triggerSpec, true);
});
Expand Down Expand Up @@ -1727,7 +1747,10 @@ return (function () {
} catch (e) {
logError(e);
} finally {
parent.removeChild(script);
// remove old script element, but only if it is still in DOM
if (script.parentElement) {
script.parentElement.removeChild(script);
}
}
}
}
Expand Down Expand Up @@ -1758,9 +1781,10 @@ return (function () {

function initButtonTracking(form){
var maybeSetLastButtonClicked = function(evt){
if (matches(evt.target, "button, input[type='submit']")) {
var elt = closest(evt.target, "button, input[type='submit']");
if (elt !== null) {
var internalData = getInternalData(form);
internalData.lastButtonClicked = evt.target;
internalData.lastButtonClicked = elt;
}
};

Expand Down Expand Up @@ -1919,6 +1943,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) {
Expand Down Expand Up @@ -1948,6 +1974,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) {
Expand All @@ -1969,13 +1997,32 @@ return (function () {
function saveCurrentPageToHistory() {
var elt = getHistoryElement();
var path = currentPathForHistory || location.pathname+location.search;
triggerEvent(getDocument().body, "htmx:beforeHistorySave", {path:path, historyElt:elt});
if(htmx.config.historyEnabled) history.replaceState({htmx:true}, getDocument().title, window.location.href);
saveToHistoryCache(path, cleanInnerHtmlForHistory(elt), getDocument().title, window.scrollY);

// Allow history snapshot feature to be disabled where hx-history="false"
// is present *anywhere* in the current document we're about to save,
// so we can prevent privileged data entering the cache.
// The page will still be reachable as a history entry, but htmx will fetch it
// live from the server onpopstate rather than look in the localStorage cache
var disableHistoryCache = getDocument().querySelector('[hx-history="false" i],[data-hx-history="false" i]');
if (!disableHistoryCache) {
triggerEvent(getDocument().body, "htmx:beforeHistorySave", {path: path, historyElt: elt});
saveToHistoryCache(path, cleanInnerHtmlForHistory(elt), getDocument().title, window.scrollY);
}

if (htmx.config.historyEnabled) history.replaceState({htmx: true}, getDocument().title, window.location.href);
}

function pushUrlIntoHistory(path) {
if(htmx.config.historyEnabled) history.pushState({htmx:true}, "", path);
// remove the cache buster parameter, if any
if (htmx.config.getCacheBusterParam) {
path = path.replace(/org\.htmx\.cache-buster=[^&]*&?/, '')
if (path.endsWith('&') || path.endsWith("?")) {
path = path.slice(0, -1);
}
}
if(htmx.config.historyEnabled) {
history.pushState({htmx:true}, "", path);
}
currentPathForHistory = path;
}

Expand Down Expand Up @@ -2121,7 +2168,7 @@ return (function () {
// and the new value could be arrays, so we have to handle all four cases :/
if (name != null && value != null) {
var current = values[name];
if(current) {
if (current !== undefined) {
if (Array.isArray(current)) {
if (Array.isArray(value)) {
values[name] = current.concat(value);
Expand Down Expand Up @@ -2749,6 +2796,10 @@ return (function () {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
}

if (htmx.config.getCacheBusterParam && verb === 'get') {
filteredParameters['org.htmx.cache-buster'] = getRawAttribute(target, "id") || "true";
}

// behavior of anchors w/ empty href is to use the current URL
if (path == null || path === "") {
path = getDocument().location.href;
Expand Down Expand Up @@ -3108,7 +3159,11 @@ return (function () {
// @ts-ignore
if (selectionInfo.start && newActiveElt.setSelectionRange) {
// @ts-ignore
newActiveElt.setSelectionRange(selectionInfo.start, selectionInfo.end);
try {
newActiveElt.setSelectionRange(selectionInfo.start, selectionInfo.end);
} catch (e) {
// the setSelectionRange method is present on fields that don't support it, so just let this fail
}
}
newActiveElt.focus(focusOptions);
}
Expand Down
9 changes: 8 additions & 1 deletion www/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ htmx.defineExtension("preload", {
// Called after a successful AJAX request, to mark the
// content as loaded (and prevent additional AJAX calls.)
var done = function(html) {
node.preloadState = "DONE"
if (!node.preloadAlways) {
node.preloadState = "DONE"
}

if (attr(node, "preload-images") == "true") {
document.createElement("div").innerHTML = html // create and populate a node to load linked resources, too.
Expand Down Expand Up @@ -81,6 +83,10 @@ htmx.defineExtension("preload", {

// Get event name from config.
var on = attr(node, "preload") || "mousedown"
const always = on.indexOf("always") !== -1
if (always) {
on = on.replace('always', '').trim()
}

// FALL THROUGH to here means we need to add an EventListener

Expand Down Expand Up @@ -121,6 +127,7 @@ htmx.defineExtension("preload", {

// Mark the node as ready to run.
node.preloadState = "PAUSE";
node.preloadAlways = always;
htmx.trigger(node, "preload:init") // This event can be used to load content immediately.
}

Expand Down
Loading

0 comments on commit 15790c2

Please sign in to comment.