| @@ -2,14 +2,11 @@ | ||
| 2 | 2 | namespace Elementor\Core\Page_Assets; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module; |
| 5 | 5 | use Elementor\Plugin; |
| 6 | -use Elementor\Control_Animation; | |
| 7 | -use Elementor\Control_Exit_Animation; | |
| 8 | -use Elementor\Control_Hover_Animation; | |
| 9 | 6 | |
| 10 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly. | |
| 8 | + exit; // Exit if accessed directly | |
| 12 | 9 | } |
| 13 | 10 | |
| 14 | 11 | /** |
| 15 | 12 | * Elementor assets loader. |
| @@ -18,81 +15,28 @@ | ||
| 18 | 15 | * |
| 19 | 16 | * @since 3.3.0 |
| 20 | 17 | */ |
| 21 | 18 | class Loader extends Module { |
| 22 | - private array $assets = []; | |
| 19 | + private $assets; | |
| 23 | 20 | |
| 24 | - public function get_name(): string { | |
| 21 | + public function get_name() { | |
| 25 | 22 | return 'assets-loader'; |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | - private function init_assets(): void { | |
| 29 | - $assets = [ | |
| 30 | - 'styles' => $this->init_styles(), | |
| 25 | + private function init_assets() { | |
| 26 | + $this->assets = [ | |
| 27 | + 'styles' => [ | |
| 28 | + 'e-animations' => [ | |
| 29 | + 'src' => $this->get_css_assets_url( 'animations', 'assets/lib/animations/', true ), | |
| 30 | + 'version' => ELEMENTOR_VERSION, | |
| 31 | + 'dependencies' => [], | |
| 32 | + ], | |
| 33 | + ], | |
| 31 | 34 | 'scripts' => [], |
| 32 | 35 | ]; |
| 33 | - | |
| 34 | - $this->assets = $assets; | |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | - private function init_styles(): array { | |
| 38 | - $styles = [ | |
| 39 | - 'e-shapes' => [ | |
| 40 | - 'src' => $this->get_css_assets_url( 'shapes', 'assets/css/conditionals/' ), | |
| 41 | - 'version' => ELEMENTOR_VERSION, | |
| 42 | - 'dependencies' => [], | |
| 43 | - ], | |
| 44 | - 'e-swiper' => [ | |
| 45 | - 'src' => $this->get_css_assets_url( 'e-swiper', 'assets/css/conditionals/' ), | |
| 46 | - 'version' => ELEMENTOR_VERSION, | |
| 47 | - 'dependencies' => [ 'swiper' ], | |
| 48 | - ], | |
| 49 | - 'swiper' => [ | |
| 50 | - 'src' => $this->get_css_assets_url( 'swiper', 'assets/lib/swiper/v8/css/' ), | |
| 51 | - 'version' => '8.4.5', | |
| 52 | - 'dependencies' => [], | |
| 53 | - ], | |
| 54 | - ]; | |
| 55 | - | |
| 56 | - return array_merge( $styles, $this->get_animation_styles() ); | |
| 57 | - } | |
| 58 | - | |
| 59 | - private function get_animations(): array { | |
| 60 | - $grouped_animations = Control_Animation::get_default_animations(); | |
| 61 | - $grouped_animations['hover'] = Control_Hover_Animation::get_default_animations(); | |
| 62 | - $exit_animations = Control_Exit_Animation::get_default_animations(); | |
| 63 | - | |
| 64 | - $grouped_animations = array_merge( $grouped_animations, $exit_animations ); | |
| 65 | - | |
| 66 | - $animations = []; | |
| 67 | - | |
| 68 | - foreach ( $grouped_animations as $group_label => $group ) { | |
| 69 | - foreach ( $group as $animation_key => $animation_label ) { | |
| 70 | - $animations[ $animation_key ] = $group_label; | |
| 71 | - } | |
| 72 | - } | |
| 73 | - | |
| 74 | - return $animations; | |
| 75 | - } | |
| 76 | - | |
| 77 | - private function get_animation_styles(): array { | |
| 78 | - $animations = $this->get_animations(); | |
| 79 | - $styles = []; | |
| 80 | - | |
| 81 | - foreach ( $animations as $animation => $group_label ) { | |
| 82 | - $style_prefix = 'hover' === $group_label ? 'e-animation-' : ''; | |
| 83 | - | |
| 84 | - $styles[ 'e-animation-' . $animation ] = [ | |
| 85 | - 'src' => $this->get_css_assets_url( $style_prefix . $animation, 'assets/lib/animations/styles/' ), | |
| 86 | - 'version' => ELEMENTOR_VERSION, | |
| 87 | - 'dependencies' => [], | |
| 88 | - ]; | |
| 89 | - } | |
| 90 | - | |
| 91 | - return $styles; | |
| 92 | - } | |
| 93 | - | |
| 94 | - public function get_assets(): array { | |
| 38 | + public function get_assets() { | |
| 95 | 39 | if ( ! $this->assets ) { |
| 96 | 40 | $this->init_assets(); |
| 97 | 41 | } |
| 98 | 42 | |
| @@ -99,14 +43,14 @@ | ||
| 99 | 43 | return $this->assets; |
| 100 | 44 | } |
| 101 | 45 | |
| 102 | 46 | /** |
| 103 | - * @param array $assets_data { | |
| 47 | + * @param array $assets { | |
| 104 | 48 | * @type array 'styles' |
| 105 | 49 | * @type array 'scripts' |
| 106 | 50 | * } |
| 107 | 51 | */ |
| 108 | - public function enable_assets( array $assets_data ): void { | |
| 52 | + public function enable_assets( array $assets_data ) { | |
| 109 | 53 | if ( ! $this->assets ) { |
| 110 | 54 | $this->init_assets(); |
| 111 | 55 | } |
| 112 | 56 | |
| @@ -112,14 +56,8 @@ | ||
| 112 | 56 | |
| 113 | 57 | foreach ( $assets_data as $assets_type => $assets_list ) { |
| 114 | 58 | foreach ( $assets_list as $asset_name ) { |
| 115 | 59 | $this->assets[ $assets_type ][ $asset_name ]['enabled'] = true; |
| 116 | - | |
| 117 | - if ( 'scripts' === $assets_type ) { | |
| 118 | - wp_enqueue_script( $asset_name ); | |
| 119 | - } else { | |
| 120 | - wp_enqueue_style( $asset_name ); | |
| 121 | - } | |
| 122 | 60 | } |
| 123 | 61 | } |
| 124 | 62 | } |
| 125 | 63 | |
| @@ -128,9 +66,9 @@ | ||
| 128 | 66 | * @type array 'styles' |
| 129 | 67 | * @type array 'scripts' |
| 130 | 68 | * } |
| 131 | 69 | */ |
| 132 | - public function add_assets( array $assets ): void { | |
| 70 | + public function add_assets( array $assets ) { | |
| 133 | 71 | if ( ! $this->assets ) { |
| 134 | 72 | $this->init_assets(); |
| 135 | 73 | } |
| 136 | 74 | |
| @@ -136,22 +74,16 @@ | ||
| 136 | 74 | |
| 137 | 75 | $this->assets = array_replace_recursive( $this->assets, $assets ); |
| 138 | 76 | } |
| 139 | 77 | |
| 140 | - /** | |
| 141 | - * @deprecated 3.22.0 | |
| 142 | - */ | |
| 143 | - public function enqueue_assets(): void { | |
| 78 | + public function enqueue_assets() { | |
| 144 | 79 | $assets = $this->get_assets(); |
| 145 | 80 | $is_preview_mode = Plugin::$instance->preview->is_preview_mode(); |
| 81 | + $is_optimized_assets_loading = Plugin::$instance->experiments->is_feature_active( 'e_optimized_assets_loading' ); | |
| 146 | 82 | |
| 147 | 83 | foreach ( $assets as $assets_type => $assets_type_data ) { |
| 148 | 84 | foreach ( $assets_type_data as $asset_name => $asset_data ) { |
| 149 | - if ( empty( $asset_data['src'] ) ) { | |
| 150 | - continue; | |
| 151 | - } | |
| 152 | - | |
| 153 | - if ( ! empty( $asset_data['enabled'] ) || $is_preview_mode ) { | |
| 85 | + if ( ! empty( $asset_data['enabled'] ) || $is_preview_mode || ! $is_optimized_assets_loading ) { | |
| 154 | 86 | if ( 'scripts' === $assets_type ) { |
| 155 | 87 | wp_enqueue_script( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'], true ); |
| 156 | 88 | } else { |
| 157 | 89 | wp_enqueue_style( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'] ); |
| @@ -160,9 +92,9 @@ | ||
| 160 | 92 | } |
| 161 | 93 | } |
| 162 | 94 | } |
| 163 | 95 | |
| 164 | - private function register_assets(): void { | |
| 96 | + private function register_assets() { | |
| 165 | 97 | $assets = $this->get_assets(); |
| 166 | 98 | |
| 167 | 99 | foreach ( $assets as $assets_type => $assets_type_data ) { |
| 168 | 100 | foreach ( $assets_type_data as $asset_name => $asset_data ) { |