start_controls_section( 'eppro_sticky_section', [ 'label' => EPPRO_Elementor_Helper::panel_label( __( 'Sticky', 'admore-widgets-suite' ) ), 'tab' => \Elementor\Controls_Manager::TAB_ADVANCED, ] ); $element->add_control( 'eppro_sticky_enable', [ 'label' => __( 'Enable Sticky', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '', ] ); $element->add_control( 'eppro_sticky_position', [ 'label' => __( 'Stick To', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'top', 'options' => [ 'top' => __( 'Top', 'admore-widgets-suite' ), 'bottom' => __( 'Bottom', 'admore-widgets-suite' ), ], 'condition' => [ 'eppro_sticky_enable' => 'yes' ], ] ); $element->add_control( 'eppro_sticky_offset', [ 'label' => __( 'Offset (px)', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => [ 'px' ], 'range' => [ 'px' => [ 'min' => 0, 'max' => 300 ] ], 'default' => [ 'size' => 0 ], 'condition' => [ 'eppro_sticky_enable' => 'yes' ], ] ); $element->add_control( 'eppro_sticky_z_index', [ 'label' => __( 'Z-Index', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 100, 'min' => 1, 'condition' => [ 'eppro_sticky_enable' => 'yes' ], ] ); $element->add_control( 'eppro_sticky_scroll_bg', [ 'label' => __( 'Background After Scroll', 'admore-widgets-suite' ), 'description' => __( 'Applied once the element becomes sticky.', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'condition' => [ 'eppro_sticky_enable' => 'yes' ], ] ); $element->add_control( 'eppro_sticky_devices', [ 'label' => __( 'Sticky On', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'multiple' => true, 'default' => [ 'desktop', 'tablet', 'mobile' ], 'options' => [ 'desktop' => __( 'Desktop', 'admore-widgets-suite' ), 'tablet' => __( 'Tablet', 'admore-widgets-suite' ), 'mobile' => __( 'Mobile', 'admore-widgets-suite' ), ], 'condition' => [ 'eppro_sticky_enable' => 'yes' ], ] ); $element->end_controls_section(); } // ========================================================================= // Render — inject data-attributes read by JS // ========================================================================= public static function add_attributes( \Elementor\Element_Base $element ): void { $settings = $element->get_settings_for_display(); if ( ( $settings['eppro_sticky_enable'] ?? '' ) !== 'yes' ) return; $pos = $settings['eppro_sticky_position'] ?? 'top'; $offset = (int) ( $settings['eppro_sticky_offset']['size'] ?? 0 ); $z = (int) ( $settings['eppro_sticky_z_index'] ?? 100 ); $scroll_bg = esc_attr( $settings['eppro_sticky_scroll_bg'] ?? '' ); $raw_devices = $settings['eppro_sticky_devices'] ?? [ 'desktop', 'tablet', 'mobile' ]; $devices = is_array( $raw_devices ) ? implode( ',', $raw_devices ) : (string) $raw_devices; $element->add_render_attribute( '_wrapper', [ 'data-eppro-sticky' => 'yes', 'data-eppro-sticky-position' => esc_attr( $pos ), 'data-eppro-sticky-offset' => esc_attr( $offset ), 'data-eppro-sticky-z' => esc_attr( $z ), 'data-eppro-sticky-scroll-bg'=> $scroll_bg, 'data-eppro-sticky-devices' => esc_attr( $devices ), ] ); } }