elementor
/
modules
/
atomic-widgets
/
elements
/
atomic-background-video
/
handlers
/
editor-background-video-state.js
editor-background-video-state.js in Elementor Website Builder – more than just a page builder trunk, at modules/atomic-widgets/elements/atomic-background-video/handlers/editor-background-video-state.js
| 1 | import { Alpine } from '@elementor/alpinejs'; |
| 2 | |
| 3 | const STORE_NAME = 'editor-background-video-state'; |
| 4 | const PLAYING_STATE = 'playing'; |
| 5 | const PAUSED_STATE = 'paused'; |
| 6 | |
| 7 | /** |
| 8 | * @typedef {Record<string, 'playing' | 'paused' | ''>} BackgroundVideoState |
| 9 | */ |
| 10 | |
| 11 | function ensureStore() { |
| 12 | if ( ! Alpine.store( STORE_NAME ) ) { |
| 13 | Alpine.store( STORE_NAME, /** @type {BackgroundVideoState} */ ( {} ) ); |
| 14 | } |
| 15 | |
| 16 | return /** @type {BackgroundVideoState} */ ( Alpine.store( STORE_NAME ) ); |
| 17 | } |
| 18 | |
| 19 | export function resolveDesignTimeState( state ) { |
| 20 | if ( PAUSED_STATE === state || '' === state ) { |
| 21 | return state; |
| 22 | } |
| 23 | |
| 24 | return PLAYING_STATE; |
| 25 | } |
| 26 | |
| 27 | export function getEditorState( elementId, fallback = PLAYING_STATE ) { |
| 28 | const store = ensureStore(); |
| 29 | |
| 30 | return store[ elementId ] ?? fallback; |
| 31 | } |
| 32 | |
| 33 | export function setEditorState( elementId, state ) { |
| 34 | const store = ensureStore(); |
| 35 | |
| 36 | store[ elementId ] = state; |
| 37 | } |
| 38 | |
| 39 | export function isEditorPreview() { |
| 40 | return Boolean( window.elementorFrontend?.isEditMode?.() || window.parent?.elementor ); |
| 41 | } |
| 42 |