PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1027
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1027
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-custom-css.php 11 months ago wpr-parallax.php 11 months ago wpr-particles.php 11 months ago wpr-sticky-section.php 11 months ago
wpr-particles.php
184 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 {
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'), Utilities::get_plugin_name()),
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 ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
69 \WprAddonsPro\Extensions\Wpr_Particles_Pro::add_control_which_particle($element);
70 } else {
71 $element->add_control (
72 'which_particle',
73 [
74 'label' => __( 'Select Style', 'plugin-domain' ),
75 'type' => Controls_Manager::SELECT,
76 'default' => 'wpr_particle_json_custom',
77 'options' => [
78 'wpr_particle_json_custom' => __( 'Custom', 'plugin-domain' ),
79 'pro-pjs' => __( 'Predefined (Pro)', 'plugin-domain' ),
80 ],
81 'condition' => [
82 'wpr_enable_particles' => 'yes'
83 ]
84 ]
85 );
86
87 // Upgrade to Pro Notice
88 Utilities::upgrade_pro_notice( $element, Controls_Manager::RAW_HTML, 'particles', 'which_particle', ['pro-pjs'] );
89 }
90
91 $this->custom_json_particles( $this->default_particles, $element );
92
93 if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
94 \WprAddonsPro\Extensions\Wpr_Particles_Pro::add_control_group_predefined_particles($element);
95 }
96
97 $element->end_controls_section();
98
99 } // end if()
100
101 }
102
103 public function custom_json_particles($array, $element) {
104 $element->add_control(
105 'wpr_particle_json_custom_notice',
106 [
107 'type' => Controls_Manager::RAW_HTML,
108 'content_classes' => 'elementor-control-field-description',
109 'raw' => __('<a href="https://vincentgarreau.com/particles.js/" target="_blank">Click here</a> to generate JSON for the below field.', 'wpr-addons'),
110 'condition' => [
111 'which_particle' => 'wpr_particle_json_custom',
112 'wpr_enable_particles' => 'yes'
113 ],
114 ]
115 );
116
117 $element->add_control(
118 'wpr_particle_json_custom',
119 [
120 'type' => Controls_Manager::CODE,
121 'label' => esc_html__( 'Enter Custom JSON', 'wpr-addons' ),
122 'default' => $array,
123 'render_type' => 'template',
124 'condition' => [
125 'which_particle' => 'wpr_particle_json_custom',
126 'wpr_enable_particles' => 'yes'
127 ],
128 ]
129 );
130 }
131
132 public function _print_template( $template, $widget ) {
133 if ( $widget->get_name() !== 'section' && $widget->get_name() !== 'container' ) {
134 return $template;
135 }
136
137 ob_start();
138
139 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>';
140
141 $particles_content = ob_get_contents();
142
143 ob_end_clean();
144
145 return $template . $particles_content;
146 }
147
148 public function _before_render( $element ) {
149 if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) {
150 return;
151 }
152
153 $settings = $element->get_settings();
154
155 if ( $settings['wpr_enable_particles'] === 'yes' ) {
156 $settings['which_particle'] = 'pro-pjs' === $settings['which_particle'] ? 'wpr_particle_json_custom' : $settings['which_particle'];
157
158 if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) {
159 $element->add_render_attribute( '_wrapper', [
160 'data-wpr-particles' => $settings[$settings['which_particle']],
161 'particle-source' => $settings['which_particle'],
162 ] );
163 } else {
164 $element->add_render_attribute( '_wrapper', [
165 'data-wpr-particles' => $settings[$settings['which_particle']],
166 'particle-source' => $settings['which_particle'],
167 'wpr-quantity' => $settings['quantity'],
168 'wpr-color' => $settings['particles_color'],
169 'wpr-speed' => $settings['particles_speed'],
170 'wpr-shape' => $settings['particles_shape'],
171 'wpr-size' => $settings['particles_size']
172 ] );
173 }
174 }
175 }
176
177 public function enqueue_scripts() {
178 wp_enqueue_script( 'wpr-particles', WPR_ADDONS_URL . 'assets/js/lib/particles/particles.js', [ 'jquery' ], '3.0.6', true );
179 }
180
181 }
182
183 new Wpr_Particles();
184