| 1 |
<?php |
| 2 |
namespace UiCoreElements\Utils; |
| 3 |
|
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Utils; |
| 6 |
use Elementor\Repeater; |
| 7 |
use Elementor\Group_Control_Image_Size; |
| 8 |
use Elementor\Group_Control_Box_Shadow; |
| 9 |
use Elementor\Group_Control_Css_Filter; |
| 10 |
|
| 11 |
defined('ABSPATH') || exit(); |
| 12 |
|
| 13 |
trait Logo_Trait { |
| 14 |
|
| 15 |
// Settings |
| 16 |
function TRAIT_register_logo_repeater_controls($logo) |
| 17 |
{ |
| 18 |
$this->start_controls_section( |
| 19 |
'section_logo', |
| 20 |
[ |
| 21 |
'label' => __( $logo, 'uicore-elements' ), |
| 22 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 23 |
] |
| 24 |
); |
| 25 |
|
| 26 |
$repeater = new Repeater(); |
| 27 |
$repeater->add_control( |
| 28 |
'title', |
| 29 |
[ |
| 30 |
'label' => __( 'Title', 'uicore-elements' ), |
| 31 |
'type' => Controls_Manager::TEXT, |
| 32 |
] |
| 33 |
); |
| 34 |
$repeater->add_control( |
| 35 |
'image', |
| 36 |
[ |
| 37 |
'label' => __( 'Logo Image', 'uicore-elements' ), |
| 38 |
'type' => Controls_Manager::MEDIA, |
| 39 |
'default' => [ |
| 40 |
'url' => Utils::get_placeholder_image_src(), |
| 41 |
], |
| 42 |
] |
| 43 |
); |
| 44 |
$repeater->add_control( |
| 45 |
'link', |
| 46 |
[ |
| 47 |
'label' => __( 'Website URL', 'uicore-elements' ), |
| 48 |
'type' => Controls_Manager::URL, |
| 49 |
'show_external' => false, |
| 50 |
'label_block' => false, |
| 51 |
] |
| 52 |
); |
| 53 |
$this->add_control( |
| 54 |
'logo_list', |
| 55 |
[ |
| 56 |
'show_label' => false, |
| 57 |
'type' => Controls_Manager::REPEATER, |
| 58 |
'fields' => $repeater->get_controls(), |
| 59 |
'title_field' => "{{{ title }}}", |
| 60 |
'default' => [ |
| 61 |
[ |
| 62 |
'title' => __( 'Item 1', 'uicore-elements' ), |
| 63 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 64 |
], |
| 65 |
[ |
| 66 |
'title' => __( 'Item 2', 'uicore-elements' ), |
| 67 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 68 |
], |
| 69 |
[ |
| 70 |
'title' => __( 'Item 3', 'uicore-elements' ), |
| 71 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 72 |
], |
| 73 |
[ |
| 74 |
'title' => __( 'Item 4', 'uicore-elements' ), |
| 75 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 76 |
], |
| 77 |
[ |
| 78 |
'title' => __( 'Item 5', 'uicore-elements' ), |
| 79 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 80 |
], |
| 81 |
[ |
| 82 |
'title' => __( 'Item 6', 'uicore-elements' ), |
| 83 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 84 |
], |
| 85 |
[ |
| 86 |
'title' => __( 'Item 7', 'uicore-elements' ), |
| 87 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 88 |
], |
| 89 |
[ |
| 90 |
'title' => __( 'Item 8', 'uicore-elements' ), |
| 91 |
'image' => [ 'url' => Utils::get_placeholder_image_src() ] |
| 92 |
], |
| 93 |
] |
| 94 |
] |
| 95 |
); |
| 96 |
$this->end_controls_section(); |
| 97 |
} |
| 98 |
function TRAIT_register_logo_adittional_controls() |
| 99 |
{ |
| 100 |
$this->add_group_control( |
| 101 |
Group_Control_Image_Size::get_type(), |
| 102 |
[ |
| 103 |
'name' => 'thumbnail', |
| 104 |
'default' => 'large', |
| 105 |
'default' => 'medium', |
| 106 |
'exclude' => [ |
| 107 |
'custom' |
| 108 |
] |
| 109 |
] |
| 110 |
); |
| 111 |
$this->add_responsive_control( |
| 112 |
'height', |
| 113 |
[ |
| 114 |
'label' => __( 'Item Height', 'uicore-elements' ), |
| 115 |
'type' => Controls_Manager::SLIDER, |
| 116 |
'size_units' => [ 'px' ], |
| 117 |
'range' => [ |
| 118 |
'px' => [ |
| 119 |
'max' => 500, |
| 120 |
'min' => 100, |
| 121 |
] |
| 122 |
], |
| 123 |
'selectors' => [ |
| 124 |
'{{WRAPPER}} .ui-e-item' => 'height: {{SIZE}}{{UNIT}};' |
| 125 |
], |
| 126 |
] |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
// Grid Styles |
| 131 |
function TRAIT_register_logos_grid_style_controls() |
| 132 |
{ |
| 133 |
$this->start_controls_tabs( 'logos_style' ); |
| 134 |
|
| 135 |
$this->start_controls_tab( |
| 136 |
'tab_logos_style_normal', |
| 137 |
[ |
| 138 |
'label' => __( 'Normal', 'uicore-elements' ), |
| 139 |
] |
| 140 |
); |
| 141 |
|
| 142 |
$this->add_control( |
| 143 |
'item_bg_color', |
| 144 |
[ |
| 145 |
'label' => __( 'Background Color', 'uicore-elements' ), |
| 146 |
'type' => Controls_Manager::COLOR, |
| 147 |
'selectors' => [ |
| 148 |
'{{WRAPPER}} figure' => 'background-color: {{VALUE}};', |
| 149 |
], |
| 150 |
] |
| 151 |
); |
| 152 |
// Using Group Control Border overlays script border styling |
| 153 |
$this->add_control( |
| 154 |
'item_border_type', |
| 155 |
[ |
| 156 |
'label' => __( 'Border Type', 'bdthemes-element-pack' ), |
| 157 |
'type' => Controls_Manager::SELECT, |
| 158 |
'options' => [ |
| 159 |
'none' => __( 'None', 'bdthemes-element-pack' ), |
| 160 |
'solid' => __( 'Solid', 'bdthemes-element-pack' ), |
| 161 |
'double' => __( 'Double', 'bdthemes-element-pack' ), |
| 162 |
'dotted' => __( 'Dotted', 'bdthemes-element-pack' ), |
| 163 |
'dashed' => __( 'Dashed', 'bdthemes-element-pack' ), |
| 164 |
'groove' => __( 'Groove', 'bdthemes-element-pack' ), |
| 165 |
], |
| 166 |
'default' => 'solid', |
| 167 |
'selectors' => [ |
| 168 |
'{{WRAPPER}} .ui-e-item' => 'border-style: {{VALUE}};', |
| 169 |
], |
| 170 |
] |
| 171 |
); |
| 172 |
$this->add_responsive_control( |
| 173 |
'item_border_width', |
| 174 |
[ |
| 175 |
'label' => __( 'Border Width', 'bdthemes-element-pack' ), |
| 176 |
'type' => Controls_Manager::SLIDER, |
| 177 |
'default' => [ |
| 178 |
'size' => 2, |
| 179 |
], |
| 180 |
'tablet_default' => [ |
| 181 |
'size' => 2, |
| 182 |
], |
| 183 |
'mobile_default' => [ |
| 184 |
'size' => 2, |
| 185 |
], |
| 186 |
'range' => [ |
| 187 |
'px' => [ |
| 188 |
'min' => 0, |
| 189 |
'max' => 50, |
| 190 |
], |
| 191 |
], |
| 192 |
'selectors' => [ |
| 193 |
'{{WRAPPER}}' => '--ui-e-border-width: {{SIZE}}{{UNIT}};' |
| 194 |
], |
| 195 |
'condition' => [ |
| 196 |
'item_border_type!' => 'none', |
| 197 |
] |
| 198 |
] |
| 199 |
); |
| 200 |
$this->add_control( |
| 201 |
'item_border_color', |
| 202 |
[ |
| 203 |
'label' => __( 'Border Color', 'bdthemes-element-pack' ), |
| 204 |
'type' => Controls_Manager::COLOR, |
| 205 |
'selectors' => [ |
| 206 |
'{{WRAPPER}} .ui-e-item' => 'border-color: {{VALUE}};', |
| 207 |
], |
| 208 |
'default' => '#EEE', |
| 209 |
'condition' => [ |
| 210 |
'item_border_type!' => 'none', |
| 211 |
] |
| 212 |
] |
| 213 |
); |
| 214 |
$this->add_responsive_control( |
| 215 |
'item_border_radius', |
| 216 |
[ |
| 217 |
'label' => __( 'Border Radius', 'uicore-elements' ), |
| 218 |
'type' => Controls_Manager::DIMENSIONS, |
| 219 |
'size_units' => [ 'px', '%' ], |
| 220 |
'default' => [ |
| 221 |
'top' => 5, |
| 222 |
'right' => 5, |
| 223 |
'bottom' => 5, |
| 224 |
'left' => 5, |
| 225 |
'unit' => 'px', |
| 226 |
'isLinked' => true, |
| 227 |
], |
| 228 |
'selectors' => [ |
| 229 |
// each side is used separately by logo-grid script |
| 230 |
'{{WRAPPER}}' => '--ui-e-top-radius: {{TOP}}{{UNIT}}; |
| 231 |
--ui-e-right-radius: {{RIGHT}}{{UNIT}}; |
| 232 |
--ui-e-left-radius: {{LEFT}}{{UNIT}}; |
| 233 |
--ui-e-bottom-radius: {{BOTTOM}}{{UNIT}}; |
| 234 |
--ui-e-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 235 |
], |
| 236 |
] |
| 237 |
); |
| 238 |
$this->add_responsive_control( |
| 239 |
'item_padding', |
| 240 |
[ |
| 241 |
'label' => __( 'Padding', 'uicore-elements' ), |
| 242 |
'type' => Controls_Manager::DIMENSIONS, |
| 243 |
'size_units' => [ 'px', 'em', '%' ], |
| 244 |
'default' => [ |
| 245 |
'top' => 20, |
| 246 |
'right' => 20, |
| 247 |
'bottom' => 20, |
| 248 |
'left' => 20, |
| 249 |
'unit' => 'px', |
| 250 |
'isLinked' => true, |
| 251 |
], |
| 252 |
'selectors' => [ |
| 253 |
'{{WRAPPER}} figure' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 254 |
], |
| 255 |
] |
| 256 |
); |
| 257 |
$this->add_group_control( |
| 258 |
Group_Control_Box_Shadow::get_type(), |
| 259 |
[ |
| 260 |
'name' => 'logos_box_shadow_item', |
| 261 |
'exclude' => [ |
| 262 |
'box_shadow_position', |
| 263 |
], |
| 264 |
'selector' => '{{WRAPPER}} .ui-e-item', |
| 265 |
'condition' => [ |
| 266 |
'layout' => 'inner-border' |
| 267 |
], |
| 268 |
] |
| 269 |
); |
| 270 |
$this->add_group_control( |
| 271 |
Group_Control_Box_Shadow::get_type(), |
| 272 |
[ |
| 273 |
'name' => 'logos_box_shadow_wrapper', |
| 274 |
'exclude' => [ |
| 275 |
'box_shadow_position', |
| 276 |
], |
| 277 |
'selector' => '{{WRAPPER}} .ui-e-grid', |
| 278 |
'condition' => [ |
| 279 |
'layout!' => 'inner-border' |
| 280 |
], |
| 281 |
] |
| 282 |
); |
| 283 |
$this->TRAIT_register_logos_image_style_controls('normal'); |
| 284 |
$this->end_controls_tab(); |
| 285 |
|
| 286 |
$this->start_controls_tab( |
| 287 |
'tab_logos_style_hover', |
| 288 |
[ |
| 289 |
'label' => __( 'Hover', 'uicore-elements' ), |
| 290 |
] |
| 291 |
); |
| 292 |
$this->add_control( |
| 293 |
'item_bg_hover_color', |
| 294 |
[ |
| 295 |
'label' => __( 'Background Color', 'uicore-elements' ), |
| 296 |
'type' => Controls_Manager::COLOR, |
| 297 |
'selectors' => [ |
| 298 |
'{{WRAPPER}} .ui-e-item:hover figure' => 'background-color: {{VALUE}};', |
| 299 |
], |
| 300 |
] |
| 301 |
); |
| 302 |
$this->add_control( |
| 303 |
'grid_border_hover_color', |
| 304 |
[ |
| 305 |
'label' => __( 'Border Color', 'uicore-elements' ), |
| 306 |
'type' => Controls_Manager::COLOR, |
| 307 |
'selectors' => [ |
| 308 |
'{{WRAPPER}} .ui-e-item:hover' => 'border-color: {{VALUE}};', |
| 309 |
], |
| 310 |
'condition' => [ |
| 311 |
'item_border_type!' => 'none', |
| 312 |
'layout' => 'inner-border', |
| 313 |
] |
| 314 |
] |
| 315 |
); |
| 316 |
$this->TRAIT_register_logos_image_style_controls('hover'); |
| 317 |
$this->end_controls_tab(); |
| 318 |
|
| 319 |
$this->end_controls_tabs(); |
| 320 |
} |
| 321 |
// Logo Image Styles |
| 322 |
function TRAIT_register_logos_image_style_controls($state) |
| 323 |
{ |
| 324 |
if($state == 'normal'){ |
| 325 |
$this->add_group_control( |
| 326 |
Group_Control_Css_Filter::get_type(), |
| 327 |
[ |
| 328 |
'name' => 'image_css_filters', |
| 329 |
'selector' => '{{WRAPPER}} figure img', |
| 330 |
] |
| 331 |
); |
| 332 |
$this->add_responsive_control( |
| 333 |
'image_size', |
| 334 |
[ |
| 335 |
'label' => __( 'Image Size', 'uicore-elements' ), |
| 336 |
'type' => Controls_Manager::SLIDER, |
| 337 |
'size_units' => [ 'px', '%' ], |
| 338 |
'range' => [ |
| 339 |
'px' => [ |
| 340 |
'min' => 10, |
| 341 |
'max' => 500, |
| 342 |
], |
| 343 |
'%' => [ |
| 344 |
'min' => 0, |
| 345 |
'max' => 100, |
| 346 |
], |
| 347 |
], |
| 348 |
'selectors' => [ |
| 349 |
'{{WRAPPER}} img' => 'height: {{SIZE}}{{UNIT}}; width: {{SIZE}}{{UNIT}}; object-fit: contain;' |
| 350 |
], |
| 351 |
] |
| 352 |
); |
| 353 |
} else if ($state == 'hover'){ |
| 354 |
$this->add_group_control( |
| 355 |
Group_Control_Css_Filter::get_type(), |
| 356 |
[ |
| 357 |
'name' => 'image_css_filters_hover', |
| 358 |
'selector' => '{{WRAPPER}} figure:hover img', |
| 359 |
] |
| 360 |
); |
| 361 |
$this->add_control( |
| 362 |
'image_bg_hover_transition', |
| 363 |
[ |
| 364 |
'label' => __( 'Transition Duration', 'uicore-elements' ), |
| 365 |
'type' => Controls_Manager::SLIDER, |
| 366 |
'range' => [ |
| 367 |
'px' => [ |
| 368 |
'max' => 3, |
| 369 |
'step' => 0.1, |
| 370 |
], |
| 371 |
], |
| 372 |
'selectors' => [ |
| 373 |
'{{WRAPPER}} figure img' => 'transition-duration: {{SIZE}}s;', |
| 374 |
], |
| 375 |
] |
| 376 |
); |
| 377 |
} else if($state == 'active'){ |
| 378 |
$this->add_group_control( |
| 379 |
Group_Control_Css_Filter::get_type(), |
| 380 |
[ |
| 381 |
'name' => 'image_css_filters_active', |
| 382 |
'selector' => '{{WRAPPER}} .is-selected figure img', |
| 383 |
] |
| 384 |
); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
// Rendering |
| 389 |
function render_logo_figure($data, $size) |
| 390 |
{ |
| 391 |
$image = wp_get_attachment_image_url($data['id'], $size); |
| 392 |
$name = isset($data['name']) ? $data['name'] : ''; |
| 393 |
$desc = isset($data['description']) ? $data['description'] : ''; |
| 394 |
$alt = $name . ' : ' . $desc; |
| 395 |
?> |
| 396 |
<figure class="<?php echo esc_attr($this->get_settings_for_display('logo_hover_animation'));?>"> |
| 397 |
<?php |
| 398 |
if($image) { |
| 399 |
echo wp_get_attachment_image( |
| 400 |
$data['id'], |
| 401 |
$size, |
| 402 |
false, |
| 403 |
['alt' => esc_attr( $alt )] |
| 404 |
); |
| 405 |
} else { |
| 406 |
printf( |
| 407 |
'<img src="%s" alt="%s">', |
| 408 |
Utils::get_placeholder_image_src(), |
| 409 |
esc_attr( $alt ) |
| 410 |
); |
| 411 |
} |
| 412 |
?> |
| 413 |
</figure> |
| 414 |
<?php |
| 415 |
} |
| 416 |
function TRAIT_render_logo_item() |
| 417 |
{ |
| 418 |
$settings = $this->get_settings_for_display(); |
| 419 |
|
| 420 |
// Get entrance and item hover animation classes |
| 421 |
$entrance = (isset($settings['animate_items']) && $settings['animate_items'] == 'ui-e-grid-animate') ? 'elementor-invisible' : ''; |
| 422 |
$hover = isset($settings['item_hover_animation']) ? $settings['item_hover_animation'] : null; |
| 423 |
$animations = sprintf('%s %s', $entrance, $hover); |
| 424 |
|
| 425 |
// Check if any animation that relies on the animation wrapper is set |
| 426 |
$has_animation = !empty($entrance) || !empty($hover) || !empty($settings['item_hover_animation']) || !empty($settings['logo_hover_animation']); |
| 427 |
|
| 428 |
// Build wrapper class |
| 429 |
$is_carousel = strpos($this->get_name(), 'carousel') !== false; |
| 430 |
$this->add_render_attribute([ |
| 431 |
'wrapper' => [ |
| 432 |
'class' => $is_carousel ? 'ui-e-wrp swiper-slide' : 'ui-e-wrp', |
| 433 |
], |
| 434 |
]); |
| 435 |
|
| 436 |
// TODO: remove `ui-e-item-wrp`, at least, 2 releases after 1.0.6 |
| 437 |
foreach ( $settings['logo_list'] as $index => $item ) { |
| 438 |
|
| 439 |
// Params |
| 440 |
$key = 'logo_'.$index; |
| 441 |
$tag = 'div '; |
| 442 |
$this->add_render_attribute($key, 'class', ['ui-e-item', 'ui-e-item-wrp'] ); |
| 443 |
|
| 444 |
// Build URL |
| 445 |
if (!empty($item['link']['url'])) { |
| 446 |
$tag = 'a '; |
| 447 |
$this->add_link_attributes($key, $item['link'] ); |
| 448 |
} |
| 449 |
?> |
| 450 |
<div <?php $this->print_render_attribute_string('wrapper'); ?>> |
| 451 |
<?php if($has_animation) : ?> |
| 452 |
<div class='ui-e-animations-wrp <?php echo esc_attr($animations);?>'> |
| 453 |
<?php endif; ?> |
| 454 |
<<?php echo esc_html($tag);?> <?php $this->print_render_attribute_string($key); ?>> |
| 455 |
<?php $this->render_logo_figure($item['image'], $settings['thumbnail_size']); ?> |
| 456 |
</<?php echo esc_html($tag);?>> |
| 457 |
<?php if($has_animation) : ?> |
| 458 |
</div> |
| 459 |
<?php endif; ?> |
| 460 |
</div> |
| 461 |
<?php |
| 462 |
} |
| 463 |
} |
| 464 |
} |