PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1060
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1060
1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / extensions / wpr-particles.php
royal-elementor-addons / extensions Last commit date
wpr-column-slider.php 3 weeks ago wpr-custom-css.php 3 weeks ago wpr-display-conditions.php 3 weeks ago wpr-equal-height.php 3 weeks ago wpr-extensions-base.php 3 weeks ago wpr-parallax.php 3 weeks ago wpr-particles.php 3 weeks ago wpr-sticky-section.php 3 weeks ago
wpr-particles.php
180 lines
1 <?php
2 use Elementor\Controls_Manager;
3 use WprAddons\Classes\Utilities;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Wpr_Particles extends Wpr_Extensions_Base {
10
11 private static $_instance = null;
12
13 public $default_particles = '{"particles":{"number":{"value":80,"density":{"enable":true,"value_area":800}},"color":{"value":"#000000"},"shape":{"type":"circle","stroke":{"width":0,"color":"#000000"},"polygon":{"nb_sides":5},"image":{"src":"img/github.svg","width":100,"height":100}},"opacity":{"value":0.5,"random":false,"anim":{"enable":false,"speed":1,"opacity_min":0.1,"sync":false}},"size":{"value":3,"random":true,"anim":{"enable":false,"speed":40,"size_min":0.1,"sync":false}},"line_linked":{"enable":true,"distance":150,"color":"#000000","opacity":0.4,"width":1},"move":{"enable":true,"speed":6,"direction":"none","random":false,"straight":false,"out_mode":"out","bounce":false,"attract":{"enable":false,"rotateX":600,"rotateY":1200}}},"interactivity":{"detect_on":"window","events":{"onhover":{"enable":true,"mode":"repulse"},"onclick":{"enable":true,"mode":"push"},"resize":true},"modes":{"grab":{"distance":400,"line_linked":{"opacity":1}},"bubble":{"distance":400,"size":40,"duration":2,"opacity":8,"speed":3},"repulse":{"distance":200,"duration":0.4},"push":{"particles_nb":4},"remove":{"particles_nb":2}}},"retina_detect":true}' ;
14
15 public function __construct() {
16 add_action( 'elementor/element/section/section_background/after_section_end', [ $this, 'register_controls' ], 10 );
17 add_action( 'elementor/frontend/section/before_render', [ $this, '_before_render' ], 10, 1 );
18 add_action( 'elementor/section/print_template', [ $this, '_print_template' ], 10, 2 );
19 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
20
21 // FLEXBOX
22 add_action( 'elementor/element/container/section_layout/after_section_end', [$this, 'register_controls'], 10 );
23 add_action( 'elementor/frontend/container/before_render', [$this, '_before_render'], 10, 1 );
24 add_action( 'elementor/container/print_template', [ $this, '_print_template' ], 10, 2 );
25 }
26
27 public function register_controls( $element ) {
28
29 if ( ( 'section' === $element->get_name() || 'container' === $element->get_name() ) ) {
30
31 $element->start_controls_section (
32 'wpr_section_particles',
33 [
34 'tab' => Controls_Manager::TAB_STYLE,
35 'label' => sprintf(esc_html__('Particles - %s', 'wpr-addons'), esc_html('RA')),
36 ]
37 );
38
39 $element->add_control(
40 'wpr_particles_apply_changes',
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 $element->add_control(
49 'particles_video_tutorial',
50 [
51 'raw' => '<br><a href="https://www.youtube.com/watch?v=8OdnaoFSj94" target="_blank">Watch Video Tutorial <span class="dashicons dashicons-video-alt3"></span></a>',
52 'type' => Controls_Manager::RAW_HTML,
53 ]
54 );
55
56 $element->add_control (
57 'wpr_enable_particles',
58 [
59 'type' => Controls_Manager::SWITCHER,
60 'label' => esc_html__( 'Enable Particles Background', 'wpr-addons' ),
61 'default' => 'no',
62 'return_value' => 'yes',
63 'prefix_class' => 'wpr-particle-',
64 'render_type' => 'template',
65 ]
66 );
67
68 if ( ! $this->maybe_call_pro_method( '\WprAddonsPro\Extensions\Wpr_Particles_Pro', 'add_control_which_particle', [ $element ] ) ) {
69 $element->add_control (
70 'which_particle',
71 [
72 'label' => __( 'Select Style', 'wpr-addons' ),
73 'type' => Controls_Manager::SELECT,
74 'default' => 'wpr_particle_json_custom',
75 'options' => [
76 'wpr_particle_json_custom' => __( 'Custom', 'wpr-addons' ),
77 'pro-pjs' => __( 'Predefined (Pro)', 'wpr-addons' ),
78 ],
79 'condition' => [
80 'wpr_enable_particles' => 'yes'
81 ]
82 ]
83 );
84
85 // Upgrade to Pro Notice
86 Utilities::upgrade_pro_notice( $element, Controls_Manager::RAW_HTML, 'particles', 'which_particle', ['pro-pjs'] );
87 }
88
89 $this->custom_json_particles( $this->default_particles, $element );
90
91 $this->maybe_call_pro_method( '\WprAddonsPro\Extensions\Wpr_Particles_Pro', 'add_control_group_predefined_particles', [ $element ] );
92
93 $element->end_controls_section();
94
95 } // end if()
96
97 }
98
99 public function custom_json_particles($array, $element) {
100 $element->add_control(
101 'wpr_particle_json_custom_notice',
102 [
103 'type' => Controls_Manager::RAW_HTML,
104 'content_classes' => 'elementor-control-field-description',
105 'raw' => __('<a href="https://vincentgarreau.com/particles.js/" target="_blank">Click here</a> to generate JSON for the below field.', 'wpr-addons'),
106 'condition' => [
107 'which_particle' => 'wpr_particle_json_custom',
108 'wpr_enable_particles' => 'yes'
109 ],
110 ]
111 );
112
113 $element->add_control(
114 'wpr_particle_json_custom',
115 [
116 'type' => Controls_Manager::CODE,
117 'label' => esc_html__( 'Enter Custom JSON', 'wpr-addons' ),
118 'default' => $array,
119 'render_type' => 'template',
120 'condition' => [
121 'which_particle' => 'wpr_particle_json_custom',
122 'wpr_enable_particles' => 'yes'
123 ],
124 ]
125 );
126 }
127
128 public function _print_template( $template, $widget ) {
129 if ( $widget->get_name() !== 'section' && $widget->get_name() !== 'container' ) {
130 return $template;
131 }
132
133 ob_start();
134
135 echo '<div class="wpr-particle-wrapper" id="wpr-particle-{{ view.getID() }}" data-wpr-particles-editor="{{ settings[settings.which_particle] }}" particle-source="{{settings.which_particle}}" wpr-quantity="{{settings.quantity}}" wpr-color="{{settings.particles_color}}" wpr-speed="{{settings.particles_speed}}" wpr-shape="{{settings.particles_shape}}" wpr-size="{{settings.particles_size}}"></div>';
136
137 $particles_content = ob_get_contents();
138
139 ob_end_clean();
140
141 return $template . $particles_content;
142 }
143
144 public function _before_render( $element ) {
145 if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) {
146 return;
147 }
148
149 $settings = $element->get_settings();
150
151 if ( $settings['wpr_enable_particles'] === 'yes' ) {
152 $settings['which_particle'] = 'pro-pjs' === $settings['which_particle'] ? 'wpr_particle_json_custom' : $settings['which_particle'];
153
154 if ( ! $this->has_active_pro_license() ) {
155 $element->add_render_attribute( '_wrapper', [
156 'data-wpr-particles' => $settings[$settings['which_particle']],
157 'particle-source' => $settings['which_particle'],
158 ] );
159 } else {
160 $element->add_render_attribute( '_wrapper', [
161 'data-wpr-particles' => $settings[$settings['which_particle']],
162 'particle-source' => $settings['which_particle'],
163 'wpr-quantity' => $settings['quantity'],
164 'wpr-color' => $settings['particles_color'],
165 'wpr-speed' => $settings['particles_speed'],
166 'wpr-shape' => $settings['particles_shape'],
167 'wpr-size' => $settings['particles_size']
168 ] );
169 }
170 }
171 }
172
173 public function enqueue_scripts() {
174 wp_enqueue_script( 'wpr-particles', WPR_ADDONS_URL . 'assets/js/lib/particles/particles.js', [ 'jquery' ], '3.0.6', true );
175 }
176
177 }
178
179 new Wpr_Particles();
180