Lets try that again

Experimental fix for https://github.com/bigskysoftware/htmx/issues/131
This commit is contained in:
carson 2020-07-04 15:46:25 -07:00
parent 947a4470de
commit aaae399308

View File

@ -1066,12 +1066,12 @@ return (function () {
var elt = getHistoryElement(); var elt = getHistoryElement();
var path = currentPathForHistory || location.pathname+location.search; var path = currentPathForHistory || location.pathname+location.search;
triggerEvent(getDocument().body, "htmx:beforeHistorySave", {path:path, historyElt:elt}); triggerEvent(getDocument().body, "htmx:beforeHistorySave", {path:path, historyElt:elt});
if(htmx.config.historyEnabled) history.replaceState({}, getDocument().title, window.location.href); if(htmx.config.historyEnabled) history.replaceState({htmx:true}, getDocument().title, window.location.href);
saveToHistoryCache(path, elt.innerHTML, getDocument().title, window.scrollY); saveToHistoryCache(path, elt.innerHTML, getDocument().title, window.scrollY);
} }
function pushUrlIntoHistory(path) { function pushUrlIntoHistory(path) {
if(htmx.config.historyEnabled) history.pushState({}, "", path); if(htmx.config.historyEnabled) history.pushState({htmx:true}, "", path);
currentPathForHistory = path; currentPathForHistory = path;
} }
@ -1703,8 +1703,10 @@ return (function () {
var body = getDocument().body; var body = getDocument().body;
processNode(body, true); processNode(body, true);
triggerEvent(body, 'htmx:load', {}); triggerEvent(body, 'htmx:load', {});
window.onpopstate = function () { window.onpopstate = function (event) {
restoreHistory(); if (event.state && event.state.htmx) {
restoreHistory();
}
}; };
}) })