wpr-column-slider.php
5 days ago
wpr-custom-css.php
5 days ago
wpr-display-conditions.php
5 days ago
wpr-equal-height.php
5 days ago
wpr-extensions-base.php
5 days ago
wpr-parallax.php
5 days ago
wpr-particles.php
5 days ago
wpr-sticky-section.php
5 days ago
wpr-parallax.php
480 lines
| 1 | <?php |
| 2 | namespace WprAddons\Extensions; |
| 3 | |
| 4 | use Elementor\Controls_Manager; |
| 5 | use Elementor\Control_Media; |
| 6 | use Elementor\Controls_Stack; |
| 7 | use Elementor\Element_Base; |
| 8 | use Elementor\Repeater; |
| 9 | use Elementor\Utils; |
| 10 | use WprAddons\Classes\Utilities; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly. |
| 14 | } |
| 15 | |
| 16 | class Wpr_Parallax_Scroll extends \Wpr_Extensions_Base { |
| 17 | |
| 18 | public function __construct() { |
| 19 | add_action( 'elementor/element/section/section_background/after_section_end', [$this, 'register_controls'], 10); |
| 20 | add_action( 'elementor/frontend/section/before_render', [$this, '_before_render'], 10, 1); |
| 21 | add_action( 'elementor/section/print_template', [ $this, '_print_template' ], 10, 2 ); |
| 22 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 23 | |
| 24 | // FLEXBOX |
| 25 | add_action('elementor/element/container/section_layout/after_section_end', [$this, 'register_controls'], 10); |
| 26 | add_action('elementor/frontend/container/before_render', [$this, '_before_render'], 10, 1); |
| 27 | add_action( 'elementor/container/print_template', [ $this, '_print_template' ], 10, 2 ); |
| 28 | } |
| 29 | |
| 30 | public function register_controls( $element ) { |
| 31 | $element->start_controls_section( |
| 32 | 'wpr_section_parallax', |
| 33 | [ |
| 34 | 'tab' => Controls_Manager::TAB_STYLE, |
| 35 | 'label' => sprintf(esc_html__('Parallax - %s', 'wpr-addons'), esc_html('RA')), |
| 36 | ] |
| 37 | ); |
| 38 | |
| 39 | $element->add_control( |
| 40 | 'wpr_parallax', |
| 41 | [ |
| 42 | 'type' => Controls_Manager::RAW_HTML, |
| 43 | 'raw' => '<div class="elementor-update-preview-button editor-wpr-preview-update"><span>Update changes to Preview</span><button class="elementor-button elementor-button-success" onclick="elementor.reloadPreview();">Apply</button></div>', |
| 44 | 'separator' => 'after' |
| 45 | ] |
| 46 | ); |
| 47 | |
| 48 | if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 49 | |
| 50 | $element->add_control( |
| 51 | 'parallax_video_tutorial', |
| 52 | [ |
| 53 | 'raw' => '<br><a href="https://www.youtube.com/watch?v=DcDeQ__lJbw" target="_blank">Watch Video Tutorial <span class="dashicons dashicons-video-alt3"></span></a>', |
| 54 | 'type' => Controls_Manager::RAW_HTML, |
| 55 | ] |
| 56 | ); |
| 57 | |
| 58 | $element->add_control( |
| 59 | 'wpr_enable_jarallax', |
| 60 | [ |
| 61 | 'type' => Controls_Manager::SWITCHER, |
| 62 | 'label' => __('Enable Background Parallax', 'wpr-addons'), |
| 63 | 'default' => 'no', |
| 64 | 'label_on' => __('Yes', 'wpr-addons'), |
| 65 | 'label_off' => __('No', 'wpr-addons'), |
| 66 | 'return_value' => 'yes', |
| 67 | 'render_type' => 'template', |
| 68 | 'prefix_class' => 'wpr-jarallax-' |
| 69 | ] |
| 70 | ); |
| 71 | |
| 72 | // $element->add_control( |
| 73 | // 'parallax_item_bg_size', |
| 74 | // [ |
| 75 | // 'label' => esc_html__( 'Size', 'wpr-addons' ), |
| 76 | // 'type' => Controls_Manager::SELECT, |
| 77 | // 'default' => 'cover', |
| 78 | // 'options' => [ |
| 79 | // 'cover' => esc_html__( 'Cover', 'wpr-addons' ), |
| 80 | // 'contain' => esc_html__( 'Contain', 'wpr-addons' ), |
| 81 | // 'auto' => esc_html__( 'Auto', 'wpr-addons' ), |
| 82 | // ], |
| 83 | // 'selectors' => [ |
| 84 | // '{{WRAPPER}}.wpr-jarallax-yes' => 'position: relative; background-size: {{VALUE}}; background-repeat: no-repeat background-blend-mode: darken; background-position: left top;', |
| 85 | // '{{WRAPPER}} .wpr-jarallax' => 'position: relative; background-size: {{VALUE}}; background-repeat: no-repeat; background-blend-mode: darken; background-position: left top;', |
| 86 | // ], |
| 87 | // ] |
| 88 | // ); |
| 89 | |
| 90 | $element->add_control( |
| 91 | 'speed', |
| 92 | [ |
| 93 | 'label' => __( 'Animation Speed', 'wpr-addons' ), |
| 94 | 'type' => Controls_Manager::NUMBER, |
| 95 | 'min' => -1.0, |
| 96 | 'max' => 2.0, |
| 97 | 'step' => 0.1, |
| 98 | 'default' => 1.4, |
| 99 | 'render_type' => 'template', |
| 100 | 'condition' => [ |
| 101 | 'wpr_enable_jarallax' => 'yes' |
| 102 | ] |
| 103 | ] |
| 104 | ); |
| 105 | |
| 106 | if ( ! $this->maybe_call_pro_method( '\WprAddonsPro\Extensions\Wpr_Parallax_Scroll_Pro', 'add_control_scroll_effect', [ $element ] ) ) { |
| 107 | $element->add_control( |
| 108 | 'scroll_effect', |
| 109 | [ |
| 110 | 'label' => __( 'Scrolling Effect', 'wpr-addons' ), |
| 111 | 'type' => Controls_Manager::SELECT, |
| 112 | 'default' => 'scroll', |
| 113 | 'options' => [ |
| 114 | 'scroll' => esc_html__( 'Scroll', 'wpr-addons' ), |
| 115 | 'scale' => esc_html__( 'Zoom', 'wpr-addons' ), |
| 116 | 'pro-op' => esc_html__( 'Opacity (Pro)', 'wpr-addons' ), |
| 117 | 'pro-sclo' => esc_html__('Scale Opacity (Pro)', 'wpr-addons'), |
| 118 | 'pro-scrlo' => esc_html__( 'Scroll Opacity (Pro)', 'wpr-addons' ) |
| 119 | ], |
| 120 | 'render_type' => 'template', |
| 121 | 'condition' => [ |
| 122 | 'wpr_enable_jarallax' => 'yes' |
| 123 | ] |
| 124 | ] |
| 125 | ); |
| 126 | |
| 127 | // Upgrade to Pro Notice |
| 128 | Utilities::upgrade_pro_notice( $element, Controls_Manager::RAW_HTML, 'parallax-background', 'scroll_effect', ['pro-op','pro-sclo','pro-scrlo'] ); |
| 129 | } |
| 130 | |
| 131 | $element->add_control( |
| 132 | 'bg_image', |
| 133 | [ |
| 134 | 'label' => __( 'Choose Image', 'wpr-addons' ), |
| 135 | 'type' => Controls_Manager::MEDIA, |
| 136 | 'dynamic' => [ |
| 137 | 'active' => true, |
| 138 | ], |
| 139 | 'default' => [ |
| 140 | 'url' => Utils::get_placeholder_image_src(), |
| 141 | ], |
| 142 | 'render_type' => 'template', |
| 143 | 'condition' => [ |
| 144 | 'wpr_enable_jarallax' => 'yes' |
| 145 | ] |
| 146 | ] |
| 147 | ); |
| 148 | |
| 149 | if ( ! $this->maybe_call_pro_method( '\WprAddonsPro\Extensions\Wpr_Parallax_Scroll_Pro', 'add_control_bg_image_mobile', [ $element ] ) ) { |
| 150 | $element->add_control( |
| 151 | 'bg_image_mobile', |
| 152 | [ |
| 153 | 'label' => __( 'Choose Mobile Image (Pro)', 'wpr-addons' ), |
| 154 | 'type' => Controls_Manager::MEDIA, |
| 155 | 'classes' => 'wpr-pro-control', |
| 156 | 'condition' => [ |
| 157 | 'wpr_enable_jarallax' => 'yes' |
| 158 | ] |
| 159 | ] |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | } // end if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 164 | |
| 165 | $element->add_control( |
| 166 | 'parallax_type_divider', |
| 167 | [ |
| 168 | 'type' => Controls_Manager::DIVIDER, |
| 169 | 'style' => 'thick', |
| 170 | ] |
| 171 | ); |
| 172 | |
| 173 | if ( 'on' === get_option('wpr-parallax-multi-layer', 'on') ) { |
| 174 | |
| 175 | $element->add_control( |
| 176 | 'parallax_multi_video_tutorial', |
| 177 | [ |
| 178 | 'raw' => '<a href="https://youtu.be/DcDeQ__lJbw?t=121" target="_blank">Watch Video Tutorial <span class="dashicons dashicons-video-alt3"></span></a>', |
| 179 | 'type' => Controls_Manager::RAW_HTML, |
| 180 | ] |
| 181 | ); |
| 182 | |
| 183 | $element->add_control( |
| 184 | 'wpr_enable_parallax_hover', |
| 185 | [ |
| 186 | 'type' => Controls_Manager::SWITCHER, |
| 187 | 'label' => __('Enable Multi Layer Parallax', 'wpr-addons'), |
| 188 | 'default' => 'no', |
| 189 | 'label_on' => __('Yes', 'wpr-addons'), |
| 190 | 'label_off' => __('No', 'wpr-addons'), |
| 191 | 'return_value' => 'yes', |
| 192 | 'render_type' => 'template', |
| 193 | 'prefix_class' => 'wpr-parallax-' |
| 194 | ] |
| 195 | ); |
| 196 | |
| 197 | $element->add_control( |
| 198 | 'invert_direction', |
| 199 | [ |
| 200 | 'type' => Controls_Manager::SWITCHER, |
| 201 | 'label' => __('Invert Animation Direction', 'wpr-addons'), |
| 202 | 'default' => 'no', |
| 203 | 'label_on' => __('Yes', 'wpr-addons'), |
| 204 | 'label_off' => __('No', 'wpr-addons'), |
| 205 | 'return_value' => 'yes', |
| 206 | 'render_type' => 'template', |
| 207 | 'condition' => [ |
| 208 | 'wpr_enable_parallax_hover' => 'yes' |
| 209 | ] |
| 210 | ] |
| 211 | ); |
| 212 | |
| 213 | $element->add_control( |
| 214 | 'scalar_speed', |
| 215 | [ |
| 216 | 'type' => Controls_Manager::SLIDER, |
| 217 | 'label' => esc_html__( 'Animation Speed', 'wpr-addons' ), |
| 218 | 'size_units' => [ '%' ], |
| 219 | 'range' => [ |
| 220 | '%' => [ |
| 221 | 'min' => 0.0, |
| 222 | 'max' => 100.0, |
| 223 | ] |
| 224 | ], |
| 225 | 'default' => [ |
| 226 | 'unit' => '%', |
| 227 | 'size' => 10.0, |
| 228 | ], |
| 229 | 'condition' => [ |
| 230 | 'wpr_enable_parallax_hover' => 'yes' |
| 231 | ] |
| 232 | ] |
| 233 | ); |
| 234 | |
| 235 | $repeater = new Repeater(); |
| 236 | |
| 237 | $repeater->add_control( |
| 238 | 'repeater_bg_image', |
| 239 | [ |
| 240 | 'label' => __( 'Choose Image', 'wpr-addons' ), |
| 241 | 'type' => Controls_Manager::MEDIA, |
| 242 | // 'dynamic' => [ |
| 243 | // 'active' => true, |
| 244 | // ], |
| 245 | 'default' => [ |
| 246 | 'url' => Utils::get_placeholder_image_src(), |
| 247 | ], |
| 248 | 'render_type' => 'template', |
| 249 | ] |
| 250 | ); |
| 251 | |
| 252 | $repeater->add_control( |
| 253 | 'layer_width', |
| 254 | [ |
| 255 | 'label' => esc_html__( 'Image Width', 'wpr-addons' ), |
| 256 | 'type' => Controls_Manager::NUMBER, |
| 257 | 'default' => 100, |
| 258 | 'min' => 0, |
| 259 | 'max' => 1000, |
| 260 | 'step' => 10, |
| 261 | 'selectors' => [ |
| 262 | '{{WRAPPER}} {{CURRENT_ITEM}}.wpr-parallax-ml-children' => 'width: {{SIZE}}px !important;', |
| 263 | ], |
| 264 | ] |
| 265 | ); |
| 266 | |
| 267 | $repeater->add_responsive_control( |
| 268 | 'layer_position_hr', |
| 269 | [ |
| 270 | 'type' => Controls_Manager::SLIDER, |
| 271 | 'label' => esc_html__( 'Horizontal Position (%)', 'wpr-addons' ), |
| 272 | 'size_units' => [ '%' ], |
| 273 | 'range' => [ |
| 274 | '%' => [ |
| 275 | 'min' => 0, |
| 276 | 'max' => 100, |
| 277 | ] |
| 278 | ], |
| 279 | 'default' => [ |
| 280 | 'unit' => '%', |
| 281 | 'size' => 50, |
| 282 | ], |
| 283 | 'selectors' => [ |
| 284 | '{{WRAPPER}} {{CURRENT_ITEM}}.wpr-parallax-ml-children' => 'left: {{SIZE}}{{UNIT}} !important;', |
| 285 | ], |
| 286 | 'separator' => 'before', |
| 287 | ] |
| 288 | ); |
| 289 | |
| 290 | $repeater->add_responsive_control( |
| 291 | 'layer_position_vr', |
| 292 | [ |
| 293 | 'type' => Controls_Manager::SLIDER, |
| 294 | 'label' => esc_html__( 'Vertical Position (%)', 'wpr-addons' ), |
| 295 | 'size_units' => [ '%' ], |
| 296 | 'range' => [ |
| 297 | '%' => [ |
| 298 | 'min' => 0, |
| 299 | 'max' => 100, |
| 300 | ] |
| 301 | ], |
| 302 | 'default' => [ |
| 303 | 'unit' => '%', |
| 304 | 'size' => 50, |
| 305 | ], |
| 306 | 'selectors' => [ |
| 307 | '{{WRAPPER}} {{CURRENT_ITEM}}.wpr-parallax-ml-children' => 'top: {{SIZE}}{{UNIT}}!important;', |
| 308 | ], |
| 309 | ] |
| 310 | ); |
| 311 | |
| 312 | $repeater->add_control( |
| 313 | 'data_depth', |
| 314 | [ |
| 315 | 'label' => __( 'Data Depth', 'wpr-addons' ), |
| 316 | 'type' => Controls_Manager::NUMBER, |
| 317 | 'min' => -1.0, |
| 318 | 'max' => 2.0, |
| 319 | 'step' => 0.1, |
| 320 | 'default' => 0.4, |
| 321 | 'render_type' => 'template', |
| 322 | ] |
| 323 | ); |
| 324 | |
| 325 | $element->add_control( |
| 326 | 'hover_parallax', |
| 327 | [ |
| 328 | 'label' => __( 'Repeater List', 'wpr-addons' ), |
| 329 | 'type' => Controls_Manager::REPEATER, |
| 330 | 'fields' => $repeater->get_controls(), |
| 331 | 'default' => [ |
| 332 | [ |
| 333 | 'layer_position_vr' => [ |
| 334 | 'unit' => '%', |
| 335 | 'size' => 30, |
| 336 | ], |
| 337 | 'layer_position_hr' => [ |
| 338 | 'unit' => '%', |
| 339 | 'size' => 40, |
| 340 | ], |
| 341 | ], |
| 342 | [ |
| 343 | 'layer_position_vr' => [ |
| 344 | 'unit' => '%', |
| 345 | 'size' => 60, |
| 346 | ], |
| 347 | 'layer_position_hr' => [ |
| 348 | 'unit' => '%', |
| 349 | 'size' => 20, |
| 350 | ], |
| 351 | ], |
| 352 | ], |
| 353 | 'condition' => [ |
| 354 | 'wpr_enable_parallax_hover' => 'yes' |
| 355 | ] |
| 356 | ] |
| 357 | ); |
| 358 | |
| 359 | if ( ! $this->has_active_pro_license() ) { |
| 360 | $element->add_control( |
| 361 | 'paralax_repeater_pro_notice', |
| 362 | [ |
| 363 | 'type' => Controls_Manager::RAW_HTML, |
| 364 | 'raw' => 'More than 2 Layers are available<br> in the <strong><a href="https://royal-elementor-addons.com/?ref=rea-plugin-panel-parallax-multi-layer-upgrade-pro#purchasepro" target="_blank">Pro version</a></strong>', |
| 365 | // 'raw' => 'More than 2 Layers are available<br> in the <strong><a href="'. admin_url('admin.php?page=wpr-addons-pricing') .'" target="_blank">Pro version</a></strong>', |
| 366 | 'content_classes' => 'wpr-pro-notice', |
| 367 | 'condition' => [ |
| 368 | 'wpr_enable_parallax_hover' => 'yes' |
| 369 | ] |
| 370 | ] |
| 371 | ); |
| 372 | } |
| 373 | |
| 374 | } // end if ( 'on' === get_option('wpr-parallax-multi-layer', 'on') ) { |
| 375 | |
| 376 | $element->end_controls_section(); |
| 377 | } |
| 378 | |
| 379 | public function _before_render( $element ) { |
| 380 | // bail if any other element but section |
| 381 | // output buffer controlling functions removed elements from live preview |
| 382 | |
| 383 | if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) return; |
| 384 | |
| 385 | $settings = $element->get_settings_for_display(); |
| 386 | |
| 387 | // Parallax Background |
| 388 | if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 389 | if ( 'yes' === $settings['wpr_enable_jarallax'] ) { |
| 390 | $element->add_render_attribute( '_wrapper', [ |
| 391 | 'class' => 'wpr-jarallax', |
| 392 | 'speed-data' => $settings['speed'], |
| 393 | 'bg-image' => $settings['bg_image']['url'], |
| 394 | 'bg-image-mobile' => isset($settings['bg_image_mobile']['url']) ? $settings['bg_image_mobile']['url'] : '', |
| 395 | 'scroll-effect' => $settings['scroll_effect'], |
| 396 | ] ); |
| 397 | |
| 398 | // if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 399 | // echo '<div '. $element->get_render_attribute_string( '_wrapper' ) .'></div>'; |
| 400 | // } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // Parallax Multi Layer |
| 405 | if ( 'on' === get_option('wpr-parallax-multi-layer', 'on') ) { |
| 406 | if ( $settings['wpr_enable_parallax_hover'] == 'yes' ) { |
| 407 | if ( $settings['hover_parallax'] ) { |
| 408 | |
| 409 | echo '<div class="wpr-parallax-multi-layer" scalar-speed="'. esc_attr($settings['scalar_speed']['size']) .'" direction="'. esc_attr($settings['invert_direction']) .'" style="overflow: hidden;">'; |
| 410 | |
| 411 | foreach ( $settings['hover_parallax'] as $key => $item ) { |
| 412 | if ( $key < 2 || $this->has_active_pro_license() ) { |
| 413 | echo '<div data-depth="'. esc_attr($item['data_depth']) .'" style-top="'. esc_attr($item['layer_position_vr']['size']) .'%" style-left="'. esc_attr($item['layer_position_hr']['size']) .'%" class="wpr-parallax-ml-children elementor-repeater-item-'. esc_attr($item['_id']) .'">'; |
| 414 | echo '<img src="'. esc_url($item['repeater_bg_image']['url']) .'">'; |
| 415 | echo '</div>'; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | echo '</div>'; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | } |
| 425 | |
| 426 | public function _print_template( $template, $widget ) { |
| 427 | ob_start(); |
| 428 | |
| 429 | if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 430 | echo '<div class="wpr-jarallax" speed-data-editor="{{settings.speed}}" scroll-effect-editor="{{settings.scroll_effect}}" bg-image-editor="{{settings.bg_image.url}}" bg-image-mobile-editor="{{ settings.bg_image_mobile && settings.bg_image_mobile.url ? settings.bg_image_mobile.url : \'\' }}"></div>'; |
| 431 | } |
| 432 | // Multi Layer |
| 433 | if ( 'on' === get_option('wpr-parallax-multi-layer', 'on') ) { |
| 434 | if ( ! $this->has_active_pro_license() ) { |
| 435 | ?> |
| 436 | <# if ( settings.hover_parallax.length && settings.wpr_enable_parallax_hover == 'yes') { #> |
| 437 | <div class="wpr-parallax-multi-layer" direction="{{settings.invert_direction}}" scalar-speed="{{settings.scalar_speed.size}}" data-relative-input="true" style="overflow: hidden;"> |
| 438 | <# _.each( settings.hover_parallax, function( item, index ) { #> |
| 439 | <# if ( index > 1 ) return; #> |
| 440 | <div data-depth="{{item.data_depth}}" class="wpr-parallax-ml-children elementor-repeater-item-{{ item._id }}"> |
| 441 | <img src="{{item.repeater_bg_image.url}}"> |
| 442 | </div> |
| 443 | <# }); #> |
| 444 | </div> |
| 445 | <# } #> |
| 446 | <?php |
| 447 | } else { |
| 448 | ?> |
| 449 | <# if ( settings.hover_parallax.length && settings.wpr_enable_parallax_hover == 'yes') { #> |
| 450 | <div class="wpr-parallax-multi-layer" direction="{{settings.invert_direction}}" scalar-speed="{{settings.scalar_speed.size}}" data-relative-input="true" style="overflow: hidden;"> |
| 451 | <# _.each( settings.hover_parallax, function( item ) { #> |
| 452 | <div data-depth="{{item.data_depth}}" class="wpr-parallax-ml-children elementor-repeater-item-{{ item._id }}"> |
| 453 | <img src="{{item.repeater_bg_image.url}}"> |
| 454 | </div> |
| 455 | <# }); #> |
| 456 | </div> |
| 457 | <# } #> |
| 458 | <?php |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | $parallax_content = ob_get_contents(); |
| 463 | |
| 464 | ob_end_clean(); |
| 465 | return $template . $parallax_content; |
| 466 | } |
| 467 | |
| 468 | public static function enqueue_scripts() { |
| 469 | if ( 'on' === get_option('wpr-parallax-background', 'on') ) { |
| 470 | wp_enqueue_script( 'wpr-jarallax', WPR_ADDONS_URL . 'assets/js/lib/jarallax/jarallax.min.js', ['jquery'], '1.12.7', true ); |
| 471 | } |
| 472 | |
| 473 | if ( 'on' === get_option('wpr-parallax-multi-layer', 'on') ) { |
| 474 | wp_enqueue_script( 'wpr-parallax-hover', WPR_ADDONS_URL . 'assets/js/lib/parallax/parallax.min.js', ['jquery'], '1.0', true ); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | } |
| 479 | new Wpr_Parallax_Scroll(); |
| 480 |