| @@ -1,160 +1,255 @@ | ||
| 1 | -<?php | |
| 2 | -namespace UiCoreElements; | |
| 3 | -use Elementor\Plugin; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Scripts and Styles Class | |
| 7 | - */ | |
| 8 | -class Assets { | |
| 9 | - | |
| 10 | - function __construct() { | |
| 11 | - if ( is_admin() ) { | |
| 12 | - add_action( 'admin_enqueue_scripts', [ $this, 'register' ], 5 ); | |
| 13 | - add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue' ], 5 ); | |
| 14 | - } else { | |
| 15 | - add_action( 'wp_enqueue_scripts', [ $this, 'register' ], 5 ); | |
| 16 | - } | |
| 17 | - } | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * Register our app scripts and styles | |
| 21 | - * | |
| 22 | - * @return void | |
| 23 | - */ | |
| 24 | - public function register() { | |
| 25 | - $this->register_scripts( $this->get_scripts() ); | |
| 26 | - $this->register_styles( $this->get_styles() ); | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * Enqueue our app scripts directly in the Elementor editor | |
| 31 | - * | |
| 32 | - * @return void | |
| 33 | - */ | |
| 34 | - public function enqueue() { | |
| 35 | - if ( Plugin::instance()->editor->is_edit_mode() ) { | |
| 36 | - wp_enqueue_script('ui-nested-elements', UICORE_ELEMENTS_ASSETS . '/js/utils/nested-elements.js', [], UICORE_ELEMENTS_VERSION, true); | |
| 37 | - } | |
| 38 | - } | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Register scripts | |
| 42 | - * | |
| 43 | - * @param array $scripts | |
| 44 | - * | |
| 45 | - * @return void | |
| 46 | - */ | |
| 47 | - private function register_scripts( $scripts ) { | |
| 48 | - foreach ( $scripts as $handle => $script ) { | |
| 49 | - $deps = isset( $script['deps'] ) ? $script['deps'] : false; | |
| 50 | - $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false; | |
| 51 | - $version = isset( $script['version'] ) ? $script['version'] : UICORE_ELEMENTS_VERSION; | |
| 52 | - | |
| 53 | - wp_register_script( $handle, $script['src'], $deps, $version, $in_footer ); | |
| 54 | - } | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Register styles | |
| 59 | - * | |
| 60 | - * @param array $styles | |
| 61 | - * | |
| 62 | - * @return void | |
| 63 | - */ | |
| 64 | - public function register_styles( $styles ) { | |
| 65 | - foreach ( $styles as $handle => $style ) { | |
| 66 | - $deps = isset( $style['deps'] ) ? $style['deps'] : false; | |
| 67 | - | |
| 68 | - wp_register_style( $handle, $style['src'], $deps, UICORE_ELEMENTS_VERSION ); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Get all registered scripts | |
| 74 | - * | |
| 75 | - * @return array | |
| 76 | - */ | |
| 77 | - public function get_scripts() { | |
| 78 | - $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 79 | - | |
| 80 | - $scripts = [ | |
| 81 | - // libs | |
| 82 | - 'ui-e-countup' => [ | |
| 83 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/countUp.umd.js', | |
| 84 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 85 | - 'in_footer' => true | |
| 86 | - ], | |
| 87 | - 'ui-e-odometer' => [ | |
| 88 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/odometer.js', | |
| 89 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 90 | - 'in_footer' => true | |
| 91 | - ], | |
| 92 | - // utils | |
| 93 | - 'ui-e-entrance' => [ | |
| 94 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/global-entrances.js', | |
| 95 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 96 | - 'in_footer' => true | |
| 97 | - ], | |
| 98 | - 'ui-e-masonry' => [ | |
| 99 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/global-masonry.js', | |
| 100 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 101 | - 'in_footer' => true | |
| 102 | - ], | |
| 103 | - 'ui-e-ajax-request' => [ | |
| 104 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/ajax-request.js', | |
| 105 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 106 | - 'in_footer' => true | |
| 107 | - ], | |
| 108 | - 'ui-e-recaptcha' => [ | |
| 109 | - 'src' => 'https://www.google.com/recaptcha/api.js?render=explicit', | |
| 110 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 111 | - 'in_footer' => false | |
| 112 | - ], | |
| 113 | - 'ui-e-recaptcha-v3' => [ | |
| 114 | - 'src' => 'https://www.google.com/recaptcha/api.js?render=' . get_option('uicore_elements_recaptcha_site_key'), | |
| 115 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 116 | - 'in_footer' => false | |
| 117 | - ], | |
| 118 | - 'ui-e-repeater-custom-key' => [ | |
| 119 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/repeater-custom-key.js', | |
| 120 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 121 | - 'in_footer' => true | |
| 122 | - ], | |
| 123 | - // components | |
| 124 | - 'ui-e-counter' => [ | |
| 125 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/global-counter.js', | |
| 126 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 127 | - 'deps' => ['ui-e-countup'], | |
| 128 | - 'in_footer' => true | |
| 129 | - ], | |
| 130 | - 'ui-e-carousel' => [ | |
| 131 | - 'src' => UICORE_ELEMENTS_ASSETS . '/js/utils/global-carousel.js', | |
| 132 | - 'version' => UICORE_ELEMENTS_VERSION, | |
| 133 | - 'deps' => ['elementor-frontend'], | |
| 134 | - 'in_footer' => true | |
| 135 | - ], | |
| 136 | - ]; | |
| 137 | - | |
| 138 | - return $scripts; | |
| 139 | - } | |
| 140 | - | |
| 141 | - /** | |
| 142 | - * Get registered styles | |
| 143 | - * | |
| 144 | - * @return array | |
| 145 | - */ | |
| 146 | - public function get_styles() { | |
| 147 | - | |
| 148 | - $styles = [ | |
| 149 | - 'ui-e-animation' => [ | |
| 150 | - 'src' => UICORE_ELEMENTS_ASSETS . '/css/utils/global-animations.css' | |
| 151 | - ], | |
| 152 | - 'ui-e-entrance' => [ | |
| 153 | - 'src' => UICORE_ELEMENTS_ASSETS . '/css/utils/global-entrances.css' | |
| 154 | - ], | |
| 155 | - ]; | |
| 156 | - | |
| 157 | - return $styles; | |
| 158 | - } | |
| 159 | - | |
| 160 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UiCoreElements; | |
| 4 | + | |
| 5 | +use Elementor\Plugin; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Scripts and Styles Class | |
| 9 | + */ | |
| 10 | +class Assets | |
| 11 | +{ | |
| 12 | + | |
| 13 | + function __construct() | |
| 14 | + { | |
| 15 | + if (is_admin()) { | |
| 16 | + add_action('admin_enqueue_scripts', [$this, 'register'], 5); | |
| 17 | + add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue'], 5); | |
| 18 | + } else { | |
| 19 | + add_action('wp_enqueue_scripts', [$this, 'register'], 5); | |
| 20 | + } | |
| 21 | + } | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Register our app scripts and styles | |
| 25 | + * | |
| 26 | + * @return void | |
| 27 | + */ | |
| 28 | + public function register() | |
| 29 | + { | |
| 30 | + $this->register_scripts($this->get_scripts()); | |
| 31 | + $this->register_styles($this->get_styles()); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Enqueue our app scripts directly in the Elementor editor | |
| 36 | + * | |
| 37 | + * @return void | |
| 38 | + */ | |
| 39 | + public function enqueue() | |
| 40 | + { | |
| 41 | + if (Plugin::instance()->editor->is_edit_mode()) { | |
| 42 | + wp_enqueue_script('ui-nested-elements', UICORE_ELEMENTS_ASSETS . '/js/components/nested-elements.js', ['nested-elements', 'elementor-editor', 'elementor-common'], UICORE_ELEMENTS_VERSION, true); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Register scripts | |
| 48 | + * | |
| 49 | + * @param array $scripts | |
| 50 | + * | |
| 51 | + * @return void | |
| 52 | + */ | |
| 53 | + private function register_scripts($scripts) | |
| 54 | + { | |
| 55 | + foreach ($scripts as $handle => $script) { | |
| 56 | + $deps = isset($script['deps']) ? $script['deps'] : false; | |
| 57 | + $in_footer = isset($script['in_footer']) ? $script['in_footer'] : false; | |
| 58 | + $version = isset($script['version']) ? $script['version'] : UICORE_ELEMENTS_VERSION; | |
| 59 | + | |
| 60 | + wp_register_script($handle, $script['src'], $deps, $version, $in_footer); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Register styles | |
| 66 | + * | |
| 67 | + * @param array $styles | |
| 68 | + * | |
| 69 | + * @return void | |
| 70 | + */ | |
| 71 | + public function register_styles($styles) | |
| 72 | + { | |
| 73 | + foreach ($styles as $handle => $style) { | |
| 74 | + $deps = isset($style['deps']) ? $style['deps'] : false; | |
| 75 | + | |
| 76 | + wp_register_style($handle, $style['src'], $deps, UICORE_ELEMENTS_VERSION); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Get all registered scripts | |
| 82 | + * | |
| 83 | + * @return array | |
| 84 | + */ | |
| 85 | + public function get_scripts() | |
| 86 | + { | |
| 87 | + $prefix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; | |
| 88 | + | |
| 89 | + $scripts = [ | |
| 90 | + // Libs that extend current scripts | |
| 91 | + 'ui-e-countup' => [ | |
| 92 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/countUp.umd.js', | |
| 93 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 94 | + 'in_footer' => true | |
| 95 | + ], | |
| 96 | + 'ui-e-odometer' => [ | |
| 97 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/odometer.js', | |
| 98 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 99 | + 'in_footer' => true | |
| 100 | + ], | |
| 101 | + // TODO: update swiper version when loop bug is fixed (last checked on 11.2.6) | |
| 102 | + 'ui-e-swiper' => [ | |
| 103 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/swiper.js', | |
| 104 | + 'version' => '11.2.1-ui', | |
| 105 | + 'in_footer' => true | |
| 106 | + ], | |
| 107 | + 'ui-e-special-effects' => [ | |
| 108 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/special-effects.js', | |
| 109 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 110 | + 'in_footer' => true | |
| 111 | + ], | |
| 112 | + 'ui-e-circular-avatar-carousel' => [ | |
| 113 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/circular_avatar.js', | |
| 114 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 115 | + 'in_footer' => true | |
| 116 | + ], | |
| 117 | + 'ui-e-stacked-carousel' => [ | |
| 118 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/stacked.js', | |
| 119 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 120 | + 'in_footer' => true | |
| 121 | + ], | |
| 122 | + | |
| 123 | + // Utils and non-compiled assets | |
| 124 | + 'ui-e-recaptcha' => [ | |
| 125 | + 'src' => 'https://www.google.com/recaptcha/api.js?render=explicit', | |
| 126 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 127 | + 'in_footer' => false | |
| 128 | + ], | |
| 129 | + 'ui-e-recaptcha-v3' => [ | |
| 130 | + 'src' => 'https://www.google.com/recaptcha/api.js?render=' . get_option('uicore_elements_recaptcha_site_key'), | |
| 131 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 132 | + 'in_footer' => false | |
| 133 | + ], | |
| 134 | + | |
| 135 | + // Components compiled for enqueue | |
| 136 | + 'ui-e-entrance' => [ | |
| 137 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-entrances.js', | |
| 138 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 139 | + 'in_footer' => true | |
| 140 | + ], | |
| 141 | + 'ui-e-masonry' => [ | |
| 142 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-masonry.js', | |
| 143 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 144 | + 'in_footer' => true | |
| 145 | + ], | |
| 146 | + 'ui-e-ajax-request' => [ | |
| 147 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/ajax-request.js', | |
| 148 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 149 | + 'in_footer' => true | |
| 150 | + ], | |
| 151 | + 'ui-e-counter' => [ | |
| 152 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-counter.js', | |
| 153 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 154 | + 'deps' => ['ui-e-countup'], | |
| 155 | + 'in_footer' => true | |
| 156 | + ], | |
| 157 | + 'ui-e-carousel' => [ | |
| 158 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-carousel.js', | |
| 159 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 160 | + 'deps' => ['ui-e-swiper'], | |
| 161 | + 'in_footer' => true | |
| 162 | + ], | |
| 163 | + 'ui-e-repeater-custom-key' => [ | |
| 164 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/repeater-custom-key.js', | |
| 165 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 166 | + 'in_footer' => true | |
| 167 | + ], | |
| 168 | + 'ui-e-testimonial' => [ | |
| 169 | + 'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-testimonial.js', | |
| 170 | + 'version' => UICORE_ELEMENTS_VERSION, | |
| 171 | + 'in_footer' => true | |
| 172 | + ], | |
| 173 | + | |
| 174 | + ]; | |
| 175 | + | |
| 176 | + return $scripts; | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * Get registered styles | |
| 181 | + * | |
| 182 | + * @return array | |
| 183 | + */ | |
| 184 | + public function get_styles() | |
| 185 | + { | |
| 186 | + | |
| 187 | + // Singular files widgets may enqueue | |
| 188 | + $styles = [ | |
| 189 | + // Animation related | |
| 190 | + 'ui-e-animation' => [ | |
| 191 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/global-animations.css' | |
| 192 | + ], | |
| 193 | + 'ui-e-entrance' => [ | |
| 194 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/global-entrances.css' | |
| 195 | + ], | |
| 196 | + | |
| 197 | + // Layout related | |
| 198 | + 'ui-e-grid' => [ | |
| 199 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/grid.css' | |
| 200 | + ], | |
| 201 | + 'ui-e-legacy-grid' => [ | |
| 202 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/legacy-grid.css' | |
| 203 | + ], | |
| 204 | + 'ui-e-carousel' => [ | |
| 205 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/carousel.css', | |
| 206 | + 'deps' => ['swiper', 'e-swiper'], | |
| 207 | + ], | |
| 208 | + | |
| 209 | + // Specifics | |
| 210 | + 'ui-e-post-meta' => [ | |
| 211 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/meta.css' | |
| 212 | + ], | |
| 213 | + 'ui-e-filters' => [ | |
| 214 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/filters.css' | |
| 215 | + ], | |
| 216 | + 'ui-e-counter-motion' => [ | |
| 217 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/counter-motion.css' | |
| 218 | + ], | |
| 219 | + | |
| 220 | + // Advanced Menu | |
| 221 | + 'ui-e-advanced-menu-editor' => [ | |
| 222 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/editor.css' | |
| 223 | + ], | |
| 224 | + 'ui-e-advanced-menu-fullscreen-layout' => [ | |
| 225 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/fullscreen-layout.css' | |
| 226 | + ], | |
| 227 | + 'ui-e-advanced-menu-website-blur' => [ | |
| 228 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/website-blur.css' | |
| 229 | + ], | |
| 230 | + 'ui-e-advanced-menu-canvas-dropdown-expand' => [ | |
| 231 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/canvas-expand.css' | |
| 232 | + ], | |
| 233 | + 'ui-e-advanced-menu-canvas-dropdown-slide' => [ | |
| 234 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/canvas-slide.css' | |
| 235 | + ], | |
| 236 | + 'ui-e-advanced-menu-hover-underline' => [ | |
| 237 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/hover-underline.css' | |
| 238 | + ], | |
| 239 | + 'ui-e-advanced-menu-hover-button' => [ | |
| 240 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/hover-button.css' | |
| 241 | + ], | |
| 242 | + 'ui-e-advanced-menu-hover-magnet' => [ | |
| 243 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/hover-magnet.css' | |
| 244 | + ], | |
| 245 | + 'ui-e-advanced-menu-hover-focus' => [ | |
| 246 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/hover-focus.css' | |
| 247 | + ], | |
| 248 | + 'ui-e-advanced-menu-hover-text_flip' => [ | |
| 249 | + 'src' => UICORE_ELEMENTS_ASSETS . '/css/components/advanced-menu/hover-text-flip.css' | |
| 250 | + ], | |
| 251 | + ]; | |
| 252 | + | |
| 253 | + return $styles; | |
| 254 | + } | |
| 255 | +} | |