Skip to content

Commit

Permalink
Merge pull request #810 from AlejandroSuero/feature/fix-video-playing…
Browse files Browse the repository at this point in the history
…-error

fix(#809): boxers video clips quotes playing when going back after closing it
  • Loading branch information
midudev authored May 17, 2024
2 parents 95876ba + 96948ad commit 5026e5c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/components/ClipsModal.astro
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,27 @@
const $clipContainer = $$(".clip-container")
const $clipDialog = $(".clip-dialog") as HTMLDialogElement
const $closeButton = $(".close-dialog")
const $ytFrame = $(".yt-iframe")
let $ytFrame = $(".yt-iframe")
const ytFrameCopy = $ytFrame

if (!$clipDialog) return

$clipDialog.addEventListener("close", () => {
$ytFrame?.setAttribute("src", "")
if ($ytFrame !== null) {
$ytFrame.setAttribute("src", "")
} else {
ytFrameCopy?.setAttribute("src", "")
}
})

$closeButton?.addEventListener("click", () => $clipDialog.close())
$closeButton?.addEventListener("click", () => {
$clipDialog.close()
if ($ytFrame !== null) {
$ytFrame.remove()
} else {
ytFrameCopy?.remove()
}
})

$clipDialog.addEventListener("click", (event) => {
const target = event.target as HTMLElement
Expand All @@ -83,7 +95,15 @@
const currentTarget = event.currentTarget as HTMLElement
const { url } = currentTarget.dataset
if (!url) return
$ytFrame?.setAttribute("src", `${url}&autoplay=1`)
$ytFrame = $(".yt-iframe") as HTMLIFrameElement
if ($ytFrame !== null) {
$ytFrame.setAttribute("src", `${url}&autoplay=1`)
} else {
if (ytFrameCopy) {
$clipDialog?.querySelector("div")?.prepend(ytFrameCopy)
ytFrameCopy.setAttribute("src", `${url}&autoplay=1`)
}
}
$clipDialog.showModal()
})
})
Expand Down

0 comments on commit 5026e5c

Please sign in to comment.