This commit is contained in:
2026-07-11 15:39:10 +00:00
parent e50ae8fa1c
commit 7fd56a3e0d
2 changed files with 48 additions and 85 deletions

View File

@@ -4,42 +4,17 @@ import { useLocation } from 'react-router-dom'
export default function useLayoutInit() {
const { pathname } = useLocation()
// Re-initialize theme JS on route change
useEffect(() => {
let destroyed = false
let rafId = null
function tryInit() {
if (destroyed) return
// Apply data-bg-src to elements
document.querySelectorAll('[data-bg-src]').forEach(el => {
const src = el.getAttribute('data-bg-src')
if (src && !el.classList.contains('background-image')) {
el.style.backgroundImage = `url(${src})`
el.classList.add('background-image')
}
})
// Check if jQuery and theme init function are ready
if (typeof window.jQuery === 'function' && typeof window.rakar_content_load_scripts === 'function') {
try {
// Destroy ALL existing swiper instances to prevent duplicates
document.querySelectorAll('.swiper').forEach(el => {
if (el.swiper) {
try { el.swiper.destroy(true, true) } catch (e) { console.warn('useLayoutInit: swiper destroy failed:', e) }
}
})
// Run theme initialization
window.rakar_content_load_scripts()
window.__layoutReady = true
window.dispatchEvent(new Event('layout-ready'))
return true
} catch (e) {
console.warn('Theme init error:', e)
}
if (destroyed) return false
if (typeof window.rakar_content_load_scripts === 'function') {
window.rakar_content_load_scripts()
window.__layoutReady = true
window.dispatchEvent(new Event('layout-ready'))
return true
}
return false
}