Heading_Highlighted.php
220 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | namespace SPEL\includes\Admin\extension; |
| 4 | |
| 5 | use Elementor\Controls_Manager; |
| 6 | use Elementor\Element_Base; |
| 7 | |
| 8 | if (!defined('ABSPATH')) { |
| 9 | exit; // Exit if accessed directly |
| 10 | } |
| 11 | |
| 12 | class Heading_Highlighted { |
| 13 | |
| 14 | public function __construct() { |
| 15 | |
| 16 | |
| 17 | // Elementor Heading Widget Support |
| 18 | add_action( 'elementor/element/heading/section_title_style/after_section_end', [ $this, 'register_heading_widget_controls' ] ); |
| 19 | |
| 20 | add_action( 'elementor/editor/before_render', [ $this, 'render_display_content' ], 99 ); |
| 21 | add_action( 'elementor/frontend/before_render', [ $this, 'render_display_content' ], 99 ); |
| 22 | |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | * Heading Widgets. |
| 27 | */ |
| 28 | public function register_heading_widget_controls( Element_Base $element): void |
| 29 | { |
| 30 | |
| 31 | |
| 32 | //=============== Start Highlighted Text ===============// |
| 33 | $element->start_controls_section( |
| 34 | 'spel_highlighted_text_style', [ |
| 35 | 'label' => esc_html__( 'Highlighted Text', 'spider-elements-pro' ) . SPEL_TEXT_BADGE, |
| 36 | 'tab' => Controls_Manager::TAB_STYLE, |
| 37 | ] |
| 38 | ); |
| 39 | |
| 40 | $element->add_control( |
| 41 | 'spe_highlighted_text_enable', [ |
| 42 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 43 | 'label' => esc_html__( 'Enable Highlighted', 'spider-elements-pro' ), |
| 44 | 'frontend_available' => true, |
| 45 | 'label_on' => esc_html__( 'Enable', 'spider-elements-pro' ), |
| 46 | 'label_off' => esc_html__( 'Disable', 'spider-elements-pro' ), |
| 47 | 'description' => __( 'Highlighted text must be written in <span></span> tag. Example: Welcome to <span>Highlighted</span>', 'spider-elements-pro' ), |
| 48 | 'return_value' => 'yes', |
| 49 | 'default' => 'no', |
| 50 | ] |
| 51 | ); |
| 52 | |
| 53 | $element->add_group_control( |
| 54 | \Elementor\Group_Control_Typography::get_type(), [ |
| 55 | 'name' => 'spe_highlighted_text_typo', |
| 56 | 'selector' => '{{WRAPPER}} .elementor-heading-title span', |
| 57 | 'condition' => [ |
| 58 | 'spe_highlighted_text_enable' => 'yes', |
| 59 | ], |
| 60 | ] |
| 61 | ); |
| 62 | |
| 63 | $element->add_control( |
| 64 | 'spe_highlighted_text_color', [ |
| 65 | 'label' => esc_html__( 'Text Color', 'spider-elements-pro' ), |
| 66 | 'type' => Controls_Manager::COLOR, |
| 67 | 'selectors' => [ |
| 68 | '{{WRAPPER}} .elementor-heading-title span' => 'color: {{VALUE}}', |
| 69 | ], |
| 70 | 'condition' => [ |
| 71 | 'spe_highlighted_text_enable' => 'yes', |
| 72 | ], |
| 73 | ] |
| 74 | ); |
| 75 | |
| 76 | //Background |
| 77 | $element->add_control( |
| 78 | 'spe_highlighted_text_bg_select', [ |
| 79 | 'label' => esc_html__( 'Background Style', 'spider-elements-pro' ), |
| 80 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 81 | 'options' => [ |
| 82 | 'none' => esc_html__( 'None', 'spider-elements-pro' ), |
| 83 | 'bg' => esc_html__( 'Background', 'spider-elements-pro' ), |
| 84 | ], |
| 85 | 'default' => 'none', |
| 86 | 'separator' => 'before', |
| 87 | ] |
| 88 | ); |
| 89 | |
| 90 | |
| 91 | $element->add_group_control( |
| 92 | \Elementor\Group_Control_Background::get_type(), [ |
| 93 | 'name' => 'spe_highlighted_text_bg_color', |
| 94 | 'types' => [ 'classic', 'gradient' ], |
| 95 | 'exclude' => ['image'], |
| 96 | 'selector' => '{{WRAPPER}} .elementor-heading-title span::after', |
| 97 | 'condition' => [ |
| 98 | 'spe_highlighted_text_bg_select' => 'bg', |
| 99 | ], |
| 100 | ] |
| 101 | ); |
| 102 | |
| 103 | $element->add_responsive_control( |
| 104 | 'spe_highlighted_text_bg_width', [ |
| 105 | 'label' => esc_html__( 'Width', 'spider-elements-pro' ), |
| 106 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 107 | 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], |
| 108 | 'range' => [ |
| 109 | 'px' => [ |
| 110 | 'min' => 0, |
| 111 | 'max' => 1000, |
| 112 | 'step' => 5, |
| 113 | ], |
| 114 | '%' => [ |
| 115 | 'min' => 0, |
| 116 | 'max' => 100, |
| 117 | ], |
| 118 | ], |
| 119 | 'default' => [ |
| 120 | 'unit' => '%', |
| 121 | 'size' => '', |
| 122 | ], |
| 123 | 'selectors' => [ |
| 124 | '{{WRAPPER}} .elementor-heading-title span::after' => 'width: {{SIZE}}{{UNIT}};', |
| 125 | ], |
| 126 | 'condition' => [ |
| 127 | 'spe_highlighted_text_bg_select' => 'bg', |
| 128 | ], |
| 129 | ] |
| 130 | ); |
| 131 | |
| 132 | |
| 133 | $element->add_responsive_control( |
| 134 | 'spe_highlighted_text_bg_height', [ |
| 135 | 'label' => esc_html__( 'Height', 'spider-elements-pro' ), |
| 136 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 137 | 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], |
| 138 | 'range' => [ |
| 139 | 'px' => [ |
| 140 | 'min' => 0, |
| 141 | 'max' => 1000, |
| 142 | 'step' => 5, |
| 143 | ], |
| 144 | '%' => [ |
| 145 | 'min' => 0, |
| 146 | 'max' => 100, |
| 147 | ], |
| 148 | ], |
| 149 | 'default' => [ |
| 150 | 'unit' => '%', |
| 151 | 'size' => '', |
| 152 | ], |
| 153 | 'selectors' => [ |
| 154 | '{{WRAPPER}} .elementor-heading-title span::after' => 'height: {{SIZE}}{{UNIT}};', |
| 155 | ], |
| 156 | 'condition' => [ |
| 157 | 'spe_highlighted_text_bg_select' => 'bg', |
| 158 | ], |
| 159 | ] |
| 160 | ); |
| 161 | |
| 162 | $element->add_responsive_control( |
| 163 | 'spe_highlighted_text_bg_bottom', [ |
| 164 | 'label' => esc_html__( 'Bottom', 'spider-elements-pro' ), |
| 165 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 166 | 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], |
| 167 | 'range' => [ |
| 168 | 'px' => [ |
| 169 | 'min' => 0, |
| 170 | 'max' => 1000, |
| 171 | 'step' => 5, |
| 172 | ], |
| 173 | '%' => [ |
| 174 | 'min' => 0, |
| 175 | 'max' => 100, |
| 176 | ], |
| 177 | ], |
| 178 | 'default' => [ |
| 179 | 'unit' => '%', |
| 180 | 'size' => '', |
| 181 | ], |
| 182 | 'selectors' => [ |
| 183 | '{{WRAPPER}} .elementor-heading-title span::after' => 'bottom: {{SIZE}}{{UNIT}};', |
| 184 | ], |
| 185 | 'condition' => [ |
| 186 | 'spe_highlighted_text_bg_select' => 'bg', |
| 187 | ], |
| 188 | ] |
| 189 | ); |
| 190 | |
| 191 | |
| 192 | $element->end_controls_section(); // End Section |
| 193 | |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @param Element_Base $element |
| 198 | * @return void |
| 199 | * Render display content |
| 200 | */ |
| 201 | public function render_display_content( Element_Base $element ): void |
| 202 | { |
| 203 | |
| 204 | $align_class = $element->get_settings_for_display( 'spe_highlighted_text_bg_select' ); |
| 205 | |
| 206 | // It's render adds class for a background |
| 207 | if ( ! empty( $align_class == 'bg' ) ) { |
| 208 | |
| 209 | //It's render elementor wrapper div |
| 210 | $element->add_render_attribute( |
| 211 | '_wrapper', [ |
| 212 | 'class' => 'spe-highlighted-text-bg', |
| 213 | ] |
| 214 | ); |
| 215 | |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | } |