| 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/components/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 that extend current scripts |
| 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 |
// TODO: update swiper version when loop bug is fixed (last checked on 11.2.6) |
| 93 |
'ui-e-swiper' => [ |
| 94 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/swiper.js', |
| 95 |
'version' => '11.2.1-ui', |
| 96 |
'in_footer' => true |
| 97 |
], |
| 98 |
'ui-e-special-effects' => [ |
| 99 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/special-effects.js', |
| 100 |
'version' => UICORE_ELEMENTS_VERSION, |
| 101 |
'in_footer' => true |
| 102 |
], |
| 103 |
'ui-e-circular-avatar-carousel' => [ |
| 104 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/circular_avatar.js', |
| 105 |
'version' => UICORE_ELEMENTS_VERSION, |
| 106 |
'in_footer' => true |
| 107 |
], |
| 108 |
'ui-e-stacked-carousel' => [ |
| 109 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/lib/carousel-effects/stacked.js', |
| 110 |
'version' => UICORE_ELEMENTS_VERSION, |
| 111 |
'in_footer' => true |
| 112 |
], |
| 113 |
|
| 114 |
// Utils and non-compiled assets |
| 115 |
'ui-e-recaptcha' => [ |
| 116 |
'src' => 'https://www.google.com/recaptcha/api.js?render=explicit', |
| 117 |
'version' => UICORE_ELEMENTS_VERSION, |
| 118 |
'in_footer' => false |
| 119 |
], |
| 120 |
'ui-e-recaptcha-v3' => [ |
| 121 |
'src' => 'https://www.google.com/recaptcha/api.js?render=' . get_option('uicore_elements_recaptcha_site_key'), |
| 122 |
'version' => UICORE_ELEMENTS_VERSION, |
| 123 |
'in_footer' => false |
| 124 |
], |
| 125 |
|
| 126 |
// Components compiled for enqueue |
| 127 |
'ui-e-entrance' => [ |
| 128 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-entrances.js', |
| 129 |
'version' => UICORE_ELEMENTS_VERSION, |
| 130 |
'in_footer' => true |
| 131 |
], |
| 132 |
'ui-e-masonry' => [ |
| 133 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-masonry.js', |
| 134 |
'version' => UICORE_ELEMENTS_VERSION, |
| 135 |
'in_footer' => true |
| 136 |
], |
| 137 |
'ui-e-ajax-request' => [ |
| 138 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/ajax-request.js', |
| 139 |
'version' => UICORE_ELEMENTS_VERSION, |
| 140 |
'in_footer' => true |
| 141 |
], |
| 142 |
'ui-e-counter' => [ |
| 143 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-counter.js', |
| 144 |
'version' => UICORE_ELEMENTS_VERSION, |
| 145 |
'deps' => ['ui-e-countup'], |
| 146 |
'in_footer' => true |
| 147 |
], |
| 148 |
'ui-e-carousel' => [ |
| 149 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-carousel.js', |
| 150 |
'version' => UICORE_ELEMENTS_VERSION, |
| 151 |
'deps' => ['ui-e-swiper'], |
| 152 |
'in_footer' => true |
| 153 |
], |
| 154 |
'ui-e-repeater-custom-key' => [ |
| 155 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/repeater-custom-key.js', |
| 156 |
'version' => UICORE_ELEMENTS_VERSION, |
| 157 |
'in_footer' => true |
| 158 |
], |
| 159 |
'ui-e-testimonial' => [ |
| 160 |
'src' => UICORE_ELEMENTS_ASSETS . '/js/components/global-testimonial.js', |
| 161 |
'version' => UICORE_ELEMENTS_VERSION, |
| 162 |
'in_footer' => true |
| 163 |
] |
| 164 |
]; |
| 165 |
|
| 166 |
return $scripts; |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Get registered styles |
| 171 |
* |
| 172 |
* @return array |
| 173 |
*/ |
| 174 |
public function get_styles() { |
| 175 |
|
| 176 |
// Singular files widgets may enqueue |
| 177 |
$styles = [ |
| 178 |
// Animation related |
| 179 |
'ui-e-animation' => [ |
| 180 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/global-animations.css' |
| 181 |
], |
| 182 |
'ui-e-entrance' => [ |
| 183 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/global-entrances.css' |
| 184 |
], |
| 185 |
|
| 186 |
// Layout related |
| 187 |
'ui-e-grid' => [ |
| 188 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/grid.css' |
| 189 |
], |
| 190 |
'ui-e-legacy-grid' =>[ |
| 191 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/legacy-grid.css' |
| 192 |
], |
| 193 |
'ui-e-carousel' => [ |
| 194 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/carousel.css', |
| 195 |
'deps' => ['swiper', 'e-swiper'], |
| 196 |
], |
| 197 |
|
| 198 |
// Specifics |
| 199 |
'ui-e-post-meta' => [ |
| 200 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/meta.css' |
| 201 |
], |
| 202 |
'ui-e-filters' => [ |
| 203 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/filters.css' |
| 204 |
], |
| 205 |
'ui-e-counter-motion' => [ |
| 206 |
'src' => UICORE_ELEMENTS_ASSETS . '/css/components/counter-motion.css' |
| 207 |
] |
| 208 |
]; |
| 209 |
|
| 210 |
return $styles; |
| 211 |
} |
| 212 |
|
| 213 |
} |
| 214 |
|