| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateCursor\Extension; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Group_Control_Typography; |
| 7 |
use Elementor\Group_Control_Background; |
| 8 |
use Elementor\Group_Control_Border; |
| 9 |
use Elementor\Utils; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || die(); |
| 12 |
|
| 13 |
class Extend_Cursor { |
| 14 |
/** |
| 15 |
* The single class instance. |
| 16 |
* |
| 17 |
* @var $instance |
| 18 |
*/ |
| 19 |
private static $instance = null; |
| 20 |
|
| 21 |
/** |
| 22 |
* Get instance |
| 23 |
*/ |
| 24 |
public static function instance() { |
| 25 |
if ( is_null( self::$instance ) ) { |
| 26 |
self::$instance = new self(); |
| 27 |
} |
| 28 |
return self::$instance; |
| 29 |
} |
| 30 |
|
| 31 |
static $should_script_enqueue = false; |
| 32 |
|
| 33 |
private function __construct() { |
| 34 |
// Check for required Elementor version first — the hooks below |
| 35 |
// enqueue/render Elementor-specific integration and must not |
| 36 |
// register at all on an incompatible version (previously this |
| 37 |
// check ran after registering them, so the version gate was |
| 38 |
// decorative: notice-only, hooks fired regardless). |
| 39 |
if ( ! version_compare( ELEMENTOR_VERSION, ultimate_cursor()->minimum_elementor_version, '>=' ) ) { |
| 40 |
add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) ); |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
// The Elementor per-widget cursor controls are a legacy system, superseded |
| 45 |
// by the main Ultimate Cursor dashboard. New installs no longer see the |
| 46 |
// editor controls (soft-deprecation), but widgets that already have a saved |
| 47 |
// cursor still render on the frontend. Sites that want the editor controls |
| 48 |
// back can re-enable them: |
| 49 |
// add_filter('ultimate_cursor_enable_elementor_controls', '__return_true'); |
| 50 |
if ( apply_filters( 'ultimate_cursor_enable_elementor_controls', false ) ) { |
| 51 |
add_action( 'elementor/element/common/_section_style/after_section_end', array( $this, 'add_controls_section' ), 1 ); |
| 52 |
} |
| 53 |
add_action( 'elementor/frontend/widget/before_render', array( $this, 'should_script_enqueue' ) ); |
| 54 |
add_action( 'elementor/preview/enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 55 |
} |
| 56 |
public function enqueue_scripts() { |
| 57 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 58 |
wp_enqueue_script( 'ultimate-cursor-cotton', ultimate_cursor()->plugin_url . 'assets/js/cotton' . $suffix . '.js', array(), '5.3.5', true ); |
| 59 |
wp_enqueue_style( 'uce-cursor-css', ultimate_cursor()->plugin_url . 'assets/css/ultimate-cursor.css', null, UCA_VERSION ); |
| 60 |
wp_enqueue_script( 'uce-cursor-js', ultimate_cursor()->plugin_url . 'assets/js/ultimate-cursor.js', array( 'jquery' ), UCA_VERSION, true ); |
| 61 |
} |
| 62 |
public function should_script_enqueue( $element ) { |
| 63 |
if ( self::$should_script_enqueue ) { |
| 64 |
return; |
| 65 |
} |
| 66 |
if ( 'yes' === $element->get_settings_for_display( 'ultimate_cursor_show' ) ) { |
| 67 |
self::$should_script_enqueue = true; |
| 68 |
$this->enqueue_scripts(); |
| 69 |
self::enqueue_scripts(); |
| 70 |
remove_action( 'elementor/frontend/widget/before_render', array( $this, 'should_script_enqueue' ) ); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
public function add_controls_section( $element ) { |
| 75 |
|
| 76 |
$element->start_controls_section( |
| 77 |
'section_ultimate_cursor', |
| 78 |
array( |
| 79 |
'label' => __( 'Ultimate Cursor', 'ultimate-cursor' ), |
| 80 |
'tab' => Controls_Manager::TAB_ADVANCED, |
| 81 |
) |
| 82 |
); |
| 83 |
|
| 84 |
$element->add_control( |
| 85 |
'ultimate_cursor_show', |
| 86 |
array( |
| 87 |
'label' => __( 'Enable Cursors?', 'ultimate-cursor' ), |
| 88 |
'type' => Controls_Manager::SWITCHER, |
| 89 |
'return_value' => 'yes', |
| 90 |
'prefix_class' => 'uce-cursor-enabled-', |
| 91 |
'frontend_available' => true, |
| 92 |
'render_type' => 'template', |
| 93 |
) |
| 94 |
); |
| 95 |
$element->start_controls_tabs( |
| 96 |
'ultimate_cursor_tabs' |
| 97 |
); |
| 98 |
|
| 99 |
$element->start_controls_tab( |
| 100 |
'ultimate_cursor_tab_layout', |
| 101 |
array( |
| 102 |
'label' => esc_html__( 'Layout', 'ultimate-cursor' ), |
| 103 |
'condition' => array( |
| 104 |
'ultimate_cursor_show' => 'yes', |
| 105 |
), |
| 106 |
) |
| 107 |
); |
| 108 |
$element->add_control( |
| 109 |
'ultimate_cursor_source', |
| 110 |
array( |
| 111 |
'label' => esc_html__( 'Cursor Type', 'ultimate-cursor' ), |
| 112 |
'type' => Controls_Manager::SELECT, |
| 113 |
'default' => 'default', |
| 114 |
'frontend_available' => true, |
| 115 |
'render_type' => 'template', |
| 116 |
'options' => array( |
| 117 |
'default' => esc_html__( 'Default', 'ultimate-cursor' ), |
| 118 |
'text' => esc_html__( 'Text', 'ultimate-cursor' ), |
| 119 |
'image' => esc_html__( 'Image', 'ultimate-cursor' ), |
| 120 |
'icons' => esc_html__( 'Icons', 'ultimate-cursor' ), |
| 121 |
), |
| 122 |
'condition' => array( |
| 123 |
'ultimate_cursor_show' => 'yes', |
| 124 |
), |
| 125 |
) |
| 126 |
); |
| 127 |
$element->add_control( |
| 128 |
'ultimate_cursor_image_src', |
| 129 |
array( |
| 130 |
'label' => esc_html__( 'Image', 'ultimate-cursor' ), |
| 131 |
'type' => Controls_Manager::MEDIA, |
| 132 |
'frontend_available' => true, |
| 133 |
'render_type' => 'template', |
| 134 |
'default' => array( |
| 135 |
'url' => Utils::get_placeholder_image_src(), |
| 136 |
), |
| 137 |
'condition' => array( |
| 138 |
'ultimate_cursor_source' => 'image', |
| 139 |
), |
| 140 |
) |
| 141 |
); |
| 142 |
$element->add_control( |
| 143 |
'ultimate_cursor_icons', |
| 144 |
array( |
| 145 |
'label' => esc_html__( 'Icons', 'ultimate-cursor' ), |
| 146 |
'type' => Controls_Manager::ICONS, |
| 147 |
'frontend_available' => true, |
| 148 |
'render_type' => 'template', |
| 149 |
'condition' => array( |
| 150 |
'ultimate_cursor_source' => 'icons', |
| 151 |
), |
| 152 |
'default' => array( |
| 153 |
'value' => 'fas fa-laugh-wink', |
| 154 |
'library' => 'fa-solid', |
| 155 |
), |
| 156 |
) |
| 157 |
); |
| 158 |
$element->add_control( |
| 159 |
'ultimate_cursor_style', |
| 160 |
array( |
| 161 |
'label' => __( 'Style', 'ultimate-cursor' ), |
| 162 |
'type' => Controls_Manager::SELECT, |
| 163 |
'default' => 'ep-cursor-style-1', |
| 164 |
'options' => array( |
| 165 |
'ep-cursor-style-1' => __( 'Style 1', 'ultimate-cursor' ), |
| 166 |
'ep-cursor-style-2' => __( 'Style 2', 'ultimate-cursor' ), |
| 167 |
'ep-cursor-style-3' => __( 'Style 3', 'ultimate-cursor' ), |
| 168 |
), |
| 169 |
'frontend_available' => true, |
| 170 |
'render_type' => 'template', |
| 171 |
'condition' => array( |
| 172 |
'ultimate_cursor_show' => 'yes', |
| 173 |
'ultimate_cursor_source' => 'default', |
| 174 |
), |
| 175 |
) |
| 176 |
); |
| 177 |
$element->add_control( |
| 178 |
'ultimate_cursor_text_label', |
| 179 |
array( |
| 180 |
'label' => esc_html__( 'Text Label', 'ultimate-cursor' ), |
| 181 |
'type' => Controls_Manager::TEXT, |
| 182 |
'default' => esc_html__( 'Ultimate Cursor', 'ultimate-cursor' ), |
| 183 |
'selectors' => array( |
| 184 |
'{{WRAPPE}}.uce-cursor-enabled-yes' => '--cursor-text-label:"{{VALUE}}"', |
| 185 |
), |
| 186 |
'frontend_available' => true, |
| 187 |
'render_type' => 'template', |
| 188 |
'condition' => array( |
| 189 |
'ultimate_cursor_source' => 'text', |
| 190 |
), |
| 191 |
) |
| 192 |
); |
| 193 |
$element->add_control( |
| 194 |
'ultimate_cursor_speed', |
| 195 |
array( |
| 196 |
'label' => __( 'Speed', 'ultimate-cursor' ), |
| 197 |
'type' => Controls_Manager::SLIDER, |
| 198 |
'size_units' => array( 'px' ), |
| 199 |
'range' => array( |
| 200 |
'px' => array( |
| 201 |
'min' => 0, |
| 202 |
'max' => 1, |
| 203 |
'step' => 0.001, |
| 204 |
), |
| 205 |
), |
| 206 |
'default' => array( |
| 207 |
'unit' => 'px', |
| 208 |
'size' => 0.075, |
| 209 |
), |
| 210 |
'frontend_available' => true, |
| 211 |
'render_type' => 'none', |
| 212 |
'condition' => array( |
| 213 |
'ultimate_cursor_show' => 'yes', |
| 214 |
'ultimate_cursor_source' => 'default', |
| 215 |
), |
| 216 |
|
| 217 |
) |
| 218 |
); |
| 219 |
$element->add_control( |
| 220 |
'ultimate_cursor_disable_default_cursor', |
| 221 |
array( |
| 222 |
'label' => __( 'Disable Default Cursor', 'ultimate-cursor' ), |
| 223 |
'type' => Controls_Manager::SWITCHER, |
| 224 |
'return_value' => 'yes', |
| 225 |
'separator' => 'before', |
| 226 |
'condition' => array( |
| 227 |
'ultimate_cursor_show' => 'yes', |
| 228 |
), |
| 229 |
'selectors' => array( |
| 230 |
'{{WRAPPER}}.uce-cursor-enabled-yes' => 'cursor: none', |
| 231 |
), |
| 232 |
) |
| 233 |
); |
| 234 |
$element->end_controls_tab(); |
| 235 |
$element->start_controls_tab( |
| 236 |
'ultimate_cursor_tab_style', |
| 237 |
array( |
| 238 |
'label' => esc_html__( 'Style', 'ultimate-cursor' ), |
| 239 |
'condition' => array( |
| 240 |
'ultimate_cursor_show' => 'yes', |
| 241 |
), |
| 242 |
) |
| 243 |
); |
| 244 |
$element->add_control( |
| 245 |
'ultimate_cursor_primary', |
| 246 |
array( |
| 247 |
'label' => esc_html__( 'Primary', 'ultimate-cursor' ), |
| 248 |
'type' => Controls_Manager::HEADING, |
| 249 |
'separator' => 'before', |
| 250 |
'condition' => array( |
| 251 |
'ultimate_cursor_source' => 'default', |
| 252 |
), |
| 253 |
) |
| 254 |
); |
| 255 |
$element->add_control( |
| 256 |
'ultimate_cursor_primary_color', |
| 257 |
array( |
| 258 |
'label' => esc_html__( 'Color', 'ultimate-cursor' ), |
| 259 |
'type' => Controls_Manager::COLOR, |
| 260 |
'selectors' => array( |
| 261 |
'{{WRAPPER}}.uce-cursor-enabled-yes' => '--cursor-ball-color: {{VALUE}}', |
| 262 |
), |
| 263 |
'condition' => array( |
| 264 |
'ultimate_cursor_source' => array( 'default', 'icons' ), |
| 265 |
), |
| 266 |
) |
| 267 |
); |
| 268 |
$element->add_responsive_control( |
| 269 |
'ultimate_cursor_primary_size', |
| 270 |
array( |
| 271 |
'label' => esc_html__( 'Size', 'ultimate-cursor' ), |
| 272 |
'type' => Controls_Manager::SLIDER, |
| 273 |
'selectors' => array( |
| 274 |
'{{WRAPPER}}.uce-cursor-enabled-yes' => '--cursor-ball-size:{{SIZE}}{{UNIT}};', |
| 275 |
), |
| 276 |
'condition' => array( |
| 277 |
'ultimate_cursor_source' => 'default', |
| 278 |
), |
| 279 |
) |
| 280 |
); |
| 281 |
$element->add_control( |
| 282 |
'ultimate_cursor_secondary', |
| 283 |
array( |
| 284 |
'label' => esc_html__( 'Secondary', 'ultimate-cursor' ), |
| 285 |
'type' => Controls_Manager::HEADING, |
| 286 |
'separator' => 'before', |
| 287 |
'condition' => array( |
| 288 |
'ultimate_cursor_source' => 'default', |
| 289 |
), |
| 290 |
) |
| 291 |
); |
| 292 |
$element->add_control( |
| 293 |
'ultimate_cursor_secondary_color', |
| 294 |
array( |
| 295 |
'label' => esc_html__( 'Color', 'ultimate-cursor' ), |
| 296 |
'type' => Controls_Manager::COLOR, |
| 297 |
'selectors' => array( |
| 298 |
'{{WRAPPER}}.uce-cursor-enabled-yes' => '--cursor-circle-color: {{VALUE}}', |
| 299 |
), |
| 300 |
'condition' => array( |
| 301 |
'ultimate_cursor_source' => 'default', |
| 302 |
), |
| 303 |
) |
| 304 |
); |
| 305 |
$element->add_responsive_control( |
| 306 |
'ultimate_cursor_secondary_size', |
| 307 |
array( |
| 308 |
'label' => esc_html__( 'Size', 'ultimate-cursor' ), |
| 309 |
'type' => Controls_Manager::SLIDER, |
| 310 |
'selectors' => array( |
| 311 |
'{{WRAPPER}}.uce-cursor-enabled-yes' => '--cursor-circle-size:{{SIZE}}{{UNIT}};', |
| 312 |
), |
| 313 |
'condition' => array( |
| 314 |
'ultimate_cursor_source' => 'default', |
| 315 |
), |
| 316 |
) |
| 317 |
); |
| 318 |
// TEXT |
| 319 |
$element->add_control( |
| 320 |
'ultimate_cursor_text_color', |
| 321 |
array( |
| 322 |
'label' => esc_html__( 'Color', 'ultimate-cursor' ), |
| 323 |
'type' => Controls_Manager::COLOR, |
| 324 |
'selectors' => array( |
| 325 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text' => 'color: {{VALUE}}', |
| 326 |
), |
| 327 |
'condition' => array( |
| 328 |
'ultimate_cursor_source' => 'text', |
| 329 |
), |
| 330 |
) |
| 331 |
); |
| 332 |
$element->add_group_control( |
| 333 |
Group_Control_Background::get_type(), |
| 334 |
array( |
| 335 |
'name' => 'ultimate_cursor_text_background', |
| 336 |
'label' => esc_html__( 'Background', 'ultimate-cursor' ), |
| 337 |
'types' => array( 'classic', 'gradient' ), |
| 338 |
'selector' => '{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text', |
| 339 |
'condition' => array( |
| 340 |
'ultimate_cursor_source' => 'text', |
| 341 |
), |
| 342 |
) |
| 343 |
); |
| 344 |
$element->add_responsive_control( |
| 345 |
'ultimate_cursor_text_padding', |
| 346 |
array( |
| 347 |
'label' => esc_html__( 'Padding', 'ultimate-cursor' ), |
| 348 |
'type' => Controls_Manager::DIMENSIONS, |
| 349 |
'size_units' => array( 'px', '%', 'em' ), |
| 350 |
'selectors' => array( |
| 351 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 352 |
), |
| 353 |
'condition' => array( |
| 354 |
'ultimate_cursor_source' => 'text', |
| 355 |
), |
| 356 |
) |
| 357 |
); |
| 358 |
$element->add_group_control( |
| 359 |
Group_Control_Border::get_type(), |
| 360 |
array( |
| 361 |
'name' => 'ultimate_cursor_text_border', |
| 362 |
'label' => esc_html__( 'Border', 'ultimate-cursor' ), |
| 363 |
'selector' => '{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text', |
| 364 |
'condition' => array( |
| 365 |
'ultimate_cursor_source' => 'text', |
| 366 |
), |
| 367 |
) |
| 368 |
); |
| 369 |
$element->add_responsive_control( |
| 370 |
'ultimate_cursor_text_radius', |
| 371 |
array( |
| 372 |
'label' => esc_html__( 'Border Radius', 'ultimate-cursor' ), |
| 373 |
'type' => Controls_Manager::DIMENSIONS, |
| 374 |
'size_units' => array( 'px', '%', 'em' ), |
| 375 |
'selectors' => array( |
| 376 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 377 |
), |
| 378 |
'condition' => array( |
| 379 |
'ultimate_cursor_source' => 'text', |
| 380 |
), |
| 381 |
) |
| 382 |
); |
| 383 |
$element->add_group_control( |
| 384 |
Group_Control_Typography::get_type(), |
| 385 |
array( |
| 386 |
'name' => 'ultimate_cursor_text_typography', |
| 387 |
'label' => esc_html__( 'Typography', 'ultimate-cursor' ), |
| 388 |
'selector' => '{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-text', |
| 389 |
'condition' => array( |
| 390 |
'ultimate_cursor_source' => 'text', |
| 391 |
), |
| 392 |
) |
| 393 |
); |
| 394 |
$element->add_responsive_control( |
| 395 |
'ultimate_cursor_image_size', |
| 396 |
array( |
| 397 |
'label' => esc_html__( 'Size', 'ultimate-cursor' ), |
| 398 |
'type' => Controls_Manager::SLIDER, |
| 399 |
'selectors' => array( |
| 400 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-image' => 'width:{{SIZE}}{{UNIT}}; height:{{SIZE}}{{UNIT}};', |
| 401 |
), |
| 402 |
'condition' => array( |
| 403 |
'ultimate_cursor_source' => 'image', |
| 404 |
), |
| 405 |
) |
| 406 |
); |
| 407 |
$element->add_group_control( |
| 408 |
Group_Control_Border::get_type(), |
| 409 |
array( |
| 410 |
'name' => 'ultimate_cursor_image_border', |
| 411 |
'label' => esc_html__( 'Border', 'ultimate-cursor' ), |
| 412 |
'selector' => '{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-image', |
| 413 |
'condition' => array( |
| 414 |
'ultimate_cursor_source' => 'image', |
| 415 |
), |
| 416 |
) |
| 417 |
); |
| 418 |
$element->add_responsive_control( |
| 419 |
'ultimate_cursor_image_radius', |
| 420 |
array( |
| 421 |
'label' => esc_html__( 'Border Radius', 'ultimate-cursor' ), |
| 422 |
'type' => Controls_Manager::DIMENSIONS, |
| 423 |
'size_units' => array( 'px', '%', 'em' ), |
| 424 |
'selectors' => array( |
| 425 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 426 |
), |
| 427 |
'condition' => array( |
| 428 |
'ultimate_cursor_source' => 'image', |
| 429 |
), |
| 430 |
) |
| 431 |
); |
| 432 |
|
| 433 |
$element->add_responsive_control( |
| 434 |
'ultimate_cursor_icons_size', |
| 435 |
array( |
| 436 |
'label' => esc_html__( 'Size', 'ultimate-cursor' ), |
| 437 |
'type' => Controls_Manager::SLIDER, |
| 438 |
'selectors' => array( |
| 439 |
'{{WRAPPER}}.uce-cursor-enabled-yes .bdt-cursor-icons' => 'font-size:{{SIZE}}{{UNIT}};', |
| 440 |
), |
| 441 |
'condition' => array( |
| 442 |
'ultimate_cursor_source' => 'icons', |
| 443 |
), |
| 444 |
) |
| 445 |
); |
| 446 |
$element->end_controls_tab(); |
| 447 |
|
| 448 |
$element->end_controls_tabs(); |
| 449 |
$element->end_controls_section(); |
| 450 |
} |
| 451 |
} |
| 452 |
Extend_Cursor::instance(); |
| 453 |
|