Skip to content

Commit

Permalink
Restore hx-history-preserve attribute, that can be used by any elem…
Browse files Browse the repository at this point in the history
…ent swapped by htmx
  • Loading branch information
croxton committed Dec 7, 2023
1 parent 16a7bc8 commit 1e5ed11
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A core tenet of htmx is to inline implementation details, so that the behaviour
1. Include `booster.min.js` in the `<head>` of your page, right after `htmx`:
```html
<script defer src="https://cdn.jsdelivr.net/gh/bigskysoftware/htmx@1.9.9/src/htmx.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/gh/croxton/htmx-booster-pack@1.0.8/dist/booster.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/gh/croxton/htmx-booster-pack@1.0.9/dist/booster.min.js"></script>
```

2. Create a folder in the webroot of your project to store your scripts, e.g. `/scripts/boosts/`. Add a `<meta>` tag and set the `basePath` of your folder:
Expand Down
2 changes: 1 addition & 1 deletion dist/booster-pack.min.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class BoosterExt {
next: {}
};
function saveToCache(dom, store) {
let markers = dom.querySelectorAll("[data-" + extension + ']:not([data-reset="false"])');
let markers = dom.querySelectorAll("[data-" + extension + '], [hx-history-preserve]:not([data-reset="false"])');
if (markers)
for (let i = 0; i < markers.length; ++i)
typeof markers[i].id < "u" && (cache[store][markers[i].id] = markers[i].outerHTML);
Expand Down
2 changes: 1 addition & 1 deletion dist/booster.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BoosterExt {
next: {}
};
function saveToCache(dom, store) {
let markers = dom.querySelectorAll("[data-" + extension + ']:not([data-reset="false"])');
let markers = dom.querySelectorAll("[data-" + extension + '], [hx-history-preserve]:not([data-reset="false"])');
if (markers)
for (let i = 0; i < markers.length; ++i)
typeof markers[i].id < "u" && (cache[store][markers[i].id] = markers[i].outerHTML);
Expand Down
3 changes: 2 additions & 1 deletion lib/boosterExt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default class BoosterExt {
};

function saveToCache(dom, store) {
let markers = dom.querySelectorAll('[data-'+extension+']' + ':not([data-reset="false"])');
// support [hx-history-preserve] as well as booster components
let markers = dom.querySelectorAll('[data-'+extension+'], [hx-history-preserve]' + ':not([data-reset="false"])');
if (markers) {
for (let i = 0; i < markers.length; ++i) {
if (typeof markers[i].id !== 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "htmx-booster-pack",
"version": "1.0.8",
"version": "1.0.9",
"description": "Minimal component framework for htmx",
"type": "module",
"exports": {
Expand Down

0 comments on commit 1e5ed11

Please sign in to comment.