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