PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.3
UiCore Elements – Free widgets and templates for Elementor v1.2.3
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / widgets / highlighted-text.php

highlighted-text.php in UiCore Elements – Free widgets and templates for Elementor 1.2.3, at includes/widgets/highlighted-text.php

615 lines 18.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Repeater;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
8 use UiCoreElements\UiCoreWidget;
9
10 defined('ABSPATH') || exit();
11
12 /**
13 * Highlighted Text
14 *
15 * @author Andrei Voica <andrei@uicore.co>
16 * @since 1.0.3
17 */
18 class HighlightedText extends UiCoreWidget
19 {
20 public function __construct($data = [], $args = null)
21 {
22 parent::__construct($data, $args);
23 }
24
25 public function get_name()
26 {
27 return 'highlighted-text';
28 }
29 public function get_categories()
30 {
31 return ['uicore'];
32 }
33
34 public function get_title()
35 {
36 return __('Highlighted Text', 'uicore-elements');
37 }
38
39 public function get_icon()
40 {
41 return 'eicon-animated-headline ui-e-widget';
42 }
43
44 public function get_keywords()
45 {
46 return [ 'headline', 'heading', 'animation', 'title', 'text' ];
47 }
48
49 public function get_styles() {
50 return [
51 'highlighted-text'
52 ];
53 }
54
55 public function get_scripts()
56 {
57 return [
58 'highlighted-text' => [
59 'condition' => [
60 'shape_animation' => 'animate',
61 ],
62 ]
63 ];
64 }
65 public function has_widget_inner_wrapper(): bool {
66 // TODO: remove after 3.30, when the full deprecation of widget innet wrapper is ready
67 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
68 }
69
70 protected function register_controls()
71 {
72 $this->start_controls_section(
73 'text_elements',
74 [
75 'label' => __( 'Text', 'uicore-elements' ),
76 ]
77 );
78 $repeater = new Repeater();
79
80 $repeater->add_control(
81 'type',
82 [
83 'label' => esc_html__( 'Type', 'uicore-elements' ),
84 'type' => \Elementor\Controls_Manager::SELECT,
85 'default' => 'text',
86 'options' => [
87 'text' => esc_html__( 'Text', 'uicore-elements' ),
88 'icon' => esc_html__( 'Icon', 'uicore-elements' ),
89 'image' => esc_html__( 'Image', 'uicore-elements' ),
90 ],
91 'selectors' => [
92 '{{WRAPPER}} .uicore-repeater-selector' => 'border-style: {{VALUE}};',
93 ],
94 'render_type' => 'template',
95 ]
96 );
97
98 $repeater->add_control(
99 'text',
100 [
101 'label' => __( 'Text', 'uicore-elements' ),
102 'type' => Controls_Manager::TEXT,
103 'label_block' => true,
104 'placeholder' => __( 'Some Text', 'uicore-elements' ),
105 'default' => __( 'Some Text', 'uicore-elements' ),
106 'condition' => [ 'type' => 'text' ],
107 ]
108 );
109
110 $repeater->add_control(
111 'headline_style',
112 [
113 'label' => __( 'Highlight Style', 'uicore-elements' ),
114 'type' => Controls_Manager::SELECT,
115 'default' => 'none',
116 'options' => [
117 'none' => __( 'None', 'uicore-elements' ),
118 'color' => __( 'No Stroke', 'uicore-elements' ),
119 'stroke1' => __( 'Stroke 1', 'uicore-elements' ),
120 'stroke2' => __( 'Stroke 2', 'uicore-elements' ),
121 'stroke3' => __( 'Stroke 3', 'uicore-elements' ),
122 'stroke4' => __( 'Stroke 4', 'uicore-elements' ),
123 'stroke5' => __( 'Stroke 5', 'uicore-elements' ),
124 'stroke6' => __( 'Stroke 6', 'uicore-elements' ),
125 'stroke7' => __( 'Stroke 7', 'uicore-elements' ),
126 'stroke8' => __( 'Stroke 8', 'uicore-elements' ),
127 'stroke9' => __( 'Stroke 9', 'uicore-elements' ),
128 ],
129 'render_type' => 'template',
130 'condition' => [ 'type' => 'text' ],
131 ]
132 );
133
134 $repeater->add_control(
135 'icon',
136 [
137 'label' => esc_html__( 'Icon', 'uicore-elements' ),
138 'type' => \Elementor\Controls_Manager::ICONS,
139 'default' => [
140 'value' => 'fas fa-circle',
141 'library' => 'fa-solid',
142 ],
143 'recommended' => [
144 'fa-solid' => [
145 'circle',
146 'dot-circle',
147 'square-full',
148 ],
149 'fa-regular' => [
150 'circle',
151 'dot-circle',
152 'square-full',
153 ],
154 ],
155 'condition' => [ 'type' => 'icon' ],
156 ]
157 );
158
159 $repeater->add_control(
160 'icon_color',
161 [
162 'label' => esc_html__( 'Color', 'uicore-elements' ),
163 'type' => \Elementor\Controls_Manager::COLOR,
164 'selectors' => [
165 '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}}' => 'color: {{VALUE}}; fill: {{VALUE}}', //icon as a font + svg
166
167 ],
168 'condition' => [ 'type' => ['icon','text'] ],
169 ]
170 );
171 $repeater->add_group_control(
172 \Elementor\Group_Control_Background::get_type(),
173 [
174 'name' => 'background_color',
175 'condition' => [ 'type' => ['icon','text'] ],
176 'selector' => '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}} .ui-e-headline-text',
177 ]
178 );
179 $repeater->add_control(
180 'background_color_as_text',
181 [
182 'label' => esc_html__( 'Use Background Color as Text Color', 'uicore-elements' ),
183 'type' => \Elementor\Controls_Manager::SWITCHER,
184 'default' => false,
185 'render_type' => 'template',
186 'condition' => [ 'type' => ['icon','text'] ],
187 'selectors' => [
188 '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}} .ui-e-headline-text' => 'background-color: transparent;-webkit-background-clip: text;background-clip: text;-webkit-text-fill-color: transparent;',
189 ],
190 ]
191 );
192 $repeater->add_control(
193 'stroke_color',
194 [
195 'label' => esc_html__( 'Stroke Color', 'uicore-elements' ),
196 'type' => \Elementor\Controls_Manager::COLOR,
197 'selectors' => [
198 '{{WRAPPER}} {{CURRENT_ITEM}} svg path' => 'stroke: {{VALUE}}',
199
200 ],
201 'condition' => [ 'headline_style!' => ['none','color'] ],
202 ]
203 );
204
205 $repeater->add_control(
206 'image',
207 [
208 'label' => esc_html__( 'Choose Image', 'uicore-elements' ),
209 'type' => \Elementor\Controls_Manager::MEDIA,
210 'default' => [
211 'url' => \Elementor\Utils::get_placeholder_image_src(),
212 ],
213 'condition' => [ 'type' => 'image' ],
214 ]
215 );
216
217 $repeater->add_control(
218 'size',
219 [
220 'label' => __('Size', 'uicore-elements'),
221 'type' => \Elementor\Controls_Manager::SLIDER,
222 'default' => [
223 'size' => 100,
224 'unit' => '%',
225 ],
226 'range' => [
227 '%' => [
228 'min' => 0,
229 'max' => 150,
230 ],
231 ],
232 'selectors' => [
233 '{{WRAPPER}} {{CURRENT_ITEM}}' => '--ui-e-asset-size: calc({{SIZE}} / 100);',
234 ],
235 'condition' => [ 'type' => ['icon', 'image'] ],
236 ]
237 );
238
239 $this->add_control(
240 'content',
241 [
242 'label' => __( 'Content', 'uicore-elements' ),
243 'type' => Controls_Manager::REPEATER,
244 'fields' => $repeater->get_controls(),
245 'default' => [
246 [
247 'text' => __( 'This is my awesome', 'uicore-elements' ),
248 'headline_style' => 'none',
249 ],
250 [
251 'text' => __( 'highlight', 'uicore-elements' ),
252 'headline_style' => 'stroke1',
253 ],
254 [
255 'text' => __( 'text.', 'uicore-elements' ),
256 'headline_style' => 'none',
257 ],
258 ],
259 'title_field' => '{{{ type == "text" ? text : type }}}',
260 'render_type' => 'template',
261 ]
262 );
263
264 $this->add_responsive_control(
265 'alignment',
266 [
267 'label' => __( 'Alignment', 'uicore-elements' ),
268 'type' => Controls_Manager::CHOOSE,
269 'options' => [
270 'left' => [
271 'title' => __( 'Left', 'uicore-elements' ),
272 'icon' => 'eicon-text-align-left',
273 ],
274 'center' => [
275 'title' => __( 'Center', 'uicore-elements' ),
276 'icon' => 'eicon-text-align-center',
277 ],
278 'right' => [
279 'title' => __( 'Right', 'uicore-elements' ),
280 'icon' => 'eicon-text-align-right',
281 ],
282 ],
283 'default' => 'center',
284 'selectors' => [
285 '{{WRAPPER}}' => 'text-align: {{VALUE}}',
286 ],
287 ]
288 );
289
290 $this->add_control(
291 'tag',
292 [
293 'label' => __( 'HTML Tag', 'uicore-elements' ),
294 'type' => Controls_Manager::SELECT,
295 'options' => [
296 'h1' => 'H1',
297 'h2' => 'H2',
298 'h3' => 'H3',
299 'h4' => 'H4',
300 'h5' => 'H5',
301 'h6' => 'H6',
302 'div' => 'div',
303 'span' => 'span',
304 'p' => 'p',
305 ],
306 'default' => 'h2',
307 ]
308 );
309
310 $this->end_controls_section();
311
312 $this->start_controls_section(
313 'section_style_marker',
314 [
315 'label' => __( 'Shape', 'uicore-elements' ),
316 'tab' => Controls_Manager::TAB_STYLE,
317 ]
318 );
319
320 $this->add_control(
321 'marker_color',
322 [
323 'label' => __( 'Color', 'uicore-elements' ),
324 'type' => Controls_Manager::COLOR,
325 'global' => [
326 'default' => '#F1F200',
327 ],
328 'selectors' => [
329 '{{WRAPPER}} .ui-e-headline-text path' => 'stroke: {{VALUE}}',
330 ],
331 ]
332 );
333
334 $this->add_control(
335 'stroke_width',
336 [
337 'label' => __( 'Width', 'uicore-elements' ),
338 'type' => Controls_Manager::SLIDER,
339 'range' => [
340 'px' => [
341 'min' => 1,
342 'max' => 100,
343 ],
344 ],
345 'default' => [
346 'size' => '40',
347 'unit' => 'px'
348 ],
349 'selectors' => [
350 '{{WRAPPER}} .ui-e-headline-text path' => 'stroke-width: {{SIZE}}',
351 ],
352 ]
353 );
354
355 $this->add_control(
356 'vertical_offset',
357 [
358 'label' => __( 'Vertical Offset', 'uicore-elements' ),
359 'type' => Controls_Manager::SLIDER,
360 'range' => [
361 '%' => [
362 'min' => -100,
363 'max' => 100,
364 ],
365 'px' => [
366 'min' => -100,
367 'max' => 100,
368 ],
369 ],
370 'default' => [
371 'size' => '0',
372 'unit' => '%',
373 ],
374 'size_units'=>['%', 'px'],
375 'selectors' => [
376 '{{WRAPPER}} .ui-e-headline-text svg' => 'bottom: {{SIZE}}{{UNIT}}',
377 ],
378 ]
379 );
380 $this->add_control(
381 'shape_animation',
382 [
383 'label' => __( 'Animation', 'uicore-elements' ),
384 'type' => Controls_Manager::SWITCHER,
385 'label_on' => __( 'On', 'uicore-elements' ),
386 'label_off' => __( 'Off', 'uicore-elements' ),
387 'default' => 'animate',
388 'separator' => 'before',
389 'return_value' =>'animate',
390 'prefix_class' => 'ui-e-a-',
391 ]
392 );
393
394 $this->add_control(
395 'shape_animation_delay',
396 [
397 'label' => __( 'Animation Delay', 'uicore-elements' ) . ' (ms)',
398 'type' => Controls_Manager::NUMBER,
399 'default' => '',
400 'min' => 0,
401 'step' => 100,
402 'condition' => [
403 'shape_animation' => 'animate',
404 ],
405 'render_type' => 'template'
406 ]
407 );
408
409
410 $this->end_controls_section();
411
412 $this->start_controls_section(
413 'section_style_text',
414 [
415 'label' => __( 'Headline', 'uicore-elements' ),
416 'tab' => Controls_Manager::TAB_STYLE,
417 ]
418 );
419
420 $this->add_control(
421 'title_color',
422 [
423 'label' => __( 'Text Color', 'uicore-elements' ),
424 'type' => Controls_Manager::COLOR,
425 'selectors' => [
426 '{{WRAPPER}} .ui-e-highlight-icon, {{WRAPPER}} .ui-e-headline-text' => 'color: {{VALUE}}',
427 ],
428 ]
429 );
430
431
432 $this->add_group_control(
433 Group_Control_Typography::get_type(),
434 [
435 'name' => 'title_typography',
436 'selector' => '{{WRAPPER}} .ui-e-highlight-icon, {{WRAPPER}} .ui-e-headline-text, {{WRAPPER}} .ui-e-highlight-image',
437 ]
438 );
439
440 $this->add_control(
441 'higlighted_title_color',
442 [
443 'label' => __( 'Highlighted Text Color', 'uicore-elements' ),
444 'type' => Controls_Manager::COLOR,
445 'selectors' => [
446 '{{WRAPPER}} .ui-e-headline-highlighted' => 'color: {{VALUE}}',
447 ],
448 ]
449 );
450 $this->add_group_control(
451 Group_Control_Typography::get_type(),
452 [
453 'name' => 'higlighted_title_typography',
454 'selector' => '{{WRAPPER}} .ui-e-headline-highlighted',
455 ]
456 );
457
458
459 $this->end_controls_section();
460
461
462 }
463
464
465 protected function get_svg($return,$type='')
466 {
467 $paths = [
468 'none'=> null,
469 'color'=> null,
470 'stroke1'=>"<path d='M15.2,133.3L15.2,133.3c121.9-7.6,244-9.9,366.1-6.8c34.6,0.9,69.1,2.3,103.7,4'/>",
471
472 'stroke2'=>"<path d='M479,122c-13.3-1-26.8-1-40.4-2.3c-31.8-1.2-63.7,0.4-95.3,0.6c-38.5,1.5-77,2.3-115.5,5.2
473 c-41.6,1.2-83.3,5-124.9,5.2c-5.4,0.4-11,1-16.4,0.8c-21.9-0.4-44.1,1.9-65.6-3.5'/>",
474
475 'stroke3'=>"<path d='M15,133.4c19-12.7,48.1-11.4,69.2-8.2
476 c6.3,1.1,12.9,2.1,19.2,3.4c16.5,3.2,33.5,6.3,50.6,5.5c12.7-0.6,24.9-3.4,36.7-6.1c11-2.5,22.4-5.1,34.2-5.9
477 c24.3-1.9,48.5,3.4,71.9,8.4c27.6,6.1,53.8,11.8,80.4,6.8c9.9-1.9,19.2-5.3,28.3-8.4c8.2-3,16.9-5.9,25.9-8
478 c20.3-4.4,45.8-1.1,53.6,12.2'/>",
479
480 'stroke4'=>"<path d='M18,122.6c42.3-4.6,87.4-5.1,130.3-1.6'/>
481 <path d='M166.7,121.3c29.6,1.6,60,3.3,90.1,1.8c12.4-0.5,24.8-1.6,36.9-2.7c7.3-0.7,14.8-1.3,22.3-1.8
482 c55.5-4.2,112.6-1.8,166,1.1'/>
483 <path d='M57.8,133c30.8-0.7,62,1.1,92.1,2.7c30.5,1.8,62,3.6,93.2,2.7c20.4-0.5,41.1-2.4,61.1-4
484 c37.6-3.1,76.5-6.4,113.7-2'/>",
485
486 'stroke5'=>"<path d='M53.4,135.8c-12.8-1.5-25.6-1.3-38.3,0.7'/>
487 <path d='M111.2,136c-12.2-0.2-24.4-0.5-36.7-0.8'/>
488 <path d='M163.3,135.2c-12.2,0.2-24.4,0.5-36.6,0.8'/>
489 <path d='M217.8,134.7c-12.5,0.6-24.9,1.2-37.4,1.8'/>
490 <path d='M274.7,135.5c-12.8,0.1-25.5,0.1-38.3,0.2'/>
491 <path d='M327.6,135.1c-13.6-0.8-27.2-0.3-40.7,1.4'/>
492 <path d='M378.8,134.7c-12.2,0.6-24.4,1.2-36.6,1.8'/>
493 <path d='M432.5,136.4c-12.2-0.6-24.4-1.1-36.6-1.7'/>
494 <path d='M487.9,136.1c-11.6-1.3-23.3-1.4-35-0.2'/>",
495
496 'stroke6'=>"<path d='M14.4,111.6c0,0,202.9-33.7,471.2,0c0,0-194-8.9-397.3,24.7c0,0,141.9-5.9,309.2,0'/>",
497
498 'stroke7'=>"<path d='M15.2 133.3H485'/>",
499 'stroke8'=>'<path d="M1.65186 148.981C1.65186 148.981 73.8781 98.5943 206.859 93.0135C339.841 87.4327 489.874 134.065 489.874 134.065"/>',
500 'stroke9'=>'<path d="M7 74.5C7 74.5 104 127 252 117C400 107 494.5 49 494.5 49C494.5 49 473.5 59 461.5 74.5C449.5 90 449.5 107 449.5 107"/>
501 <path d="M20.5 101.5C20.5 101.5 93 133.5 180.5 142.5C268 151.5 347 127.5 347 127.5"/>'
502 ];
503
504 if($return === 'list'){
505 foreach($paths as $name => $path){
506 if($name === 'none'){
507 $svg[$name] = "";
508 }else{
509 $svg[$name] = '<span class="uicore-svg-wrapper"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 150" preserveAspectRatio="none">'.$path.'</svg></span>';
510 }
511 }
512 }else{
513 if($type === 'none'){
514 $svg = "";
515 }else{
516 $svg = '<span class="uicore-svg-wrapper"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 150" preserveAspectRatio="none">'.$paths[$type].'</svg></span>';
517 }
518 }
519
520 return $svg;
521 }
522
523 protected function render()
524 {
525 $settings = $this->get_settings_for_display();
526 $tag = $settings['tag'];
527 $content = $settings['content'];
528 $delay = $settings['shape_animation_delay'];
529 ?>
530 <<?php echo esc_html($tag); echo $delay ? ' data-delay="'.esc_attr($delay).'"' : ''; ?> class="ui-e--highlighted-text" >
531 <?php
532
533
534 foreach($content as $item){
535 $svg_markup = null;
536 switch ($item['type']) {
537 case 'text':
538 if($item['headline_style'] === 'none'){
539 echo '<span class="ui-e-headline-text elementor-repeater-item-'
540 . esc_attr($item['_id']) . '">'
541 . Helper::esc_string($item['text']) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
542 . '</span>';
543 }else{
544 $svg_markup = $this->get_svg('single',$item['headline_style']);
545 echo '<span class="ui-e-headline-text elementor-repeater-item-'
546 . esc_attr($item['_id'])
547 . ' ui-e-headline-'.esc_attr($item['headline_style']).'">
548 <span class="whitespace"></span>
549 <span>
550 <span class="ui-e-headline-text ui-e-headline-highlighted">'
551 . Helper::esc_string($item['text']) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
552 .'</span>'
553 . Helper::esc_svg($svg_markup) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
554 .'</span> <span class="whitespace"> </span></span>';
555 }
556 break;
557 case 'icon':
558 echo "<span class='ui-e-highlight-icon elementor-repeater-item-" . esc_attr($item['_id']) . "'>";
559 \Elementor\Icons_Manager::render_icon($item['icon'], ['aria-hidden' => 'true', 'class'=>'char']);
560 echo "</span>";
561 break;
562 case 'image':
563 echo '<span class="ui-e-highlight-image elementor-repeater-item-' . esc_attr($item['_id']) . '">'.wp_get_attachment_image($item['image']['id'], "medium", false, ["loading" => false, "class"=>'char']).'</span>';
564 break;
565 default:
566 break;
567 }
568
569 }
570 ?>
571 </<?php echo esc_html($tag); ?>>
572 <?php
573
574 }
575 protected function content_template() {
576 ?>
577 <#
578 var svgs = <?php echo wp_json_encode($this->get_svg('list')); ?>;
579 #>
580 <{{{ settings.tag }}} class="ui-e--highlighted-text">
581 <#
582 settings.content.forEach( function (item){
583 switch (item.type) {
584 case 'text':
585 if(item.headline_style === 'none'){
586 #><span class="ui-e-headline-text elementor-repeater-item-{{{ item._id }}}">{{{ item.text }}}</span><#
587 }else{
588 #><span class="ui-e-headline-text {{{ 'ui-e-headline-' + item.headline_style }}} elementor-repeater-item-{{{ item._id }}}"><span class="whitespace"> </span><span><span class="ui-e-headline-text ui-e-headline-highlighted">{{{ item.text }}}</span>{{{svgs[item.headline_style]}}}</span><span class="whitespace"> </span></span><#
589 }
590 break;
591 case 'icon':
592 #><span class="char ui-e-highlight-icon elementor-repeater-item-{{{ item._id }}}">{{{ elementor.helpers.renderIcon( view, item.icon, { 'aria-hidden': true }, 'i' , 'value' ) }}}</span><#
593 break;
594 case 'image':
595 var image = {
596 id: item.image.id,
597 url: item.image.url,
598 size: item.thumbnail_size,
599 dimension: item.thumbnail_custom_dimension,
600 model: view.getEditModel()
601 };
602 var image_url = elementor.imagesManager.getImageUrl( image );
603 #><span class="ui-e-highlight-image elementor-repeater-item-{{{ item._id }}}"><img class="char" src="{{{ image_url }}}" /></span><#
604 break;
605 default:
606 break;
607 }
608 });
609 #>
610 </{{{ settings.tag }}}>
611 <?php
612 }
613 }
614 \Elementor\Plugin::instance()->widgets_manager->register(new HighlightedText());
615