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(); |