mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
fix(iframe-drawer): correct URL location when opening in a new tab (#1068)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { useThrottleFn, useToggle } from '@vueuse/core'
|
||||
import { useEventListener, useThrottleFn, useToggle } from '@vueuse/core'
|
||||
import type { Ref } from 'vue'
|
||||
|
||||
import type { BewlyAppProvider } from '~/composables/useAppProvider'
|
||||
@@ -181,6 +181,21 @@ async function haveScrollbar() {
|
||||
return scrollHeight > window.innerHeight
|
||||
}
|
||||
|
||||
// When opening a video in drawer mode, listen for changes to the drawer's inner iframe url.
|
||||
// When the iframe's url changes, update the parent url to match the iframe's url.
|
||||
const beforeUrl = ref<string>(location.href.replace(/\/$/, ''))
|
||||
if (inIframe.value) {
|
||||
useEventListener(window, 'pushstate', handleIframeUrlChange)
|
||||
useEventListener(window, 'click', handleIframeUrlChange)
|
||||
|
||||
function handleIframeUrlChange() {
|
||||
if (beforeUrl.value.replace(/\/$/, '') !== parent.location.href.replace(/\/$/, '')) {
|
||||
parent.history.pushState(null, '', location.href.replace(/\/$/, ''))
|
||||
}
|
||||
beforeUrl.value = location.href.replace(/\/$/, '')
|
||||
}
|
||||
}
|
||||
|
||||
provide<BewlyAppProvider>('BEWLY_APP', {
|
||||
activatedPage,
|
||||
mainAppRef,
|
||||
|
||||
Reference in New Issue
Block a user