PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 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-sticky-section.php
royal-elementor-addons / extensions Last commit date
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-sticky-section.php
346 lines
1 <?php
2 use Elementor\Controls_Manager;
3 use Elementor\Control_Media;
4 use Elementor\Controls_Stack;
5 use Elementor\Element_Base;
6 use Elementor\Repeater;
7 use Elementor\Utils;
8 use Elementor\Core\Base\Module;
9 use Elementor\Core\Kits\Documents\Tabs\Settings_Layout;
10 use Elementor\Core\Responsive\Files\Frontend;
11 use Elementor\Plugin;
12 use Elementor\Core\Breakpoints\Manager;
13 use Elementor\Core\Breakpoints;
14 use Elementor\Group_Control_Box_Shadow;
15 use WprAddons\Classes\Utilities;
16
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 class Wpr_Sticky_Section extends Wpr_Extensions_Base {
23
24 public function __construct() {
25 add_action( 'elementor/element/section/section_background/after_section_end', [ $this, 'register_controls' ], 10 );
26 add_action( 'elementor/section/print_template', [ $this, '_print_template' ], 10, 2 );
27 add_action( 'elementor/frontend/section/before_render', [ $this, '_before_render' ], 10, 1 );
28
29 // FLEXBOX
30 add_action('elementor/element/container/section_layout/after_section_end', [$this, 'register_controls'], 10);
31 add_action( 'elementor/container/print_template', [ $this, '_print_template' ], 10, 2 );
32 add_action('elementor/frontend/container/before_render', [$this, '_before_render'], 10, 1);
33 }
34
35 public static function add_control_group_sticky_advanced_options($element) {
36
37 $element->add_control(
38 'sticky_advanced_pro_notice',
39 [
40 'type' => Controls_Manager::RAW_HTML,
41 'raw' => '<strong>Advanced Options</strong> are available in the <br><a href="https://royal-elementor-addons.com/?ref=rea-plugin-panel-advanced-stiky-upgrade-pro#purchasepro" target="_blank">Pro Version.</a> You\'ll have the ability to create impressive menu effects. Preview some examples: <strong><a href="https://demosites.royal-elementor-addons.com/fashion-v2/?ref=rea-plugin-panel-advanced-stiky-preview" target="_blank">Demo 1, </a><a href="https://demosites.royal-elementor-addons.com/digital-marketing-agency-v2/?ref=rea-plugin-panel-advanced-stiky-preview" target="_blank">Demo 2, </a><a href="https://demosites.royal-elementor-addons.com/personal-blog-v1/?ref=rea-plugin-panel-advanced-stiky-preview" target="_blank">Demo 3, </a><a href="https://demosites.royal-elementor-addons.com/digital-marketing-agency-v1/?ref=rea-plugin-panel-advanced-stiky-preview" target="_blank">Demo 4, </a><a href="https://demosites.royal-elementor-addons.com/construction-v3/?ref=rea-plugin-panel-advanced-stiky-preview" target="_blank">Demo 5</a></strong><a href="https://www.youtube.com/watch?v=ORay3VWrWuc" target="_blank" style="display: block; color: #f51f3d; margin-top: 10px; margin-bottom: 10px;">Watch Video Tutorial</a><img src="'. WPR_ADDONS_ASSETS_URL .'img/pro-options/sticky-section-pro-features.jpg" style="border: 1px solid #93003C;">',
42 'content_classes' => 'wpr-pro-notice',
43 'condition' => [
44 'enable_sticky_section' => 'yes'
45 ]
46 ]
47 );
48 }
49
50 public function register_controls( $element ) {
51
52 if ( ( 'section' === $element->get_name() || 'container' === $element->get_name() ) ) {
53
54 $element->start_controls_section (
55 'wpr_section_sticky_section',
56 [
57 'tab' => Controls_Manager::TAB_ADVANCED,
58 'label' => sprintf(esc_html__('Sticky Section - %s', 'wpr-addons'), esc_html('RA')),
59 ]
60 );
61
62 $element->add_control(
63 'wpr_sticky_apply_changes',
64 [
65 'type' => Controls_Manager::RAW_HTML,
66 '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>',
67 'separator' => 'after'
68 ]
69 );
70
71 $element->add_control (
72 'enable_sticky_section',
73 [
74 'type' => Controls_Manager::SWITCHER,
75 'label' => esc_html__( 'Make This Section Sticky', 'wpr-addons' ),
76 'default' => 'no',
77 'return_value' => 'yes',
78 'prefix_class' => 'wpr-sticky-section-',
79 'render_type' => 'template',
80 ]
81 );
82
83 $element->add_control(
84 'enable_on_devices',
85 [
86 'label' => esc_html__( 'Enable on Devices', 'wpr-addons' ),
87 'label_block' => true,
88 'type' => Controls_Manager::SELECT2,
89 'default' => ['desktop_sticky'],
90 'options' => $this->breakpoints_manager(),
91 'multiple' => true,
92 'separator' => 'before',
93 'condition' => [
94 'enable_sticky_section' => 'yes'
95 ],
96
97 ]
98 );
99
100 $element->add_control (
101 'position_type',
102 [
103 'label' => __( 'Position Type', 'wpr-addons' ),
104 'type' => Controls_Manager::SELECT,
105 'default' => 'sticky',
106 'options' => [
107 'sticky' => __( 'Stick on Scroll', 'wpr-addons' ),
108 'fixed' => __( 'Fixed by Default', 'wpr-addons' ),
109 ],
110 // 'selectors' => [
111 // '{{WRAPPER}}' => 'position: {{VALUE}};',
112 // ],
113 'render_type' => 'template',
114 'condition' => [
115 'enable_sticky_section' => 'yes'
116 ],
117 ]
118 );
119
120 $element->add_control (
121 'sticky_type',
122 [
123 'label' => __( 'Sticky Relation', 'wpr-addons' ),
124 'type' => Controls_Manager::SELECT,
125 'description' => __('Please switch to *Window* if you are going to use <span style="color: red;">*Advanced Options*</span>.', 'wpr-addons'),
126 'default' => 'sticky',
127 'options' => [
128 'sticky' => __( 'Parent', 'wpr-addons' ),
129 'fixed' => __( 'Window', 'wpr-addons' ),
130 ],
131 'render_type' => 'template',
132 'condition' => [
133 'enable_sticky_section' => 'yes',
134 'position_type' => 'sticky'
135 ],
136 ]
137 );
138
139 $element->add_control (
140 'position_location',
141 [
142 'label' => __( 'Location', 'wpr-addons' ),
143 'type' => Controls_Manager::SELECT,
144 'default' => 'top',
145 'render_type' => 'template',
146 'options' => [
147 'top' => __( 'Top', 'wpr-addons' ),
148 'bottom' => __( 'Bottom', 'wpr-addons' ),
149 ],
150 // 'selectors_dictionary' => [
151 // 'top' => 'top: {{position_offset.VALUE}}px; bottom: auto;',
152 // 'bottom' => 'bottom: {{position_offset.VALUE}}px; top: auto;'
153 // ],
154 'selectors' => [
155 '{{WRAPPER}}' => 'top: auto; bottom: auto; {{VALUE}}: {{position_offset.VALUE}}px;',
156 ],
157 'condition' => [
158 'enable_sticky_section' => 'yes'
159 ]
160 ]
161 );
162
163 $element->add_responsive_control(
164 'position_offset',
165 [
166 'label' => __( 'Offset', 'wpr-addons' ),
167 'type' => Controls_Manager::NUMBER,
168 'min' => 0,
169 'max' => 500,
170 'required' => true,
171 'frontend_available' => true,
172 'render_type' => 'template',
173 'default' => 0,
174 'widescreen_default' => 0,
175 'laptop_default' => 0,
176 'tablet_extra_default' => 0,
177 'tablet_default' => 0,
178 'mobile_extra_default' => 0,
179 'mobile_default' => 0,
180 'selectors' => [
181 '{{WRAPPER}}' => 'top: auto; bottom: auto; {{position_location.VALUE}}: {{VALUE}}px;',
182 '{{WRAPPER}} + .wpr-hidden-header' => 'top: {{VALUE}}px;',
183 '{{WRAPPER}} + .wpr-hidden-header-flex' => 'top: {{VALUE}}px;'
184 ],
185 'condition' => [
186 'enable_sticky_section' => 'yes'
187 ],
188 ]
189 );
190
191 $element->add_control(
192 'wpr_z_index',
193 [
194 'label' => esc_html__( 'Z-Index', 'wpr-addons' ),
195 'type' => Controls_Manager::NUMBER,
196 'min' => -99,
197 'max' => 99999,
198 'step' => 1,
199 'default' => 10,
200 'selectors' => [
201 '{{WRAPPER}}' => 'z-index: {{VALUE}};',
202 '.wpr-hidden-header' => 'z-index: {{VALUE}};',
203 '.wpr-hidden-header-flex' => 'z-index: {{VALUE}};'
204 ],
205 'condition' => [
206 'enable_sticky_section' => 'yes'
207 ],
208 'render_type' => 'template'
209 ]
210 );
211
212 $element->add_control(
213 'custom_breakpoints',
214 [
215 'label' => __( 'Breakpoints', 'wpr-addons' ),
216 'type' => \Elementor\Controls_Manager::HIDDEN,
217 'default' => get_option('elementor_experiment-additional_custom_breakpoints'),
218 'condition' => [
219 'enable_sticky_section' => 'yes'
220 ]
221 ]
222 );
223
224 $element->add_control(
225 'active_breakpoints',
226 [
227 'label' => __( 'Active Breakpoints', 'wpr-addons' ),
228 'type' => \Elementor\Controls_Manager::HIDDEN,
229 'default' => $this->breakpoints_manager_active(),
230 'condition' => [
231 'enable_sticky_section' => 'yes'
232 ]
233 ]
234 );
235
236 if ( ! $this->maybe_call_pro_method( '\WprAddonsPro\Extensions\Wpr_Sticky_Section_Pro', 'add_control_group_sticky_advanced_options', [ $element ] ) ) {
237 $this->add_control_group_sticky_advanced_options($element);
238 }
239
240 $element->end_controls_section();
241 }
242 }
243
244 public function breakpoints_manager() {
245 $active_breakpoints = [];
246 foreach ( \Elementor\Plugin::$instance->breakpoints->get_active_breakpoints() as $key => $value ) {
247 $active_breakpoints[$key . '_sticky'] = esc_html__(ucwords(preg_replace('/_/i', ' ', $key)), 'wpr-addons');
248 }
249
250 $active_breakpoints['desktop_sticky'] = esc_html__('Desktop', 'wpr-addons');
251 return $active_breakpoints;
252 }
253
254 public function breakpoints_manager_active() {
255 $active_breakpoints = [];
256
257 foreach ( $this->breakpoints_manager() as $key => $value ) {
258 array_push($active_breakpoints, $key);
259 }
260
261 return $active_breakpoints;
262 }
263
264 public function _before_render( $element ) {
265 if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) {
266 return;
267 }
268
269 $settings = $element->get_settings_for_display();
270
271 if ($settings['enable_sticky_section'] !== 'yes') return;
272
273 $wpr_sticky_effects_offset_widescreen = isset($settings['wpr_sticky_effects_offset_widescreen']) && !empty($settings['wpr_sticky_effects_offset_widescreen']) ? $settings['wpr_sticky_effects_offset_widescreen'] : 0;
274 $wpr_sticky_effects_offset_desktop = isset($settings['wpr_sticky_effects_offset']) && !empty($settings['wpr_sticky_effects_offset']) ? $settings['wpr_sticky_effects_offset'] : $wpr_sticky_effects_offset_widescreen;
275 $wpr_sticky_effects_offset_laptop = isset($settings['wpr_sticky_effects_offset_laptop']) && !empty($settings['wpr_sticky_effects_offset_laptop']) ? $settings['wpr_sticky_effects_offset_laptop'] : $wpr_sticky_effects_offset_desktop;
276 $wpr_sticky_effects_offset_tablet_extra = isset($settings['wpr_sticky_effects_offset_tablet_extra']) && !empty($settings['wpr_sticky_effects_offset_tablet_extra']) ? $settings['wpr_sticky_effects_offset_tablet_extra'] : $wpr_sticky_effects_offset_laptop;
277 $wpr_sticky_effects_offset_tablet = isset($settings['wpr_sticky_effects_offset_tablet']) && !empty($settings['wpr_sticky_effects_offset_tablet']) ? $settings['wpr_sticky_effects_offset_tablet'] : $wpr_sticky_effects_offset_tablet_extra;
278 $wpr_sticky_effects_offset_mobile_extra = isset($settings['wpr_sticky_effects_offset_mobile_extra']) && !empty($settings['wpr_sticky_effects_offset_mobile_extra']) ? $settings['wpr_sticky_effects_offset_mobile_extra'] : $wpr_sticky_effects_offset_tablet;
279 $wpr_sticky_effects_offset_mobile = isset($settings['wpr_sticky_effects_offset_mobile']) && !empty($settings['wpr_sticky_effects_offset_mobile']) ? $settings['wpr_sticky_effects_offset_mobile'] : $wpr_sticky_effects_offset_mobile_extra;
280
281 $allowed_positions = ['top', 'bottom']; // Define allowed positions
282 // $position_location = isset( $_POST['position_location'] ) ? $_POST['position_location'] : ''; // TODO: Check if this is needed
283 $position_location = $settings['position_location'];
284
285 if ( ! in_array( $position_location, $allowed_positions ) ) {
286 $position_location = 'top';
287 } else {
288 $position_location = sanitize_text_field( $position_location );
289 }
290
291 if ( $settings['enable_sticky_section'] === 'yes' ) {
292 $element->add_render_attribute( '_wrapper', [
293 'data-wpr-sticky-section' => $settings['enable_sticky_section'],
294 'data-wpr-position-type' => $settings['position_type'],
295 'data-wpr-position-offset' => $settings['position_offset'],
296 'data-wpr-position-location' => $position_location,
297 'data-wpr-sticky-devices' => $settings['enable_on_devices'],
298 'data-wpr-custom-breakpoints' => $settings['custom_breakpoints'],
299 'data-wpr-active-breakpoints' => $this->breakpoints_manager_active(),
300 'data-wpr-z-index' => $settings['wpr_z_index'],
301 'data-wpr-sticky-hide' => isset($settings['sticky_hide']) ? $settings['sticky_hide'] : '',
302 'data-wpr-replace-header' => isset($settings['sticky_replace_header']) ? $settings['sticky_replace_header'] : '',
303 'data-wpr-animation-duration' => isset($settings['sticky_animation_duration']) ? $settings['sticky_animation_duration'] : '',
304 'data-wpr-sticky-type' => isset($settings['sticky_type']) ? $settings['sticky_type'] : '',
305 // 'data-wpr-offset-settings' => wp_json_encode([
306 // 'widescreen' => $wpr_sticky_effects_offset_widescreen,
307 // 'desktop' => $wpr_sticky_effects_offset_desktop,
308 // 'laptop' => $wpr_sticky_effects_offset_laptop,
309 // 'tablet_extra' => $wpr_sticky_effects_offset_tablet_extra,
310 // 'tablet' => $wpr_sticky_effects_offset_tablet,
311 // 'mobile_extra' => $wpr_sticky_effects_offset_mobile_extra,
312 // 'mobile' => $wpr_sticky_effects_offset_mobile
313 // ])
314 ] );
315 }
316 }
317
318 public function _print_template( $template, $widget ) {
319 if ( $widget->get_name() !== 'section' && $widget->get_name() !== 'container' ) {
320 return $template;
321 }
322
323 ob_start();
324
325 ?>
326
327 <# if ( 'yes' === settings.enable_sticky_section) { #>
328 <# if ( 'top' !== settings.position_location && 'bottom' !== settings.position_location ) {
329 settings.position_location = 'top';
330 } #>
331
332 <div class="wpr-sticky-section-yes-editor" data-wpr-z-index={{{settings.wpr_z_index}}} data-wpr-sticky-section={{{settings.enable_sticky_section}}} data-wpr-position-type={{{settings.position_type}}} data-wpr-position-offset={{{settings.position_offset}}} data-wpr-position-location={{{settings.position_location}}} data-wpr-sticky-devices={{{settings.enable_on_devices}}} data-wpr-custom-breakpoints={{{settings.custom_breakpoints}}} data-wpr-active-breakpoints={{{settings.active_breakpoints}}} data-wpr-sticky-animation={{{settings.sticky_animation}}} data-wpr-offset-settings={{{settings.wpr_sticky_effects_offset}}} data-wpr-sticky-type={{{settings.sticky_type}}}></div>
333 <# } #>
334
335 <?php
336
337 // how to render attributes without creating new div using view.addRenderAttributes
338 $particles_content = ob_get_contents();
339
340 ob_end_clean();
341
342 return $template . $particles_content;
343 }
344 }
345
346 new Wpr_Sticky_Section();