Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWest22 committed Sep 25, 2024
1 parent 4e92e28 commit a68cdad
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ var htmx = (function() {
* @returns
*/
function oobSwap(oobValue, oobElement, settleInfo) {
handlePreservedElements(oobElement)
let selector = '#' + getRawAttribute(oobElement, 'id')
/** @type HtmxSwapStyle */
let swapStyle = 'outerHTML'
Expand Down Expand Up @@ -1462,6 +1463,7 @@ var htmx = (function() {
oobElement.parentNode.removeChild(oobElement)
triggerErrorEvent(getDocument().body, 'htmx:oobErrorNoTarget', { content: oobElement })
}
restorePreservedElements()
return oobValue
}

Expand All @@ -1484,6 +1486,7 @@ var htmx = (function() {
function handlePreservedElements(fragment) {
forEach(findAll(fragment, '[hx-preserve], [data-hx-preserve]'), function(preservedElt) {
const id = getAttributeValue(preservedElt, 'id')
const value = getAttributeValue(preservedElt, 'hx-preserve')
const existingElement = getDocument().getElementById(id)
if (existingElement != null) {
if (preservedElt.moveBefore) { // if the moveBefore API exists, use it
Expand All @@ -1494,9 +1497,15 @@ var htmx = (function() {
pantry = find('#--htmx-preserve-pantry--')
}
// @ts-ignore - use proposed moveBefore feature
if (value != 'relocate') {
existingElement.insertAdjacentHTML('beforebegin', `<div id="${id}"></div>`)
}
pantry.moveBefore(existingElement, null)
} else {
preservedElt.parentNode.replaceChild(existingElement, preservedElt)
if (value == 'relocate') {
existingElement.remove()
}
}
}
})
Expand Down
23 changes: 23 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<script type="application/javascript" src="htmx.js"></script>
</head>
<body>
<main>
<button hx-get="video1.html"
hx-target="#video-container">
Load Video Layout 1
</button>
<button hx-get="video2.html"
hx-push-url="true"
hx-target="#video-container">
Load Video Layout 2
</button>
&dot;&dot;
<hr/>
<div id="video-container">
---
</div>
</main>
</body>
</html>
8 changes: 8 additions & 0 deletions docs/video1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>The Best Song On The Internet</h1>

<iframe id="rick-roll" width="600" height="300" hx-preserve="true"
src="https://www.youtube.com/embed/eBGIQ7ZuuiU" title="Rick Roll" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen>

</iframe>
38 changes: 38 additions & 0 deletions docs/video2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<h1>The Best Song On The Internet</h1>

<section id="summary">
<h2>The Song</h2>
<p>
"Never Gonna Give You Up" is a song by English singer Rick Astley, released on 27 July 1987. Written and
produced by Stock Aitken Waterman, it was released by RCA Records as the first single from Astley's debut studio
album, Whenever You Need Somebody (1987). The song became a worldwide hit, initially in the United Kingdom in
1987, where it stayed at the top of the chart for five weeks and was the best-selling single of that year. It
eventually topped charts in 25 different countries, including the United States and West Germany,[7] and winning
Best British Single at the 1988 Brit Awards. The song is widely regarded as Astley's most popular, as well as
his signature song, and it is often played at the end of his live concerts.
</p>
</section>

<section id="the-video">
<h2>The Video</h2>
<div style="margin: auto;text-align: center">
<iframe id="rick-roll" width="600" height="300" hx-preserve="true"
src="https://www.youtube.com/embed/eBGIQ7ZuuiU" title="Rick Roll" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen>

</iframe>
</div>
</section>

<section id="artist">
<h2>The Artist</h2>
<p>
Richard Paul Astley (born 6 February 1966) is an English singer. He gained fame through his association with the
production trio Stock Aitken Waterman, releasing the 1987 album Whenever You Need Somebody, which sold 15
million copies worldwide. His debut single "Never Gonna Give You Up" was a No. 1 hit in 25 countries, winning
the 1988 Brit Award for Best British Single.[1][2] His 1988 single "Together Forever" became his second song to
top the US Billboard Hot 100 and was one of his eight songs to reach the Top 10 on the UK Singles Chart. The
title track, "Whenever You Need Somebody", was also a No. 1 hit.
</p>
</section>

0 comments on commit a68cdad

Please sign in to comment.