Skip to content

Commit 3ee379c

Browse files
committed
update event doco and rename to historyElt to be consistent
1 parent 3d04f5d commit 3ee379c

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/htmx.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,7 +3248,7 @@ var htmx = (function() {
32483248
function loadHistoryFromServer(path) {
32493249
const request = new XMLHttpRequest()
32503250
const swapSpec = { swapStyle: 'innerHTML', swapDelay: 0, settleDelay: 0 }
3251-
const details = { path, xhr: request, historyElement: getHistoryElement(), swapSpec }
3251+
const details = { path, xhr: request, historyElt: getHistoryElement(), swapSpec }
32523252
request.open('GET', path, true)
32533253
request.setRequestHeader('HX-Request', 'true')
32543254
request.setRequestHeader('HX-History-Restore-Request', 'true')
@@ -3257,8 +3257,8 @@ var htmx = (function() {
32573257
if (this.status >= 200 && this.status < 400) {
32583258
details.response = this.response
32593259
triggerEvent(getDocument().body, 'htmx:historyCacheMissLoad', details)
3260-
swap(details.historyElement, details.response, swapSpec, {
3261-
contextElement: details.historyElement,
3260+
swap(details.historyElt, details.response, swapSpec, {
3261+
contextElement: details.historyElt,
32623262
historyRequest: true
32633263
})
32643264
currentPathForHistory = details.path
@@ -3281,10 +3281,10 @@ var htmx = (function() {
32813281
const cached = getCachedHistory(path)
32823282
if (cached) {
32833283
const swapSpec = { swapStyle: 'innerHTML', swapDelay: 0, settleDelay: 0, scroll: cached.scroll }
3284-
const details = { path, item: cached, historyElement: getHistoryElement(), swapSpec }
3284+
const details = { path, item: cached, historyElt: getHistoryElement(), swapSpec }
32853285
if (triggerEvent(getDocument().body, 'htmx:historyCacheHit', details)) {
3286-
swap(details.historyElement, cached.content, swapSpec, {
3287-
contextElement: details.historyElement,
3286+
swap(details.historyElt, cached.content, swapSpec, {
3287+
contextElement: details.historyElt,
32883288
title: cached.title
32893289
})
32903290
currentPathForHistory = details.path

test/core/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ describe('Core htmx Events', function() {
772772
it('htmx:historyCacheMissLoad event can update history swap', function() {
773773
localStorage.removeItem(HTMX_HISTORY_CACHE_NAME)
774774
var handler = htmx.on('htmx:historyCacheMissLoad', function(evt) {
775-
evt.detail.historyElement = byId('hist-re-target')
775+
evt.detail.historyElt = byId('hist-re-target')
776776
evt.detail.swapSpec.swapStyle = 'outerHTML'
777777
evt.detail.response = '<div id="hist-re-target">Updated<div>'
778778
evt.detail.path = '/test3'
@@ -855,7 +855,7 @@ describe('Core htmx Events', function() {
855855
it('htmx:historyCacheHit event can update history swap', function() {
856856
localStorage.removeItem(HTMX_HISTORY_CACHE_NAME)
857857
var handler = htmx.on('htmx:historyCacheHit', function(evt) {
858-
evt.detail.historyElement = byId('hist-re-target')
858+
evt.detail.historyElt = byId('hist-re-target')
859859
evt.detail.swapSpec.swapStyle = 'outerHTML'
860860
evt.detail.item.content = '<div id="hist-re-target">Updated<div>'
861861
evt.detail.path = '/test3'

www/content/events.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ You can also override the details of the history restoration request in this eve
262262

263263
##### Details
264264

265-
* `detail.historyElement` - the history element or body that will get replaced
265+
* `detail.historyElt` - the history element or body that will get replaced
266266
* `detail.item.content` - the content of the cache that will be swapped in
267267
* `detail.item.title` - the page title to update from the cache
268268
* `detail.path` - the path and query of the page being restored
@@ -277,7 +277,7 @@ You can also modify the xhr request or other details before it makes the the req
277277

278278
##### Details
279279

280-
* `detail.historyElement` - the history element or body that will get replaced
280+
* `detail.historyElt` - the history element or body that will get replaced
281281
* `detail.xhr` - the `XMLHttpRequest` that will retrieve the remote content for restoration
282282
* `detail.path` - the path and query of the page being restored
283283
* `detial.swapSpec` - the swapSpec to be used containing the defatul swapStyle='innerHTML'
@@ -301,7 +301,7 @@ You can modify the details before it makes the swap to restore the history
301301

302302
##### Details
303303

304-
* `detail.historyElement` - the history element or body that will get replaced
304+
* `detail.historyElt` - the history element or body that will get replaced
305305
* `detail.xhr` - the `XMLHttpRequest`
306306
* `detail.path` - the path and query of the page being restored
307307
* `detail.response` - the response text that will be swapped in
@@ -320,12 +320,14 @@ This event is triggered when htmx handles a history restoration action
320320

321321
### Event - `htmx:beforeHistorySave` {#htmx:beforeHistorySave}
322322

323-
This event is triggered before the content is saved in the history api.
323+
This event is triggered before the content is saved in the history cache.
324+
325+
You can modify the contents of the historyElt to remove 3rd party javascript changes so a clean copy of the content can be backed up to the history cache
324326

325327
##### Details
326328

327-
* `detail.path` - the path and query of the page being restored
328-
* `detail.historyElt` - the history element being restored into
329+
* `detail.path` - the path and query of the page being saved
330+
* `detail.historyElt` - the history element about to be saved
329331

330332
##### Details
331333

0 commit comments

Comments
 (0)