| 1 |
<?php |
| 2 |
namespace UiCoreElements\Utils; |
| 3 |
|
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Utils; |
| 6 |
use Elementor\Repeater; |
| 7 |
use Elementor\Control_Media; |
| 8 |
use Elementor\Group_Control_Image_Size; |
| 9 |
use Elementor\Group_Control_Box_Shadow; |
| 10 |
use Elementor\Group_Control_Border; |
| 11 |
use Elementor\Group_Control_Typography; |
| 12 |
use Elementor\Group_Control_Background; |
| 13 |
use Elementor\Core\Kits\Documents\Tabs\Global_Colors; |
| 14 |
use UiCoreElements\Helper; |
| 15 |
|
| 16 |
use UiCoreElements\Utils\Carousel_Trait; |
| 17 |
|
| 18 |
|
| 19 |
defined('ABSPATH') || exit(); |
| 20 |
|
| 21 |
/** |
| 22 |
* Gallery Component |
| 23 |
* |
| 24 |
* @since 1.0.14 |
| 25 |
*/ |
| 26 |
|
| 27 |
|
| 28 |
trait Gallery_Trait { |
| 29 |
|
| 30 |
use Carousel_Trait; |
| 31 |
|
| 32 |
// Controls Registration |
| 33 |
function TRAIT_register_gallery_repeater_controls($title) |
| 34 |
{ |
| 35 |
$this->start_controls_section( |
| 36 |
'content_section', |
| 37 |
[ |
| 38 |
/* translators: %s: Control title */ |
| 39 |
'label' => esc_html( sprintf('%s', $title), 'uicore-elements'), |
| 40 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 41 |
] |
| 42 |
); |
| 43 |
|
| 44 |
$repeater = new Repeater(); |
| 45 |
$repeater->add_control( |
| 46 |
'item_image', |
| 47 |
[ |
| 48 |
'label' => esc_html__('Image', 'uicore-elements'), |
| 49 |
'type' => Controls_Manager::MEDIA, |
| 50 |
'default' => [ |
| 51 |
'url' => Utils::get_placeholder_image_src(), |
| 52 |
], |
| 53 |
] |
| 54 |
); |
| 55 |
$repeater->add_control( |
| 56 |
'item_url', |
| 57 |
[ |
| 58 |
'label' => esc_html__('Link', 'uicore-elements'), |
| 59 |
'type' => Controls_Manager::URL, |
| 60 |
'placeholder' => 'https://your-link.com', |
| 61 |
] |
| 62 |
); |
| 63 |
$repeater->add_control( |
| 64 |
'item_title', |
| 65 |
[ |
| 66 |
'label' => esc_html__('Title', 'uicore-elements'), |
| 67 |
'type' => Controls_Manager::TEXT, |
| 68 |
'default' => esc_html__('Title', 'uicore-elements'), |
| 69 |
'label_block' => true, |
| 70 |
] |
| 71 |
); |
| 72 |
$repeater->add_control( |
| 73 |
'item_description', |
| 74 |
[ |
| 75 |
'label' => esc_html__('Description', 'uicore-elements'), |
| 76 |
'type' => Controls_Manager::TEXTAREA, |
| 77 |
'label_block' => true, |
| 78 |
] |
| 79 |
); |
| 80 |
$repeater->add_control( |
| 81 |
'item_badge', |
| 82 |
[ |
| 83 |
'label' => esc_html__('Badge', 'uicore-elements'), |
| 84 |
'type' => Controls_Manager::TEXT, |
| 85 |
'label_block' => true, |
| 86 |
] |
| 87 |
); |
| 88 |
$repeater->add_control( |
| 89 |
'item_tags', |
| 90 |
[ |
| 91 |
'label' => esc_html__('Tags', 'uicore-elements'), |
| 92 |
'type' => Controls_Manager::TEXT, |
| 93 |
'description' => esc_html__('Separate tags with commas', 'uicore-elements'), |
| 94 |
'label_block' => true, |
| 95 |
] |
| 96 |
); |
| 97 |
|
| 98 |
$this->add_control( |
| 99 |
'gallery_items', |
| 100 |
[ |
| 101 |
'label' => esc_html__('Items', 'uicore-elements'), |
| 102 |
'type' => Controls_Manager::REPEATER, |
| 103 |
'fields' => $repeater->get_controls(), |
| 104 |
'default' => [ |
| 105 |
[ |
| 106 |
'item_title' => esc_html__('Item #1', 'uicore-elements'), |
| 107 |
], |
| 108 |
[ |
| 109 |
'item_title' => esc_html__('Item #2', 'uicore-elements'), |
| 110 |
], |
| 111 |
[ |
| 112 |
'item_title' => esc_html__('Item #3', 'uicore-elements'), |
| 113 |
], |
| 114 |
[ |
| 115 |
'item_title' => esc_html__('Item #4', 'uicore-elements'), |
| 116 |
], |
| 117 |
[ |
| 118 |
'item_title' => esc_html__('Item #5', 'uicore-elements'), |
| 119 |
], |
| 120 |
[ |
| 121 |
'item_title' => esc_html__('Item #6', 'uicore-elements'), |
| 122 |
], |
| 123 |
], |
| 124 |
'title_field' => '{{{ item_title }}}', |
| 125 |
] |
| 126 |
); |
| 127 |
|
| 128 |
$this->end_controls_section(); |
| 129 |
} |
| 130 |
function TRAIT_register_additional_controls($carousel = false) |
| 131 |
{ |
| 132 |
$this->start_controls_section( |
| 133 |
'additional_section', |
| 134 |
[ |
| 135 |
'label' => esc_html__('Additional', 'uicore-elements'), |
| 136 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 137 |
] |
| 138 |
); |
| 139 |
$this->add_control( |
| 140 |
'layout', |
| 141 |
[ |
| 142 |
'label' => esc_html__('Layout', 'uicore-elements'), |
| 143 |
'type' => Controls_Manager::SELECT, |
| 144 |
'default' => '', |
| 145 |
'prefix_class' => '', |
| 146 |
'render_type' => 'template', |
| 147 |
'options' => [ |
| 148 |
'' => esc_html__('Default', 'uicore-elements'), |
| 149 |
'ui-e-overlay' => esc_html__('Overlay', 'uicore-elements'), |
| 150 |
], |
| 151 |
] |
| 152 |
); |
| 153 |
|
| 154 |
$this->add_control( |
| 155 |
'item_overflow', |
| 156 |
[ |
| 157 |
'label' => esc_html__('Hide overflow', 'uicore-elements'), |
| 158 |
'type' => Controls_Manager::SWITCHER, |
| 159 |
'default' => 'no', |
| 160 |
'prefix_class' => 'ui-e-overflow-', |
| 161 |
'description' => __('Useful if you have an animation, on an image, for example, that surpasses the item area and you want to hide it.', 'uicore-elements'), |
| 162 |
'condition' => [ |
| 163 |
'layout' => '', |
| 164 |
] |
| 165 |
] |
| 166 |
); |
| 167 |
|
| 168 |
$this->add_control( |
| 169 |
'hide_tags', |
| 170 |
[ |
| 171 |
'label' => __('Hide item tags', 'uicore-elements'), |
| 172 |
'type' => Controls_Manager::SWITCHER, |
| 173 |
'separator' => 'before', |
| 174 |
'default' => 'no', |
| 175 |
] |
| 176 |
); |
| 177 |
|
| 178 |
if( ! $carousel ){ |
| 179 |
$this->add_control( |
| 180 |
'filters', |
| 181 |
[ |
| 182 |
'label' => __('Use filters', 'uicore-elements'), |
| 183 |
'type' => Controls_Manager::SWITCHER, |
| 184 |
'default' => 'no', |
| 185 |
] |
| 186 |
); |
| 187 |
$this->add_control( |
| 188 |
'clear_text', |
| 189 |
[ |
| 190 |
'label' => __('Clear Text', 'uicore-elements'), |
| 191 |
'type' => Controls_Manager::TEXT, |
| 192 |
'default' => __('All', 'uicore-elements'), |
| 193 |
'placeholder' => __('Clear filter text', 'uicore-elements'), |
| 194 |
'condition' => [ |
| 195 |
'filters' => 'yes' |
| 196 |
] |
| 197 |
] |
| 198 |
); |
| 199 |
} |
| 200 |
|
| 201 |
$this->add_control( |
| 202 |
'title_tag', |
| 203 |
[ |
| 204 |
'label' => esc_html__('Title Tag', 'uicore-elements'), |
| 205 |
'type' => Controls_Manager::SELECT, |
| 206 |
'default' => 'h4', |
| 207 |
'options' => Helper::get_title_tags(), |
| 208 |
'separator' => 'before' |
| 209 |
] |
| 210 |
); |
| 211 |
$this->add_control( |
| 212 |
'image_size', |
| 213 |
[ |
| 214 |
'label' => esc_html__('Image Size', 'uicore-elements'), |
| 215 |
'type' => Controls_Manager::SELECT, |
| 216 |
'default' => 'uicore-medium', |
| 217 |
'options' => Helper::get_images_sizes(), |
| 218 |
] |
| 219 |
); |
| 220 |
$this->add_control( |
| 221 |
'badge_position', |
| 222 |
[ |
| 223 |
'label' => esc_html__('Badge Position', 'uicore-elements'), |
| 224 |
'type' => Controls_Manager::SELECT, |
| 225 |
'default' => 'ui-e-badge-start-left', |
| 226 |
'prefix_class' => '', |
| 227 |
'render_type' => 'template', // without it, loading a page with image and changing to title won't work |
| 228 |
'options' => [ |
| 229 |
'' => __('After title', 'uicore-elements'), |
| 230 |
'ui-e-badge-start-left' => __('Image top left', 'uicore-elements'), |
| 231 |
'ui-e-badge-start-right' => __('Image top right', 'uicore-elements'), |
| 232 |
'ui-e-badge-end-left' => __('Image bottom left', 'uicore-elements'), |
| 233 |
'ui-e-badge-end-right' => __('Image bottom right', 'uicore-elements'), |
| 234 |
], |
| 235 |
] |
| 236 |
); |
| 237 |
|
| 238 |
$this->end_controls_section(); |
| 239 |
} |
| 240 |
|
| 241 |
function TRAIT_register_filters_style_controls() |
| 242 |
{ |
| 243 |
$this->start_controls_section( |
| 244 |
'style_filters_section', |
| 245 |
[ |
| 246 |
'label' => __('Filters', 'uicore-elements'), |
| 247 |
'tab' => Controls_Manager::TAB_STYLE, |
| 248 |
'condition' => [ |
| 249 |
'filters' => 'yes', |
| 250 |
], |
| 251 |
] |
| 252 |
); |
| 253 |
|
| 254 |
$this->add_responsive_control( |
| 255 |
'filters_align', |
| 256 |
[ |
| 257 |
'label' => esc_html__( 'Alignment', 'uicore-elements' ), |
| 258 |
'type' => Controls_Manager::CHOOSE, |
| 259 |
'options' => [ |
| 260 |
'start' => [ |
| 261 |
'title' => esc_html__( 'Left', 'uicore-elements' ), |
| 262 |
'icon' => 'eicon-h-align-left', |
| 263 |
], |
| 264 |
'center' => [ |
| 265 |
'title' => esc_html__( 'Center', 'uicore-elements' ), |
| 266 |
'icon' => 'eicon-h-align-center', |
| 267 |
], |
| 268 |
'end' => [ |
| 269 |
'title' => esc_html__( 'Right', 'uicore-elements' ), |
| 270 |
'icon' => 'eicon-h-align-right', |
| 271 |
], |
| 272 |
], |
| 273 |
'default' => 'center', |
| 274 |
'selectors' => [ |
| 275 |
'(desktop){{WRAPPER}} .ui-e-filters' => 'justify-content: {{VALUE}}', |
| 276 |
'(mobile){{WRAPPER}} .ui-e-filters' => 'align-items: {{VALUE}}' // mobile version sets flex-direction as column |
| 277 |
] |
| 278 |
] |
| 279 |
); |
| 280 |
$this->add_control( |
| 281 |
'filters_bottom_space', |
| 282 |
[ |
| 283 |
'label' => __('Spacing', 'uicore-elements'), |
| 284 |
'type' => Controls_Manager::SLIDER, |
| 285 |
'range' => [ |
| 286 |
'px' => [ |
| 287 |
'min' => 0, |
| 288 |
'max' => 50, |
| 289 |
], |
| 290 |
], |
| 291 |
'default' => [ |
| 292 |
'size' => 10, |
| 293 |
'unit' => 'px' |
| 294 |
], |
| 295 |
'selectors' => [ |
| 296 |
'{{WRAPPER}} .ui-e-filters' => 'margin-bottom: {{SIZE}}{{UNIT}};', |
| 297 |
], |
| 298 |
] |
| 299 |
); |
| 300 |
|
| 301 |
$this->start_controls_tabs( |
| 302 |
'filters_tabs', |
| 303 |
[ |
| 304 |
'condition' => [ |
| 305 |
'filters' => 'yes', |
| 306 |
], |
| 307 |
] |
| 308 |
); |
| 309 |
|
| 310 |
$this->start_controls_tab( |
| 311 |
'filters_normal_tab', |
| 312 |
[ |
| 313 |
'label' => esc_html__( 'Normal', 'uicore-elements' ), |
| 314 |
] |
| 315 |
); |
| 316 |
|
| 317 |
$this->add_group_control( |
| 318 |
Group_Control_Typography::get_type(), |
| 319 |
[ |
| 320 |
'name' => 'filters_typography', |
| 321 |
'selector' => '{{WRAPPER}} .ui-e-filters button', |
| 322 |
] |
| 323 |
); |
| 324 |
$this->add_control( |
| 325 |
'filters_color', |
| 326 |
[ |
| 327 |
'label' => __('Color', 'uicore-elements'), |
| 328 |
'type' => Controls_Manager::COLOR, |
| 329 |
'selectors' => [ |
| 330 |
'{{WRAPPER}} .ui-e-filters button' => 'color: {{VALUE}};', |
| 331 |
], |
| 332 |
] |
| 333 |
); |
| 334 |
$this->add_group_control( |
| 335 |
Group_Control_Background::get_type(), |
| 336 |
[ |
| 337 |
'name' => 'filters_background', |
| 338 |
'selector' => '{{WRAPPER}} .ui-e-filters button', |
| 339 |
] |
| 340 |
); |
| 341 |
$this->add_group_control( |
| 342 |
Group_Control_Border::get_type(), |
| 343 |
[ |
| 344 |
'name' => 'filters_border', |
| 345 |
'label' => esc_html__( 'Border', 'uicore-elements' ), |
| 346 |
'selector' => '{{WRAPPER}} .ui-e-filters button', |
| 347 |
] |
| 348 |
); |
| 349 |
$this->add_group_control( |
| 350 |
Group_Control_Box_Shadow::get_type(), |
| 351 |
[ |
| 352 |
'name' => 'filters_box_shadow', |
| 353 |
'selector' => '{{WRAPPER}} .ui-e-filters button', |
| 354 |
] |
| 355 |
); |
| 356 |
|
| 357 |
$this->end_controls_tab(); |
| 358 |
|
| 359 |
$this->start_controls_tab( |
| 360 |
'filters_hover_tab', |
| 361 |
[ |
| 362 |
'label' => esc_html__( 'Hover', 'uicore-elements' ), |
| 363 |
] |
| 364 |
); |
| 365 |
|
| 366 |
$this->add_control( |
| 367 |
'filters_hover_color', |
| 368 |
[ |
| 369 |
'label' => __('Color', 'uicore-elements'), |
| 370 |
'type' => Controls_Manager::COLOR, |
| 371 |
'selectors' => [ |
| 372 |
'{{WRAPPER}} .ui-e-filters button:hover' => 'color: {{VALUE}};', |
| 373 |
], |
| 374 |
] |
| 375 |
); |
| 376 |
$this->add_group_control( |
| 377 |
Group_Control_Background::get_type(), |
| 378 |
[ |
| 379 |
'name' => 'filters_hover_background', |
| 380 |
'selector' => '{{WRAPPER}} .ui-e-filters button:hover', |
| 381 |
] |
| 382 |
); |
| 383 |
$this->add_group_control( |
| 384 |
Group_Control_Border::get_type(), |
| 385 |
[ |
| 386 |
'name' => 'filters_hover_border', |
| 387 |
'label' => esc_html__( 'Border', 'uicore-elements' ), |
| 388 |
'selector' => '{{WRAPPER}} .ui-e-filters button:hover', |
| 389 |
] |
| 390 |
); |
| 391 |
$this->add_group_control( |
| 392 |
Group_Control_Box_Shadow::get_type(), |
| 393 |
[ |
| 394 |
'name' => 'filters_hover_box_shadow', |
| 395 |
'selector' => '{{WRAPPER}} .ui-e-filters button:hover', |
| 396 |
] |
| 397 |
); |
| 398 |
|
| 399 |
$this->end_controls_tab(); |
| 400 |
|
| 401 |
$this->start_controls_tab( |
| 402 |
'filters_active_tab', |
| 403 |
[ |
| 404 |
'label' => esc_html__( 'Active', 'uicore-elements' ), |
| 405 |
] |
| 406 |
); |
| 407 |
|
| 408 |
$this->add_control( |
| 409 |
'filters_active_color', |
| 410 |
[ |
| 411 |
'label' => __('Color', 'uicore-elements'), |
| 412 |
'type' => Controls_Manager::COLOR, |
| 413 |
'selectors' => [ |
| 414 |
'{{WRAPPER}} .ui-e-filters button.ui-e-active' => 'color: {{VALUE}};', |
| 415 |
], |
| 416 |
] |
| 417 |
); |
| 418 |
$this->add_group_control( |
| 419 |
Group_Control_Background::get_type(), |
| 420 |
[ |
| 421 |
'name' => 'filters_active_background', |
| 422 |
'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active', |
| 423 |
] |
| 424 |
); |
| 425 |
$this->add_group_control( |
| 426 |
Group_Control_Border::get_type(), |
| 427 |
[ |
| 428 |
'name' => 'filters_active_border', |
| 429 |
'label' => esc_html__( 'Border', 'uicore-elements' ), |
| 430 |
'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active', |
| 431 |
] |
| 432 |
); |
| 433 |
$this->add_group_control( |
| 434 |
Group_Control_Box_Shadow::get_type(), |
| 435 |
[ |
| 436 |
'name' => 'filters_active_box_shadow', |
| 437 |
'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active', |
| 438 |
] |
| 439 |
); |
| 440 |
|
| 441 |
$this->end_controls_tab(); |
| 442 |
|
| 443 |
$this->end_controls_tabs(); |
| 444 |
|
| 445 |
$this->add_control( |
| 446 |
'filters_separator', |
| 447 |
[ |
| 448 |
'type' => Controls_Manager::DIVIDER, |
| 449 |
] |
| 450 |
); |
| 451 |
|
| 452 |
$this->add_control( |
| 453 |
'filters_border_radius', |
| 454 |
[ |
| 455 |
'label' => esc_html__( 'Border Radius', 'uicore-elements' ), |
| 456 |
'type' => Controls_Manager::DIMENSIONS, |
| 457 |
'size_units' => [ 'px', '%' ], |
| 458 |
'selectors' => [ |
| 459 |
'{{WRAPPER}} .ui-e-filters button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 460 |
], |
| 461 |
] |
| 462 |
); |
| 463 |
$this->add_control( |
| 464 |
'filters_padding', |
| 465 |
[ |
| 466 |
'label' => esc_html__( 'Padding', 'uicore-elements' ), |
| 467 |
'type' => Controls_Manager::DIMENSIONS, |
| 468 |
'size_units' => [ 'px', 'em', '%' ], |
| 469 |
'selectors' => [ |
| 470 |
'{{WRAPPER}} .ui-e-filters button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 471 |
], |
| 472 |
] |
| 473 |
); |
| 474 |
|
| 475 |
$this->end_controls_section(); |
| 476 |
} |
| 477 |
function TRAIT_register_image_style_controls($is_carousel = false) |
| 478 |
{ |
| 479 |
|
| 480 |
// Carousel and grid use different match height controls and logic |
| 481 |
$height_slug = $is_carousel ? 'match_height' : 'masonry'; |
| 482 |
$height_operator = $is_carousel ? '==' : '!=='; |
| 483 |
|
| 484 |
$this->start_controls_section( |
| 485 |
'style_image_section', |
| 486 |
[ |
| 487 |
'label' => __('Image', 'uicore-elements'), |
| 488 |
'tab' => Controls_Manager::TAB_STYLE, |
| 489 |
] |
| 490 |
); |
| 491 |
|
| 492 |
$this->add_responsive_control( |
| 493 |
'image_height', |
| 494 |
[ |
| 495 |
'label' => esc_html__('Image Height', 'uicore-elements'), |
| 496 |
'type' => Controls_Manager::SLIDER, |
| 497 |
'size_units' => ['px', 'em', 'vh'], |
| 498 |
'range' => [ |
| 499 |
'px' => [ |
| 500 |
'min' => 50, |
| 501 |
'max' => 500, |
| 502 |
'step' => 5, |
| 503 |
], |
| 504 |
'em' => [ |
| 505 |
'min' => 5, |
| 506 |
'max' => 30, |
| 507 |
'step' => 1, |
| 508 |
], |
| 509 |
'vh' => [ |
| 510 |
'min' => 5, |
| 511 |
'max' => 50, |
| 512 |
], |
| 513 |
], |
| 514 |
'default' => [ |
| 515 |
'unit' => 'px', |
| 516 |
'size' => 400, |
| 517 |
], |
| 518 |
'selectors' => [ |
| 519 |
'{{WRAPPER}} .ui-e-media-wrp' => 'height: {{SIZE}}{{UNIT}};', |
| 520 |
], |
| 521 |
'conditions' => [ |
| 522 |
'relation' => 'or', |
| 523 |
'terms' => [ |
| 524 |
[ |
| 525 |
'name' => 'layout', |
| 526 |
'operator' => '==', |
| 527 |
'value' => '', |
| 528 |
], |
| 529 |
[ |
| 530 |
'relation' => 'and', |
| 531 |
'terms' => [ |
| 532 |
[ |
| 533 |
'name' => 'layout', |
| 534 |
'operator' => '==', |
| 535 |
'value' => 'ui-e-overlay', |
| 536 |
], |
| 537 |
[ |
| 538 |
'name' => $height_slug, |
| 539 |
'operator' => $height_operator, |
| 540 |
'value' => 'yes', |
| 541 |
] |
| 542 |
], |
| 543 |
], |
| 544 |
], |
| 545 |
], |
| 546 |
] |
| 547 |
); |
| 548 |
$this->add_control( |
| 549 |
'image_position', |
| 550 |
[ |
| 551 |
'label' => esc_html__('Image Position', 'uicore-elements'), |
| 552 |
'type' => Controls_Manager::SELECT, |
| 553 |
'default' => 'center', |
| 554 |
'options' => [ |
| 555 |
'top' => __('Top', 'uicore-elements'), |
| 556 |
'center' => __('Center', 'uicore-elements'), |
| 557 |
'bottom' => __('Bottom', 'uicore-elements'), |
| 558 |
], |
| 559 |
'selectors' => [ |
| 560 |
'{{WRAPPER}} .ui-e-media-wrp' => 'background-position: {{VALUE}};', |
| 561 |
], |
| 562 |
'condition' => [ |
| 563 |
'layout' => 'ui-e-overlay', |
| 564 |
], |
| 565 |
] |
| 566 |
); |
| 567 |
$this->add_control( |
| 568 |
'image_bottom_space', |
| 569 |
[ |
| 570 |
'label' => __('Spacing', 'uicore-elements'), |
| 571 |
'type' => Controls_Manager::SLIDER, |
| 572 |
'range' => [ |
| 573 |
'px' => [ |
| 574 |
'min' => 0, |
| 575 |
'max' => 50, |
| 576 |
], |
| 577 |
], |
| 578 |
'default' => [ |
| 579 |
'size' => 10, |
| 580 |
'unit' => 'px' |
| 581 |
], |
| 582 |
'condition' => [ |
| 583 |
'layout' => '' |
| 584 |
], |
| 585 |
'selectors' => [ |
| 586 |
'{{WRAPPER}}' => '--ui-e-image-spacing: {{SIZE}}{{UNIT}};', |
| 587 |
], |
| 588 |
] |
| 589 |
); |
| 590 |
$this->add_control( |
| 591 |
'image_radius', |
| 592 |
[ |
| 593 |
'label' => esc_html__( 'Border Radius', 'uicore-elements' ), |
| 594 |
'type' => Controls_Manager::DIMENSIONS, |
| 595 |
'size_units' => [ 'px', '%' ], |
| 596 |
'condition' => [ |
| 597 |
'layout' => '' |
| 598 |
], |
| 599 |
'selectors' => [ |
| 600 |
'{{WRAPPER}} .ui-e-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 601 |
], |
| 602 |
] |
| 603 |
); |
| 604 |
$this->add_group_control( |
| 605 |
Group_Control_Box_Shadow::get_type(), |
| 606 |
[ |
| 607 |
'name' => 'image_box_shadow', |
| 608 |
'selector' => '{{WRAPPER}} .ui-e-item img', |
| 609 |
'condition' => [ |
| 610 |
'layout' => '' |
| 611 |
] |
| 612 |
] |
| 613 |
); |
| 614 |
|
| 615 |
$this->end_controls_section(); |
| 616 |
} |
| 617 |
function TRAIT_register_title_style_controls() |
| 618 |
{ |
| 619 |
$this->start_controls_section( |
| 620 |
'style_title_section', |
| 621 |
[ |
| 622 |
'label' => __('Title', 'uicore-elements'), |
| 623 |
'tab' => Controls_Manager::TAB_STYLE, |
| 624 |
] |
| 625 |
); |
| 626 |
|
| 627 |
$this->add_group_control( |
| 628 |
Group_Control_Typography::get_type(), |
| 629 |
[ |
| 630 |
'name' => 'title_typography', |
| 631 |
'selector' => '{{WRAPPER}} .ui-e-title', |
| 632 |
] |
| 633 |
); |
| 634 |
$this->add_control( |
| 635 |
'title_color', |
| 636 |
[ |
| 637 |
'label' => __('Color', 'uicore-elements'), |
| 638 |
'type' => Controls_Manager::COLOR, |
| 639 |
'selectors' => [ |
| 640 |
'{{WRAPPER}} .ui-e-title' => 'color: {{VALUE}};', |
| 641 |
], |
| 642 |
] |
| 643 |
); |
| 644 |
$this->add_control( |
| 645 |
'title_hover_color', |
| 646 |
[ |
| 647 |
'label' => __('Hover Color', 'uicore-elements'), |
| 648 |
'type' => Controls_Manager::COLOR, |
| 649 |
'selectors' => [ |
| 650 |
'{{WRAPPER}} .ui-e-item:hover .ui-e-title' => 'color: {{VALUE}};', |
| 651 |
], |
| 652 |
] |
| 653 |
); |
| 654 |
$this->add_control( |
| 655 |
'title_bottom_space', |
| 656 |
[ |
| 657 |
'label' => __('Spacing', 'uicore-elements'), |
| 658 |
'type' => Controls_Manager::SLIDER, |
| 659 |
'range' => [ |
| 660 |
'px' => [ |
| 661 |
'min' => 0, |
| 662 |
'max' => 50, |
| 663 |
], |
| 664 |
], |
| 665 |
'default' => [ |
| 666 |
'size' => 10, |
| 667 |
'unit' => 'px' |
| 668 |
], |
| 669 |
'selectors' => [ |
| 670 |
'{{WRAPPER}}' => '--ui-e-title-spacing: {{SIZE}}{{UNIT}};', |
| 671 |
], |
| 672 |
] |
| 673 |
); |
| 674 |
|
| 675 |
$this->end_controls_section(); |
| 676 |
} |
| 677 |
function TRAIT_register_description_style_controls() |
| 678 |
{ |
| 679 |
$this->start_controls_section( |
| 680 |
'style_description_section', |
| 681 |
[ |
| 682 |
'label' => __('Description', 'uicore-elements'), |
| 683 |
'tab' => Controls_Manager::TAB_STYLE, |
| 684 |
] |
| 685 |
); |
| 686 |
|
| 687 |
$this->add_group_control( |
| 688 |
Group_Control_Typography::get_type(), |
| 689 |
[ |
| 690 |
'name' => 'description_typography', |
| 691 |
'selector' => '{{WRAPPER}} .ui-e-description', |
| 692 |
] |
| 693 |
); |
| 694 |
$this->add_control( |
| 695 |
'description_color', |
| 696 |
[ |
| 697 |
'label' => __('Color', 'uicore-elements'), |
| 698 |
'type' => Controls_Manager::COLOR, |
| 699 |
'selectors' => [ |
| 700 |
'{{WRAPPER}} .ui-e-description' => 'color: {{VALUE}};', |
| 701 |
], |
| 702 |
] |
| 703 |
); |
| 704 |
$this->add_control( |
| 705 |
'description_bottom_space', |
| 706 |
[ |
| 707 |
'label' => __('Spacing', 'uicore-elements'), |
| 708 |
'type' => Controls_Manager::SLIDER, |
| 709 |
'range' => [ |
| 710 |
'px' => [ |
| 711 |
'min' => 0, |
| 712 |
'max' => 50, |
| 713 |
], |
| 714 |
], |
| 715 |
'default' => [ |
| 716 |
'size' => 10, |
| 717 |
'unit' => 'px' |
| 718 |
], |
| 719 |
'condition' => [ |
| 720 |
'hide_tags!' => 'yes', |
| 721 |
], |
| 722 |
'selectors' => [ |
| 723 |
'{{WRAPPER}} .ui-e-description' => 'padding-bottom: {{SIZE}}{{UNIT}};', |
| 724 |
], |
| 725 |
] |
| 726 |
); |
| 727 |
|
| 728 |
$this->end_controls_section(); |
| 729 |
} |
| 730 |
function TRAIT_register_tags_style_controls() |
| 731 |
{ |
| 732 |
$this->start_controls_section( |
| 733 |
'style_tags_section', |
| 734 |
[ |
| 735 |
'label' => __('Tags', 'uicore-elements'), |
| 736 |
'tab' => Controls_Manager::TAB_STYLE, |
| 737 |
'condition' => [ |
| 738 |
'hide_tags!' => 'yes', |
| 739 |
] |
| 740 |
] |
| 741 |
); |
| 742 |
|
| 743 |
$this->add_group_control( |
| 744 |
Group_Control_Typography::get_type(), |
| 745 |
[ |
| 746 |
'name' => 'tags_typography', |
| 747 |
'selector' => '{{WRAPPER}} .ui-e-tags', |
| 748 |
] |
| 749 |
); |
| 750 |
$this->add_control( |
| 751 |
'tags_color', |
| 752 |
[ |
| 753 |
'label' => __('Color', 'uicore-elements'), |
| 754 |
'type' => Controls_Manager::COLOR, |
| 755 |
'selectors' => [ |
| 756 |
'{{WRAPPER}} .ui-e-tags' => 'color: {{VALUE}};', |
| 757 |
], |
| 758 |
] |
| 759 |
); |
| 760 |
|
| 761 |
$this->end_controls_section(); |
| 762 |
} |
| 763 |
function TRAIT_register_badge_style_controls() |
| 764 |
{ |
| 765 |
$this->start_controls_section( |
| 766 |
'style_badge_section', |
| 767 |
[ |
| 768 |
'label' => __('Badge', 'uicore-elements'), |
| 769 |
'tab' => Controls_Manager::TAB_STYLE, |
| 770 |
] |
| 771 |
); |
| 772 |
|
| 773 |
$this->add_group_control( |
| 774 |
Group_Control_Typography::get_type(), |
| 775 |
[ |
| 776 |
'name' => 'badge_typography', |
| 777 |
'selector' => '{{WRAPPER}} .ui-e-badge', |
| 778 |
] |
| 779 |
); |
| 780 |
$this->add_control( |
| 781 |
'badge_color', |
| 782 |
[ |
| 783 |
'label' => __('Color', 'uicore-elements'), |
| 784 |
'type' => Controls_Manager::COLOR, |
| 785 |
'selectors' => [ |
| 786 |
'{{WRAPPER}} .ui-e-badge' => 'color: {{VALUE}};', |
| 787 |
], |
| 788 |
] |
| 789 |
); |
| 790 |
$this->add_control( |
| 791 |
'badge_background_color', |
| 792 |
[ |
| 793 |
'label' => __('Background Color', 'uicore-elements'), |
| 794 |
'type' => Controls_Manager::COLOR, |
| 795 |
'global' => [ |
| 796 |
'default' => Global_Colors::COLOR_PRIMARY, |
| 797 |
], |
| 798 |
'selectors' => [ |
| 799 |
'{{WRAPPER}} .ui-e-badge' => 'background-color: {{VALUE}};', |
| 800 |
], |
| 801 |
] |
| 802 |
); |
| 803 |
$this->add_group_control( |
| 804 |
Group_Control_Border::get_type(), |
| 805 |
[ |
| 806 |
'name' => 'badge_border', |
| 807 |
'label' => esc_html__( 'Border', 'uicore-elements' ), |
| 808 |
'selector' => '{{WRAPPER}} .ui-e-badge', |
| 809 |
] |
| 810 |
); |
| 811 |
$this->add_control( |
| 812 |
'badge_border_radius', |
| 813 |
[ |
| 814 |
'label' => esc_html__( 'Border Radius', 'uicore-elements' ), |
| 815 |
'type' => Controls_Manager::DIMENSIONS, |
| 816 |
'size_units' => [ 'px', '%' ], |
| 817 |
'default' => [ |
| 818 |
'top' => 4, |
| 819 |
'right' => 4, |
| 820 |
'bottom' => 4, |
| 821 |
'left' => 4, |
| 822 |
], |
| 823 |
'selectors' => [ |
| 824 |
'{{WRAPPER}} .ui-e-badge' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 825 |
], |
| 826 |
] |
| 827 |
); |
| 828 |
$this->add_control( |
| 829 |
'badge_padding', |
| 830 |
[ |
| 831 |
'label' => esc_html__( 'Padding', 'uicore-elements' ), |
| 832 |
'type' => Controls_Manager::DIMENSIONS, |
| 833 |
'size_units' => [ 'px', 'em', '%' ], |
| 834 |
'size_units' => [ 'px', '%' ], |
| 835 |
'default' => [ |
| 836 |
'top' => 3, |
| 837 |
'right' => 10, |
| 838 |
'bottom' => 3, |
| 839 |
'left' => 10, |
| 840 |
'unit' => 'px', |
| 841 |
'isLinked' => false, |
| 842 |
], |
| 843 |
'selectors' => [ |
| 844 |
'{{WRAPPER}} .ui-e-badge' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 845 |
], |
| 846 |
] |
| 847 |
); |
| 848 |
$this->add_group_control( |
| 849 |
Group_Control_Box_Shadow::get_type(), |
| 850 |
[ |
| 851 |
'name' => 'badge_box_shadow', |
| 852 |
'selector' => '{{WRAPPER}} .ui-e-badge', |
| 853 |
] |
| 854 |
); |
| 855 |
|
| 856 |
$this->end_controls_section(); |
| 857 |
} |
| 858 |
function TRAIT_register_gallery_animations() |
| 859 |
{ |
| 860 |
$this->start_controls_section( |
| 861 |
'items_animation', |
| 862 |
[ |
| 863 |
'label' => esc_html__('Animation', 'uicore-elements'), |
| 864 |
'tab' => Controls_Manager::TAB_STYLE, |
| 865 |
] |
| 866 |
); |
| 867 |
$this->TRAIT_register_entrance_animations_controls(); // animate each item |
| 868 |
$this->TRAIT_register_hover_animation_control( |
| 869 |
'Item Hover Animation', |
| 870 |
[], |
| 871 |
['underline'] |
| 872 |
); |
| 873 |
$this->TRAIT_register_hover_animation_control( |
| 874 |
'Image Animation', |
| 875 |
['layout' => ''], |
| 876 |
['underline'] |
| 877 |
); |
| 878 |
// TODO: update all controls below after 'show' is globally implemented |
| 879 |
$this->TRAIT_register_hover_animation_control( |
| 880 |
'Title Animation', |
| 881 |
[], |
| 882 |
['zoom'] |
| 883 |
); |
| 884 |
$this->TRAIT_register_hover_animation_control( |
| 885 |
'Description Animation', |
| 886 |
[], |
| 887 |
['zoom', 'underline'], |
| 888 |
null, |
| 889 |
true |
| 890 |
); |
| 891 |
$this->TRAIT_register_hover_animation_control( |
| 892 |
'Badge Animation', |
| 893 |
[], |
| 894 |
['underline'], |
| 895 |
null, |
| 896 |
true |
| 897 |
); |
| 898 |
$this->TRAIT_register_hover_animation_control( |
| 899 |
'Tags Animation', |
| 900 |
['hide_tags!' => 'yes'], |
| 901 |
['zoom'], |
| 902 |
null, |
| 903 |
true |
| 904 |
); |
| 905 |
|
| 906 |
$this->end_controls_section(); |
| 907 |
} |
| 908 |
|
| 909 |
// Elements rendering |
| 910 |
protected function TRAIT_render_gallery($settings, $is_carousel = false) |
| 911 |
{ |
| 912 |
// Get entrance and item hover animation classes |
| 913 |
$entrance = $this->is_option('animate_items', 'ui-e-grid-animate') ? 'elementor-invisible' : ''; |
| 914 |
$hover = isset($settings['item_hover_animation']) ? $settings['item_hover_animation'] : null; |
| 915 |
$animations = sprintf('%s %s', $entrance, $hover); |
| 916 |
|
| 917 |
// Get all elements animation control options (triggered by .ui-e-animations-wrp:hover) |
| 918 |
$animation_options = [ |
| 919 |
$settings['title_animation'], |
| 920 |
$settings['description_animation'], |
| 921 |
$settings['image_animation'], |
| 922 |
$settings['badge_animation'], |
| 923 |
$settings['tags_animation'], |
| 924 |
]; |
| 925 |
|
| 926 |
// get item animation only if is not slider, |
| 927 |
if (!str_contains($this->get_name(), 'slider')) { |
| 928 |
$animation_options[] = $settings['item_hover_animation']; |
| 929 |
} |
| 930 |
|
| 931 |
// check if any of the animation are set |
| 932 |
$has_animation = array_filter($animation_options, function($value) { |
| 933 |
return $value !== ''; |
| 934 |
}); |
| 935 |
|
| 936 |
// and also check if entrance is set |
| 937 |
$has_animation = $entrance !== '' ? true : $has_animation; |
| 938 |
|
| 939 |
// |
| 940 |
$item_classes = $is_carousel |
| 941 |
? 'ui-e-wrp swiper-slide' |
| 942 |
: 'ui-e-wrp ui-e-filtered'; |
| 943 |
$this->add_render_attribute('item_wrapper', 'class', $item_classes ); |
| 944 |
|
| 945 |
// Render items |
| 946 |
foreach ( $settings['gallery_items'] as $index => $item ) { |
| 947 |
$this->render_item($index, $item, $settings, $has_animation, $animations); |
| 948 |
} |
| 949 |
|
| 950 |
if($is_carousel) { |
| 951 |
$total_slides = count($settings['gallery_items']); |
| 952 |
|
| 953 |
// Most recent swiper versions requires, if loop, at least one extra slide compared to visible slides |
| 954 |
if( $this->TRAIT_should_duplicate_slides($total_slides)) { |
| 955 |
$diff = $this->TRAIT_get_duplication_diff($total_slides); |
| 956 |
for($i = 0; $i <= $diff; $i++){ |
| 957 |
$this->render_item($index, $item, $settings, $has_animation, $animations); |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
protected function render_item($index, $item, $settings, $has_animation, $animations) |
| 964 |
{ |
| 965 |
// Params |
| 966 |
$key = 'item_'.$index; |
| 967 |
$tag = 'div '; |
| 968 |
|
| 969 |
$this->add_render_attribute($key, 'class', 'ui-e-item' ); |
| 970 |
|
| 971 |
// Build URL |
| 972 |
if ( !empty($item['item_url']['url']) ) { |
| 973 |
$tag = 'a '; |
| 974 |
$this->add_link_attributes($key, $item['item_url'] ); |
| 975 |
} |
| 976 |
|
| 977 |
?> |
| 978 |
<div <?php $this->print_render_attribute_string('item_wrapper'); ?> data-ui-e-tags="<?php echo esc_attr( sanitize_title( $item['item_tags'] )); ?>"> |
| 979 |
|
| 980 |
<?php if($has_animation) : ?> |
| 981 |
<div class='ui-e-animations-wrp <?php echo esc_attr($animations);?>'> |
| 982 |
<?php endif; ?> |
| 983 |
|
| 984 |
<<?php echo esc_html($tag);?> <?php $this->print_render_attribute_string($key); ?>> |
| 985 |
<?php $this->render_layout($index, $item, $settings); ?> |
| 986 |
</<?php echo esc_html($tag);?>> |
| 987 |
|
| 988 |
<?php if($has_animation) : ?> |
| 989 |
</div> |
| 990 |
<?php endif; ?> |
| 991 |
|
| 992 |
</div> |
| 993 |
<?php |
| 994 |
} |
| 995 |
protected function render_layout($index, $instance, $settings) |
| 996 |
{ |
| 997 |
|
| 998 |
switch( $settings['layout'] ){ |
| 999 |
case 'ui-e-overlay': |
| 1000 |
?> |
| 1001 |
<?php $this->render_image($index, $instance, $settings); ?> |
| 1002 |
|
| 1003 |
<div class="ui-e-content"> |
| 1004 |
<div class="ui-e-title-wrapper"> |
| 1005 |
<?php $this->render_title($instance, $settings); ?> |
| 1006 |
<?php |
| 1007 |
if( empty($settings['badge_position']) ) { |
| 1008 |
$this->render_badge($instance, $settings['badge_animation']); |
| 1009 |
} |
| 1010 |
?> |
| 1011 |
</div> |
| 1012 |
|
| 1013 |
<?php $this->render_description($instance, $settings['description_animation']); ?> |
| 1014 |
<?php $this->render_tags($instance, $settings); ?> |
| 1015 |
</div> |
| 1016 |
|
| 1017 |
</div> <?php // close `ui-e-media-wrp` div opened by render_image() |
| 1018 |
break; |
| 1019 |
|
| 1020 |
default: |
| 1021 |
?> |
| 1022 |
<?php $this->render_image($index, $instance, $settings); ?> |
| 1023 |
|
| 1024 |
<div class="ui-e-content"> |
| 1025 |
<div class="ui-e-title-wrapper"> |
| 1026 |
<?php $this->render_title($instance, $settings); ?> |
| 1027 |
<?php |
| 1028 |
if( empty($settings['badge_position']) ) { |
| 1029 |
$this->render_badge($instance, $settings['badge_animation']); |
| 1030 |
} |
| 1031 |
?> |
| 1032 |
</div> |
| 1033 |
|
| 1034 |
<?php $this->render_description($instance, $settings['description_animation']); ?> |
| 1035 |
<?php $this->render_tags($instance, $settings); ?> |
| 1036 |
</div> |
| 1037 |
<?php |
| 1038 |
break; |
| 1039 |
} |
| 1040 |
} |
| 1041 |
protected function render_image($index, $instance, $settings){ |
| 1042 |
|
| 1043 |
if( empty($instance['item_image']['url']) ){ |
| 1044 |
return; |
| 1045 |
} |
| 1046 |
|
| 1047 |
// `get_attachment_image_` functions get the image size on the key passed as second argument with '_size' suffix |
| 1048 |
$instance['item_image_size'] = $settings['image_size']; |
| 1049 |
$key = 'image_' . $index; |
| 1050 |
|
| 1051 |
// Overlay layout |
| 1052 |
if( $settings['layout'] === 'ui-e-overlay' ){ |
| 1053 |
|
| 1054 |
// get the image url with the proper size |
| 1055 |
$image = Group_Control_Image_Size::get_attachment_image_src( $instance['item_image']['id'], 'item_image', $instance ); |
| 1056 |
|
| 1057 |
$this->add_render_attribute( |
| 1058 |
$key, |
| 1059 |
[ |
| 1060 |
'style' => 'background-image: url(' . $image . '); background-size: cover;', |
| 1061 |
'class' => [ |
| 1062 |
'ui-e-media-wrp', |
| 1063 |
esc_attr($settings['image_animation']) |
| 1064 |
], |
| 1065 |
] |
| 1066 |
); |
| 1067 |
|
| 1068 |
?> |
| 1069 |
<div <?php $this->print_render_attribute_string($key); ?>> |
| 1070 |
<?php |
| 1071 |
if( ! empty($settings['badge_position']) ) { |
| 1072 |
$this->render_badge($instance, $settings['badge_animation']); |
| 1073 |
} |
| 1074 |
// We don't close the </div> div here because on overlay all the content goes |
| 1075 |
// inside this wrapper. The div should be closed by the parent function. |
| 1076 |
|
| 1077 |
// Default layout |
| 1078 |
} else { |
| 1079 |
|
| 1080 |
$this->add_render_attribute( |
| 1081 |
'image', |
| 1082 |
[ |
| 1083 |
'src' => $instance['item_image']['url'], |
| 1084 |
'alt' => Control_Media::get_image_alt( $instance['item_image'] ), |
| 1085 |
'title' => Control_Media::get_image_title( $instance['item_image'] ), |
| 1086 |
'class' => 'ui-e-img', |
| 1087 |
] |
| 1088 |
); |
| 1089 |
|
| 1090 |
?> |
| 1091 |
<div class="ui-e-media-wrp <?php echo esc_attr($settings['image_animation']);?>"> |
| 1092 |
<?php |
| 1093 |
if( ! empty($settings['badge_position']) ) { |
| 1094 |
$this->render_badge($instance, $settings['badge_animation']); |
| 1095 |
} |
| 1096 |
?> |
| 1097 |
<?php echo wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $instance, 'item_image', )); ?> |
| 1098 |
</div> |
| 1099 |
<?php |
| 1100 |
} |
| 1101 |
} |
| 1102 |
protected function render_title($instance, $settings) |
| 1103 |
{ |
| 1104 |
if( empty($instance['item_title']) ){ |
| 1105 |
return; |
| 1106 |
} |
| 1107 |
|
| 1108 |
?> |
| 1109 |
<<?php echo esc_html($settings['title_tag']);?> class="ui-e-title <?php echo esc_attr($settings['title_animation'])?>"> |
| 1110 |
<span> <?php echo Helper::esc_string( $instance['item_title'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </span> |
| 1111 |
</<?php echo esc_html($settings['title_tag']);?>> |
| 1112 |
<?php |
| 1113 |
} |
| 1114 |
protected function render_description($instance, $animation = '') |
| 1115 |
{ |
| 1116 |
if( empty( $instance['item_description'] ) ){ |
| 1117 |
return; |
| 1118 |
} |
| 1119 |
|
| 1120 |
?> |
| 1121 |
<p class="ui-e-description <?php echo esc_attr($animation);?>"> |
| 1122 |
<?php echo Helper::esc_string( $instance['item_description'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 1123 |
</p> |
| 1124 |
<?php |
| 1125 |
} |
| 1126 |
protected function render_badge($instance, $animation) |
| 1127 |
{ |
| 1128 |
if( empty( $instance['item_badge']) ){ |
| 1129 |
return; |
| 1130 |
} |
| 1131 |
|
| 1132 |
?> |
| 1133 |
<span class="ui-e-badge <?php echo esc_attr($animation) ;?>"> |
| 1134 |
<?php echo esc_html( $instance['item_badge'] ); ?> |
| 1135 |
</span> |
| 1136 |
<?php |
| 1137 |
} |
| 1138 |
protected function render_tags($instance, $settings) |
| 1139 |
{ |
| 1140 |
if( empty( $instance['item_tags'] ) || $this->is_option('hide_tags', 'yes') ){ |
| 1141 |
return; |
| 1142 |
} |
| 1143 |
|
| 1144 |
$tags = explode(',', $instance['item_tags']); |
| 1145 |
|
| 1146 |
?> |
| 1147 |
<div class="ui-e-tags <?php echo esc_attr($settings['tags_animation']);?>"> |
| 1148 |
<?php foreach($tags as $tag) : ?> |
| 1149 |
<span class="ui-e-tag"> |
| 1150 |
<?php |
| 1151 |
echo esc_html($tag); |
| 1152 |
echo end($tags) !== $tag ? ', ': ''; // print separator if is not last item |
| 1153 |
?> |
| 1154 |
</span> |
| 1155 |
<?php endforeach; ?> |
| 1156 |
</div> |
| 1157 |
<?php |
| 1158 |
} |
| 1159 |
protected function TRAIT_render_gallery_filters($settings) |
| 1160 |
{ |
| 1161 |
if( $this->is_option('filters', 'yes', '!==') ){ |
| 1162 |
return; |
| 1163 |
} |
| 1164 |
|
| 1165 |
$filters = []; |
| 1166 |
|
| 1167 |
foreach( $settings['gallery_items'] as $item ) { |
| 1168 |
|
| 1169 |
// tags are comma separated strings |
| 1170 |
$tags = explode(',', $item['item_tags']); |
| 1171 |
$tags = array_map('trim', $tags); |
| 1172 |
|
| 1173 |
foreach ( $tags as $tag ) { |
| 1174 |
// skip duplicates or empty tags |
| 1175 |
if( in_array($tag, $filters) || empty($tag) ){ |
| 1176 |
continue; |
| 1177 |
} |
| 1178 |
|
| 1179 |
$filters[] = $tag; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
?> |
| 1184 |
<div class="ui-e-filters"> |
| 1185 |
|
| 1186 |
<button class="ui-e-filter-item" data-filter="all"> |
| 1187 |
<?php echo esc_html( $settings['clear_text'] ); ?> |
| 1188 |
</button> |
| 1189 |
|
| 1190 |
<?php foreach($filters as $filter) : ?> |
| 1191 |
<button class="ui-e-filter-item" data-filter="<?php echo esc_attr( sanitize_title($filter)); ?>"> |
| 1192 |
<?php echo esc_html($filter); ?> |
| 1193 |
</button> |
| 1194 |
<?php endforeach; ?> |
| 1195 |
|
| 1196 |
</div> |
| 1197 |
<?php |
| 1198 |
} |
| 1199 |
} |