| 1 |
/** |
| 2 |
* King Addons Custom Cursor Preview Handler |
| 3 |
* Handles custom cursor initialization in Elementor preview/editor. |
| 4 |
*/ |
| 5 |
(() => { |
| 6 |
'use strict'; |
| 7 |
|
| 8 |
/** |
| 9 |
* Initialize or reinitialize the cursor for preview mode. |
| 10 |
*/ |
| 11 |
const initCursor = () => { |
| 12 |
const api = window.KingAddonsCustomCursor; |
| 13 |
const data = window.KingAddonsCustomCursorData; |
| 14 |
|
| 15 |
if (!api || !data) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// Force reinitialize in preview mode |
| 20 |
if (data.isPreview) { |
| 21 |
api.reinit(data); |
| 22 |
} else { |
| 23 |
api.init(data); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
/** |
| 28 |
* Boot function to initialize on Elementor events. |
| 29 |
*/ |
| 30 |
const boot = () => { |
| 31 |
// Small delay to ensure Elementor has fully loaded |
| 32 |
setTimeout(initCursor, 100); |
| 33 |
}; |
| 34 |
|
| 35 |
// Listen for Elementor frontend events |
| 36 |
if (window.elementorFrontend && typeof window.elementorFrontend.on === 'function') { |
| 37 |
window.elementorFrontend.on('components:init', boot); |
| 38 |
window.elementorFrontend.on('frontend:initialized', boot); |
| 39 |
} |
| 40 |
|
| 41 |
// Also listen for DOMContentLoaded as fallback |
| 42 |
if (document.readyState === 'loading') { |
| 43 |
document.addEventListener('DOMContentLoaded', boot, { once: true }); |
| 44 |
} else { |
| 45 |
boot(); |
| 46 |
} |
| 47 |
|
| 48 |
// Listen for Elementor preview reload |
| 49 |
if (window.elementor) { |
| 50 |
window.elementor.on('preview:loaded', boot); |
| 51 |
} |
| 52 |
})(); |
| 53 |
|