| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Widgets; |
| 3 |
use Elementor\Utils; |
| 4 |
use Elementor\Controls_Manager; |
| 5 |
|
| 6 |
defined( 'ABSPATH' ) || die(); |
| 7 |
|
| 8 |
class Easyel_Domain_Search_Widget extends \Elementor\Widget_Base { |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Get widget name. |
| 13 |
* |
| 14 |
* Retrieve widget name. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
* @access public |
| 18 |
* |
| 19 |
* @return string Widget name. |
| 20 |
*/ |
| 21 |
|
| 22 |
public function get_name() { |
| 23 |
return 'eel-domain-search'; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Get widget title. |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @access public |
| 32 |
* |
| 33 |
* @return string Widget title. |
| 34 |
*/ |
| 35 |
public function get_title() { |
| 36 |
return esc_html__( 'Domain Search', 'easy-elements' ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get widget icon. |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* @access public |
| 44 |
* |
| 45 |
* @return string Widget icon. |
| 46 |
*/ |
| 47 |
public function get_icon() { |
| 48 |
return 'easyicon easyelIcon-domain-search'; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
public function get_categories() { |
| 53 |
return [ 'easyelements_category' ]; |
| 54 |
} |
| 55 |
|
| 56 |
public function get_keywords() { |
| 57 |
return [ 'search', 'domain', 'input', 'click', 'text' ]; |
| 58 |
} |
| 59 |
|
| 60 |
public function get_style_depends() { |
| 61 |
return [ |
| 62 |
'eel-domain-search', |
| 63 |
]; |
| 64 |
} |
| 65 |
|
| 66 |
protected function register_controls() { |
| 67 |
|
| 68 |
// ===== Content Tab ===== |
| 69 |
$this->start_controls_section( |
| 70 |
'domain_section', |
| 71 |
[ |
| 72 |
'label' => esc_html__( 'Content Settings', 'easy-elements' ), |
| 73 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 74 |
] |
| 75 |
); |
| 76 |
|
| 77 |
$this->add_control( |
| 78 |
'action_url', |
| 79 |
[ |
| 80 |
'label' => esc_html__( 'Action URL', 'easy-elements' ), |
| 81 |
'type' => Controls_Manager::URL, |
| 82 |
'placeholder' => esc_html__( 'https://example.com/search', 'easy-elements' ), |
| 83 |
'default' => [ |
| 84 |
'url' => '#', |
| 85 |
], |
| 86 |
'show_external' => true, |
| 87 |
'description' => esc_html__( 'On submit the form will append ?domain=YOUR_INPUT to this URL. Do not add ?domain= yourself.', 'easy-elements' ), |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
$this->add_control( |
| 92 |
'placeholder_text', |
| 93 |
[ |
| 94 |
'label' => esc_html__( 'Placeholder', 'easy-elements' ), |
| 95 |
'type' => Controls_Manager::TEXT, |
| 96 |
'default' => esc_html__( 'Search domain...', 'easy-elements' ), |
| 97 |
] |
| 98 |
); |
| 99 |
|
| 100 |
$this->add_control( |
| 101 |
'button_text', |
| 102 |
[ |
| 103 |
'label' => esc_html__( 'Button Text', 'easy-elements' ), |
| 104 |
'type' => Controls_Manager::TEXT, |
| 105 |
'default' => esc_html__( 'Create my website', 'easy-elements' ), |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'show_search_icon', |
| 111 |
[ |
| 112 |
'label' => esc_html__( 'Show Search Icon', 'easy-elements' ), |
| 113 |
'type' => Controls_Manager::SWITCHER, |
| 114 |
'label_on' => esc_html__( 'Show', 'easy-elements' ), |
| 115 |
'label_off' => esc_html__( 'Hide', 'easy-elements' ), |
| 116 |
'return_value' => 'yes', |
| 117 |
'default' => 'yes', |
| 118 |
'description' => esc_html__( 'Toggle the magnifier icon inside the input.', 'easy-elements' ), |
| 119 |
] |
| 120 |
); |
| 121 |
|
| 122 |
$this->end_controls_section(); |
| 123 |
|
| 124 |
// ===== Style Tab — Input ===== |
| 125 |
$this->start_controls_section( |
| 126 |
'input_style_section', |
| 127 |
[ |
| 128 |
'label' => esc_html__( 'Input Style', 'easy-elements' ), |
| 129 |
'tab' => Controls_Manager::TAB_STYLE, |
| 130 |
] |
| 131 |
); |
| 132 |
|
| 133 |
$this->add_control( |
| 134 |
'input_text_color', |
| 135 |
[ |
| 136 |
'label' => __('Input Text Color', 'easy-elements'), |
| 137 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 138 |
'selectors' => [ |
| 139 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]' => 'color: {{VALUE}};', |
| 140 |
], |
| 141 |
] |
| 142 |
); |
| 143 |
|
| 144 |
$this->add_control( |
| 145 |
'input_placeholder_color', |
| 146 |
[ |
| 147 |
'label' => __('Placeholder Color', 'easy-elements'), |
| 148 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 149 |
'selectors' => [ |
| 150 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]::placeholder' => 'color: {{VALUE}}; opacity: 1;', |
| 151 |
], |
| 152 |
] |
| 153 |
); |
| 154 |
|
| 155 |
$this->add_control( |
| 156 |
'input_bg_color', |
| 157 |
[ |
| 158 |
'label' => __('Input Background', 'easy-elements'), |
| 159 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 160 |
'selectors' => [ |
| 161 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]' => 'background-color: {{VALUE}};', |
| 162 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]:hover' => 'background-color: {{VALUE}};', |
| 163 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]:focus' => 'background-color: {{VALUE}};', |
| 164 |
], |
| 165 |
] |
| 166 |
); |
| 167 |
|
| 168 |
$this->add_group_control( |
| 169 |
\Elementor\Group_Control_Typography::get_type(), |
| 170 |
[ |
| 171 |
'name' => 'input_typography', |
| 172 |
'label' => __( 'Typography', 'easy-elements' ), |
| 173 |
'selector' => '{{WRAPPER}} .eel-domain-search form input[type="text"]', |
| 174 |
] |
| 175 |
); |
| 176 |
|
| 177 |
$this->add_group_control( |
| 178 |
\Elementor\Group_Control_Border::get_type(), |
| 179 |
[ |
| 180 |
'name' => 'input_border', |
| 181 |
'label' => __( 'Border', 'easy-elements' ), |
| 182 |
'selector' => '{{WRAPPER}} .eel-domain-search form input[type="text"]', |
| 183 |
] |
| 184 |
); |
| 185 |
|
| 186 |
$this->add_responsive_control( |
| 187 |
'input_border_radius', |
| 188 |
[ |
| 189 |
'label' => __( 'Border Radius', 'easy-elements' ), |
| 190 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 191 |
'size_units' => [ 'px', '%' ], |
| 192 |
'selectors' => [ |
| 193 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 194 |
], |
| 195 |
] |
| 196 |
); |
| 197 |
|
| 198 |
$this->add_responsive_control( |
| 199 |
'input_padding', |
| 200 |
[ |
| 201 |
'label' => __( 'Padding', 'easy-elements' ), |
| 202 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 203 |
'size_units' => [ 'px', 'em', '%' ], |
| 204 |
'selectors' => [ |
| 205 |
'{{WRAPPER}} .eel-domain-search form input[type="text"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 206 |
], |
| 207 |
] |
| 208 |
); |
| 209 |
|
| 210 |
$this->add_control( |
| 211 |
'input_icon_color', |
| 212 |
[ |
| 213 |
'label' => __('Search Icon Color', 'easy-elements'), |
| 214 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 215 |
'selectors' => [ |
| 216 |
'{{WRAPPER}} .eel-domain-search .unicon-search' => 'color: {{VALUE}};', |
| 217 |
], |
| 218 |
'condition' => [ |
| 219 |
'show_search_icon' => 'yes', |
| 220 |
], |
| 221 |
] |
| 222 |
); |
| 223 |
|
| 224 |
$this->add_responsive_control( |
| 225 |
'input_icon_size', |
| 226 |
[ |
| 227 |
'label' => __( 'Search Icon Size', 'easy-elements' ), |
| 228 |
'type' => \Elementor\Controls_Manager::SLIDER, |
| 229 |
'size_units' => [ 'px', 'em' ], |
| 230 |
'range' => [ |
| 231 |
'px' => [ 'min' => 8, 'max' => 60 ], |
| 232 |
], |
| 233 |
'selectors' => [ |
| 234 |
'{{WRAPPER}} .eel-domain-search .unicon-search' => 'font-size: {{SIZE}}{{UNIT}};', |
| 235 |
], |
| 236 |
'condition' => [ |
| 237 |
'show_search_icon' => 'yes', |
| 238 |
], |
| 239 |
] |
| 240 |
); |
| 241 |
|
| 242 |
$this->end_controls_section(); |
| 243 |
|
| 244 |
// ===== Style Tab — Button ===== |
| 245 |
$this->start_controls_section( |
| 246 |
'button_style_section', |
| 247 |
[ |
| 248 |
'label' => esc_html__( 'Button Style', 'easy-elements' ), |
| 249 |
'tab' => Controls_Manager::TAB_STYLE, |
| 250 |
] |
| 251 |
); |
| 252 |
|
| 253 |
$this->start_controls_tabs('button_style_tabs'); |
| 254 |
|
| 255 |
// Normal tab |
| 256 |
$this->start_controls_tab( |
| 257 |
'button_normal_tab', |
| 258 |
[ |
| 259 |
'label' => __('Normal', 'easy-elements'), |
| 260 |
] |
| 261 |
); |
| 262 |
|
| 263 |
// Button background color (Normal) |
| 264 |
$this->add_control( |
| 265 |
'button_bg_color', |
| 266 |
[ |
| 267 |
'label' => __('Background', 'easy-elements'), |
| 268 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 269 |
'selectors' => [ |
| 270 |
'{{WRAPPER}} .eel-domain-search form button' => 'background-color: {{VALUE}};', |
| 271 |
], |
| 272 |
] |
| 273 |
); |
| 274 |
|
| 275 |
// Button text color (Normal) |
| 276 |
$this->add_control( |
| 277 |
'button_text_color', |
| 278 |
[ |
| 279 |
'label' => __('Text Color', 'easy-elements'), |
| 280 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 281 |
'selectors' => [ |
| 282 |
'{{WRAPPER}} .eel-domain-search form button' => 'color: {{VALUE}};', |
| 283 |
], |
| 284 |
] |
| 285 |
); |
| 286 |
|
| 287 |
$this->add_group_control( |
| 288 |
\Elementor\Group_Control_Typography::get_type(), |
| 289 |
[ |
| 290 |
'name' => 'btn_typography', |
| 291 |
'label' => __( 'Typography', 'easy-elements' ), |
| 292 |
'selector' => '{{WRAPPER}} .eel-domain-search form button', |
| 293 |
] |
| 294 |
); |
| 295 |
|
| 296 |
$this->add_group_control( |
| 297 |
\Elementor\Group_Control_Border::get_type(), |
| 298 |
[ |
| 299 |
'name' => 'btn_border', |
| 300 |
'label' => __( 'Border', 'easy-elements' ), |
| 301 |
'selector' => '{{WRAPPER}} .eel-domain-search form button', |
| 302 |
] |
| 303 |
); |
| 304 |
|
| 305 |
$this->add_responsive_control( |
| 306 |
'btn_border_radius', |
| 307 |
[ |
| 308 |
'label' => __( 'Border Radius', 'easy-elements' ), |
| 309 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 310 |
'size_units' => [ 'px', '%' ], |
| 311 |
'selectors' => [ |
| 312 |
'{{WRAPPER}} .eel-domain-search form button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 313 |
], |
| 314 |
] |
| 315 |
); |
| 316 |
|
| 317 |
$this->add_responsive_control( |
| 318 |
'btn_padding', |
| 319 |
[ |
| 320 |
'label' => __( 'Padding', 'easy-elements' ), |
| 321 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 322 |
'size_units' => [ 'px', 'em', '%' ], |
| 323 |
'selectors' => [ |
| 324 |
'{{WRAPPER}} .eel-domain-search form button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 325 |
], |
| 326 |
] |
| 327 |
); |
| 328 |
|
| 329 |
$this->end_controls_tab(); |
| 330 |
|
| 331 |
// Hover tab |
| 332 |
$this->start_controls_tab( |
| 333 |
'button_hover_tab', |
| 334 |
[ |
| 335 |
'label' => __('Hover', 'easy-elements'), |
| 336 |
] |
| 337 |
); |
| 338 |
|
| 339 |
// Button background color (Hover) |
| 340 |
$this->add_control( |
| 341 |
'button_bg_hover_color', |
| 342 |
[ |
| 343 |
'label' => __('Background', 'easy-elements'), |
| 344 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 345 |
'selectors' => [ |
| 346 |
'{{WRAPPER}} .eel-domain-search form button:hover' => 'background-color: {{VALUE}};', |
| 347 |
], |
| 348 |
] |
| 349 |
); |
| 350 |
|
| 351 |
// Button text color (Hover) |
| 352 |
$this->add_control( |
| 353 |
'button_text_hover_color', |
| 354 |
[ |
| 355 |
'label' => __('Text Color', 'easy-elements'), |
| 356 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 357 |
'selectors' => [ |
| 358 |
'{{WRAPPER}} .eel-domain-search form button:hover' => 'color: {{VALUE}};', |
| 359 |
], |
| 360 |
] |
| 361 |
); |
| 362 |
|
| 363 |
$this->add_group_control( |
| 364 |
\Elementor\Group_Control_Border::get_type(), |
| 365 |
[ |
| 366 |
'name' => 'btn_border_hover', |
| 367 |
'label' => __( 'Border', 'easy-elements' ), |
| 368 |
'selector' => '{{WRAPPER}} .eel-domain-search form button:hover', |
| 369 |
] |
| 370 |
); |
| 371 |
|
| 372 |
$this->end_controls_tab(); |
| 373 |
$this->end_controls_tabs(); |
| 374 |
|
| 375 |
$this->end_controls_section(); |
| 376 |
} |
| 377 |
|
| 378 |
protected function render() { |
| 379 |
$settings = $this->get_settings_for_display(); |
| 380 |
$base_url = ! empty( $settings['action_url']['url'] ) ? $settings['action_url']['url'] : '#'; |
| 381 |
$placeholder = ! empty( $settings['placeholder_text'] ) ? $settings['placeholder_text'] : 'Search domain...'; |
| 382 |
$button_text = ! empty( $settings['button_text'] ) ? $settings['button_text'] : 'Create my website'; |
| 383 |
$show_icon = ! isset( $settings['show_search_icon'] ) || $settings['show_search_icon'] === 'yes'; |
| 384 |
?> |
| 385 |
<div class="eel-domain-search"> |
| 386 |
<form method="get" action="<?php echo esc_url( $base_url ); ?>" target="_blank"> |
| 387 |
<?php if ( $show_icon ) : ?> |
| 388 |
<i class="unicon-search"></i> |
| 389 |
<?php endif; ?> |
| 390 |
<input type="text" name="domain" placeholder="<?php echo esc_attr( $placeholder ); ?>" required> |
| 391 |
<button type="submit"><?php echo esc_html( $button_text ); ?></button> |
| 392 |
</form> |
| 393 |
</div> |
| 394 |
<?php |
| 395 |
} |
| 396 |
} |