| @@ -15,15 +15,8 @@ | ||
| 15 | 15 | class Module extends BaseModule { |
| 16 | 16 | const MODULE_NAME = 'e-interactions'; |
| 17 | 17 | const EXPERIMENT_NAME = 'e_interactions'; |
| 18 | 18 | |
| 19 | - const HANDLE_MOTION_JS = 'motion-js'; | |
| 20 | - const HANDLE_SHARED_UTILS = 'elementor-interactions-shared-utils'; | |
| 21 | - const HANDLE_FRONTEND = 'elementor-interactions'; | |
| 22 | - const HANDLE_EDITOR = 'elementor-editor-interactions'; | |
| 23 | - const JS_CONFIG_OBJECT = 'ElementorInteractionsConfig'; | |
| 24 | - const SCRIPT_ID_INTERACTIONS_DATA = 'elementor-interactions-data'; | |
| 25 | - | |
| 26 | 19 | public function get_name() { |
| 27 | 20 | return self::MODULE_NAME; |
| 28 | 21 | } |
| 29 | 22 | |
| @@ -28,10 +21,8 @@ | ||
| 28 | 21 | } |
| 29 | 22 | |
| 30 | 23 | private $preset_animations; |
| 31 | 24 | |
| 32 | - private $frontend_handler; | |
| 33 | - | |
| 34 | 25 | private function get_presets() { |
| 35 | 26 | if ( ! $this->preset_animations ) { |
| 36 | 27 | $this->preset_animations = new Presets(); |
| 37 | 28 | } |
| @@ -38,16 +29,8 @@ | ||
| 38 | 29 | |
| 39 | 30 | return $this->preset_animations; |
| 40 | 31 | } |
| 41 | 32 | |
| 42 | - private function get_frontend_handler() { | |
| 43 | - if ( ! $this->frontend_handler ) { | |
| 44 | - $this->frontend_handler = new Interactions_Frontend_Handler( fn () => $this->get_config() ); | |
| 45 | - } | |
| 46 | - | |
| 47 | - return $this->frontend_handler; | |
| 48 | - } | |
| 49 | - | |
| 50 | 33 | public static function get_experimental_data() { |
| 51 | 34 | return [ |
| 52 | 35 | 'name' => self::EXPERIMENT_NAME, |
| 53 | 36 | 'title' => esc_html__( 'Interactions', 'elementor' ), |
| @@ -71,17 +54,12 @@ | ||
| 71 | 54 | } |
| 72 | 55 | |
| 73 | 56 | add_action( 'elementor/frontend/after_register_scripts', fn () => $this->register_frontend_scripts() ); |
| 74 | 57 | add_action( 'elementor/editor/before_enqueue_scripts', fn () => $this->enqueue_editor_scripts() ); |
| 58 | + add_action( 'elementor/frontend/before_enqueue_scripts', fn () => $this->enqueue_interactions() ); | |
| 75 | 59 | add_action( 'elementor/preview/enqueue_scripts', fn () => $this->enqueue_preview_scripts() ); |
| 76 | 60 | add_action( 'elementor/editor/after_enqueue_scripts', fn () => $this->enqueue_editor_scripts() ); |
| 77 | 61 | |
| 78 | - // Collect interactions from documents before they render (header, footer, post content) | |
| 79 | - add_filter( 'elementor/frontend/builder_content_data', [ $this->get_frontend_handler(), 'collect_document_interactions' ], 10, 2 ); | |
| 80 | - | |
| 81 | - // Output centralized interaction data in footer | |
| 82 | - add_action( 'wp_footer', [ $this->get_frontend_handler(), 'print_interactions_data' ], 1 ); | |
| 83 | - | |
| 84 | 62 | add_filter( 'elementor/document/save/data', |
| 85 | 63 | /** |
| 86 | 64 | * @throws \Exception |
| 87 | 65 | */ |
| @@ -98,33 +76,20 @@ | ||
| 98 | 76 | return ( new Parser( $document->get_main_id() ) )->assign_interaction_ids( $data ); |
| 99 | 77 | }, 11, 2 ); |
| 100 | 78 | } |
| 101 | 79 | |
| 102 | - public function get_config() { | |
| 80 | + private function get_config() { | |
| 103 | 81 | return [ |
| 104 | 82 | 'constants' => $this->get_presets()->defaults(), |
| 105 | - 'breakpoints' => $this->get_active_breakpoints(), | |
| 83 | + 'animationOptions' => $this->get_presets()->list(), | |
| 106 | 84 | ]; |
| 107 | 85 | } |
| 108 | 86 | |
| 109 | - private function get_active_breakpoints() { | |
| 110 | - $breakpoints_config = Plugin::$instance->breakpoints->get_breakpoints_config(); | |
| 111 | - $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); | |
| 112 | - | |
| 113 | - $breakpoints = []; | |
| 114 | - | |
| 115 | - foreach ( array_keys( $active_breakpoints ) as $breakpoint_label ) { | |
| 116 | - $breakpoints[ $breakpoint_label ] = $breakpoints_config[ $breakpoint_label ]; | |
| 117 | - } | |
| 118 | - | |
| 119 | - return $breakpoints; | |
| 120 | - } | |
| 121 | - | |
| 122 | 87 | private function register_frontend_scripts() { |
| 123 | 88 | $suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min'; |
| 124 | 89 | |
| 125 | 90 | wp_register_script( |
| 126 | - self::HANDLE_MOTION_JS, | |
| 91 | + 'motion-js', | |
| 127 | 92 | ELEMENTOR_ASSETS_URL . 'lib/motion/motion' . $suffix . '.js', |
| 128 | 93 | [], |
| 129 | 94 | '11.13.5', |
| 130 | 95 | true |
| @@ -130,29 +95,32 @@ | ||
| 130 | 95 | true |
| 131 | 96 | ); |
| 132 | 97 | |
| 133 | 98 | wp_register_script( |
| 134 | - self::HANDLE_SHARED_UTILS, | |
| 135 | - $this->get_js_assets_url( 'interactions-shared-utils' ), | |
| 136 | - [ self::HANDLE_MOTION_JS ], | |
| 99 | + 'elementor-interactions', | |
| 100 | + $this->get_js_assets_url( 'interactions' ), | |
| 101 | + [ 'motion-js' ], | |
| 137 | 102 | '1.0.0', |
| 138 | 103 | true |
| 139 | 104 | ); |
| 140 | 105 | |
| 141 | 106 | wp_register_script( |
| 142 | - self::HANDLE_FRONTEND, | |
| 143 | - $this->get_js_assets_url( 'interactions' ), | |
| 144 | - [ self::HANDLE_MOTION_JS, self::HANDLE_SHARED_UTILS ], | |
| 107 | + 'elementor-editor-interactions', | |
| 108 | + $this->get_js_assets_url( 'editor-interactions' ), | |
| 109 | + [ 'motion-js' ], | |
| 145 | 110 | '1.0.0', |
| 146 | 111 | true |
| 147 | 112 | ); |
| 113 | + } | |
| 148 | 114 | |
| 149 | - wp_register_script( | |
| 150 | - self::HANDLE_EDITOR, | |
| 151 | - $this->get_js_assets_url( 'editor-interactions' ), | |
| 152 | - [ self::HANDLE_MOTION_JS, self::HANDLE_SHARED_UTILS ], | |
| 153 | - '1.0.0', | |
| 154 | - true | |
| 115 | + public function enqueue_interactions(): void { | |
| 116 | + wp_enqueue_script( 'motion-js' ); | |
| 117 | + wp_enqueue_script( 'elementor-interactions' ); | |
| 118 | + | |
| 119 | + wp_localize_script( | |
| 120 | + 'elementor-interactions', | |
| 121 | + 'ElementorInteractionsConfig', | |
| 122 | + $this->get_config() | |
| 155 | 123 | ); |
| 156 | 124 | } |
| 157 | 125 | |
| 158 | 126 | public function enqueue_editor_scripts() { |
| @@ -157,22 +125,21 @@ | ||
| 157 | 125 | |
| 158 | 126 | public function enqueue_editor_scripts() { |
| 159 | 127 | wp_add_inline_script( |
| 160 | 128 | 'elementor-common', |
| 161 | - 'window.' . self::JS_CONFIG_OBJECT . ' = ' . wp_json_encode( $this->get_config() ) . ';', | |
| 129 | + 'window.ElementorInteractionsConfig = ' . wp_json_encode( $this->get_config() ) . ';', | |
| 162 | 130 | 'before' |
| 163 | 131 | ); |
| 164 | 132 | } |
| 165 | 133 | |
| 166 | 134 | public function enqueue_preview_scripts() { |
| 167 | - wp_enqueue_script( self::HANDLE_SHARED_UTILS ); | |
| 168 | 135 | // Ensure motion-js and editor-interactions handler are available in preview iframe |
| 169 | - wp_enqueue_script( self::HANDLE_MOTION_JS ); | |
| 170 | - wp_enqueue_script( self::HANDLE_EDITOR ); | |
| 136 | + wp_enqueue_script( 'motion-js' ); | |
| 137 | + wp_enqueue_script( 'elementor-editor-interactions' ); | |
| 171 | 138 | |
| 172 | 139 | wp_localize_script( |
| 173 | - self::HANDLE_EDITOR, | |
| 174 | - self::JS_CONFIG_OBJECT, | |
| 140 | + 'elementor-editor-interactions', | |
| 141 | + 'ElementorInteractionsConfig', | |
| 175 | 142 | $this->get_config() |
| 176 | 143 | ); |
| 177 | 144 | } |
| 178 | 145 | } |