PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.4
Elementor Website Builder – more than just a page builder v3.26.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / page-assets / loader.php

loader.php in Elementor Website Builder – more than just a page builder 3.26.4, at core/page-assets/loader.php

192 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Page_Assets;
3
4 use Elementor\Core\Base\Module;
5 use Elementor\Plugin;
6 use Elementor\Control_Animation;
7 use Elementor\Control_Exit_Animation;
8 use Elementor\Control_Hover_Animation;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly
12 }
13
14 /**
15 * Elementor assets loader.
16 *
17 * A class that is responsible for conditionally enqueuing styles and script assets that were pre-enabled.
18 *
19 * @since 3.3.0
20 */
21 class Loader extends Module {
22 private array $assets = [];
23
24 public function get_name(): string {
25 return 'assets-loader';
26 }
27
28 private function init_assets(): void {
29 $assets = [
30 'styles' => $this->init_styles(),
31 'scripts' => [],
32 ];
33
34 $this->assets = $assets;
35 }
36
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', $this->getSwiperPath() ),
51 'version' => $this->getSwiperVersion(),
52 'dependencies' => [],
53 ],
54 ];
55
56 return array_merge( $styles, $this->get_animation_styles() );
57 }
58
59 private function getSwiperPath(): string {
60 return 'assets/lib/swiper/v8/css/';
61 }
62
63 private function getSwiperVersion(): string {
64 return '8.4.5';
65 }
66
67 private function get_animations(): array {
68 $grouped_animations = Control_Animation::get_default_animations();
69 $grouped_animations['hover'] = Control_Hover_Animation::get_default_animations();
70 $exit_animations = Control_Exit_Animation::get_default_animations();
71
72 $grouped_animations = array_merge( $grouped_animations, $exit_animations );
73
74 $animations = [];
75
76 foreach ( $grouped_animations as $group_label => $group ) {
77 foreach ( $group as $animation_key => $animation_label ) {
78 $animations[ $animation_key ] = $group_label;
79 }
80 }
81
82 return $animations;
83 }
84
85 private function get_animation_styles(): array {
86 $animations = $this->get_animations();
87 $styles = [];
88
89 foreach ( $animations as $animation => $group_label ) {
90 $style_prefix = 'hover' === $group_label ? 'e-animation-' : '';
91
92 $styles[ 'e-animation-' . $animation ] = [
93 'src' => $this->get_css_assets_url( $style_prefix . $animation, 'assets/lib/animations/styles/' ),
94 'version' => ELEMENTOR_VERSION,
95 'dependencies' => [],
96 ];
97 }
98
99 return $styles;
100 }
101
102 public function get_assets(): array {
103 if ( ! $this->assets ) {
104 $this->init_assets();
105 }
106
107 return $this->assets;
108 }
109
110 /**
111 * @param array $assets {
112 * @type array 'styles'
113 * @type array 'scripts'
114 * }
115 */
116 public function enable_assets( array $assets_data ): void {
117 if ( ! $this->assets ) {
118 $this->init_assets();
119 }
120
121 foreach ( $assets_data as $assets_type => $assets_list ) {
122 foreach ( $assets_list as $asset_name ) {
123 $this->assets[ $assets_type ][ $asset_name ]['enabled'] = true;
124
125 if ( 'scripts' === $assets_type ) {
126 wp_enqueue_script( $asset_name );
127 } else {
128 wp_enqueue_style( $asset_name );
129 }
130 }
131 }
132 }
133
134 /**
135 * @param array $assets {
136 * @type array 'styles'
137 * @type array 'scripts'
138 * }
139 */
140 public function add_assets( array $assets ): void {
141 if ( ! $this->assets ) {
142 $this->init_assets();
143 }
144
145 $this->assets = array_replace_recursive( $this->assets, $assets );
146 }
147
148 /**
149 * @deprecated 3.22.0
150 */
151 public function enqueue_assets(): void {
152 $assets = $this->get_assets();
153 $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
154
155 foreach ( $assets as $assets_type => $assets_type_data ) {
156 foreach ( $assets_type_data as $asset_name => $asset_data ) {
157 if ( empty( $asset_data['src'] ) ) {
158 continue;
159 }
160
161 if ( ! empty( $asset_data['enabled'] ) || $is_preview_mode ) {
162 if ( 'scripts' === $assets_type ) {
163 wp_enqueue_script( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'], true );
164 } else {
165 wp_enqueue_style( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'] );
166 }
167 }
168 }
169 }
170 }
171
172 private function register_assets(): void {
173 $assets = $this->get_assets();
174
175 foreach ( $assets as $assets_type => $assets_type_data ) {
176 foreach ( $assets_type_data as $asset_name => $asset_data ) {
177 if ( 'scripts' === $assets_type ) {
178 wp_register_script( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'], true );
179 } else {
180 wp_register_style( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'] );
181 }
182 }
183 }
184 }
185
186 public function __construct() {
187 parent::__construct();
188
189 $this->register_assets();
190 }
191 }
192