| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimatePostKit\Traits; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || die(); |
| 8 |
|
| 9 |
trait Global_Swiper_Functions { |
| 10 |
|
| 11 |
function render_header_attribute( $name ) { |
| 12 |
$id = 'upk-' . $name . '-carousel-' . $this->get_id(); |
| 13 |
$settings = $this->get_settings_for_display(); |
| 14 |
$elementor_vp_lg = get_option( 'elementor_viewport_lg' ); |
| 15 |
$elementor_vp_md = get_option( 'elementor_viewport_md' ); |
| 16 |
$viewport_lg = ! empty( $elementor_vp_lg ) ? $elementor_vp_lg - 1 : 1023; |
| 17 |
$viewport_md = ! empty( $elementor_vp_md ) ? $elementor_vp_md - 1 : 767; |
| 18 |
|
| 19 |
$this->add_render_attribute( 'carousel', 'id', $id ); |
| 20 |
$this->add_render_attribute( 'carousel', 'class', [ 'upk-' . $name . '-carousel' ] ); |
| 21 |
|
| 22 |
if ( 'arrows' == $settings['navigation'] ) { |
| 23 |
$this->add_render_attribute( 'carousel', 'class', 'upk-arrows-align-' . $settings['arrows_position'] ); |
| 24 |
} elseif ( 'dots' == $settings['navigation'] ) { |
| 25 |
$this->add_render_attribute( 'carousel', 'class', 'upk-dots-align-' . $settings['dots_position'] ); |
| 26 |
} elseif ( 'both' == $settings['navigation'] ) { |
| 27 |
$this->add_render_attribute( 'carousel', 'class', 'upk-arrows-dots-align-' . $settings['both_position'] ); |
| 28 |
} elseif ( 'arrows-fraction' == $settings['navigation'] ) { |
| 29 |
$this->add_render_attribute( 'carousel', 'class', 'upk-arrows-dots-align-' . $settings['arrows_fraction_position'] ); |
| 30 |
} elseif ( 'progressbar' == $settings['navigation'] ) { |
| 31 |
$this->add_render_attribute( 'carousel', 'class', 'upk-progress-align-' . $settings['progress_position'] ); |
| 32 |
} |
| 33 |
|
| 34 |
if ( 'arrows-fraction' == $settings['navigation'] ) { |
| 35 |
$pagination_type = 'fraction'; |
| 36 |
} elseif ( 'both' == $settings['navigation'] or 'dots' == $settings['navigation'] ) { |
| 37 |
$pagination_type = 'bullets'; |
| 38 |
} elseif ( 'progressbar' == $settings['navigation'] ) { |
| 39 |
$pagination_type = 'progressbar'; |
| 40 |
} else { |
| 41 |
$pagination_type = ''; |
| 42 |
} |
| 43 |
|
| 44 |
$this->add_render_attribute( |
| 45 |
[ |
| 46 |
'carousel' => [ |
| 47 |
'data-settings' => [ |
| 48 |
wp_json_encode( array_filter( [ |
| 49 |
"autoplay" => ( "yes" == $settings["autoplay"] ) ? [ "delay" => $settings["autoplay_speed"] ] : false, |
| 50 |
"loop" => ( $settings["loop"] == "yes" ) ? true : false, |
| 51 |
"speed" => $settings["speed"]["size"], |
| 52 |
"pauseOnHover" => ( "yes" == $settings["pauseonhover"] ) ? true : false, |
| 53 |
"slidesPerView" => isset($settings["columns_mobile"]) ? (int)$settings["columns_mobile"] : 1, |
| 54 |
"slidesPerGroup" => isset($settings["slides_to_scroll_mobile"]) ? (int)$settings["slides_to_scroll_mobile"] : 1, |
| 55 |
"spaceBetween" => !empty($settings["item_gap_mobile"]["size"]) ? (int)$settings["item_gap_mobile"]["size"] : 0, |
| 56 |
"centeredSlides" => ( $settings["centered_slides"] === "yes" ) ? true : false, |
| 57 |
"grabCursor" => ( $settings["grab_cursor"] === "yes" ) ? true : false, |
| 58 |
"effect" => $settings["skin"], |
| 59 |
"observer" => ( $settings["observer"] ) ? true : false, |
| 60 |
"observeParents" => ( $settings["observer"] ) ? true : false, |
| 61 |
"direction" => $settings['direction'], |
| 62 |
"watchSlidesVisibility" => true, |
| 63 |
"watchSlidesProgress" => true, |
| 64 |
"mousewheel" => ( $settings["mousewheel"] === "yes" ) ? true : false, |
| 65 |
"breakpoints" => [ |
| 66 |
(int) $viewport_md => [ |
| 67 |
"slidesPerView" => isset($settings["columns_tablet"]) ? (int)$settings["columns_tablet"] : 2, |
| 68 |
"spaceBetween" => !empty($settings["item_gap_tablet"]["size"]) ? (int)$settings["item_gap_tablet"]["size"] : 0, |
| 69 |
"slidesPerGroup" => isset($settings["slides_to_scroll_tablet"]) ? (int)$settings["slides_to_scroll_tablet"] : 1, |
| 70 |
], |
| 71 |
(int) $viewport_lg => [ |
| 72 |
"slidesPerView" => isset($settings["columns"]) ? (int)$settings["columns"] : 3, |
| 73 |
"spaceBetween" => !empty($settings["item_gap"]["size"]) ? (int)$settings["item_gap"]["size"] : 0, |
| 74 |
"slidesPerGroup" => isset($settings["slides_to_scroll"]) ? (int)$settings["slides_to_scroll"] : 1, |
| 75 |
] |
| 76 |
], |
| 77 |
"navigation" => [ |
| 78 |
"nextEl" => "#" . $id . " .upk-navigation-next", |
| 79 |
"prevEl" => "#" . $id . " .upk-navigation-prev", |
| 80 |
], |
| 81 |
"pagination" => [ |
| 82 |
"el" => "#" . $id . " .swiper-pagination", |
| 83 |
"type" => $pagination_type, |
| 84 |
"clickable" => "true", |
| 85 |
'dynamicBullets' => ( "yes" == $settings["dynamic_bullets"] ) ? true : false, |
| 86 |
], |
| 87 |
"scrollbar" => [ |
| 88 |
"el" => "#" . $id . " .swiper-scrollbar", |
| 89 |
"hide" => "true", |
| 90 |
], |
| 91 |
'coverflowEffect' => [ |
| 92 |
'rotate' => ( "yes" == $settings["coverflow_toggle"] ) ? $settings["coverflow_rotate"]["size"] : 50, |
| 93 |
'stretch' => ( "yes" == $settings["coverflow_toggle"] ) ? $settings["coverflow_stretch"]["size"] : 0, |
| 94 |
'depth' => ( "yes" == $settings["coverflow_toggle"] ) ? $settings["coverflow_depth"]["size"] : 100, |
| 95 |
'modifier' => ( "yes" == $settings["coverflow_toggle"] ) ? $settings["coverflow_modifier"]["size"] : 1, |
| 96 |
'slideShadows' => true, |
| 97 |
], |
| 98 |
|
| 99 |
] ) ) |
| 100 |
] |
| 101 |
] |
| 102 |
] |
| 103 |
); |
| 104 |
|
| 105 |
$this->add_render_attribute('swiper', 'class', 'swiper-carousel swiper'); |
| 106 |
} |
| 107 |
|
| 108 |
function render_navigation() { |
| 109 |
$settings = $this->get_settings_for_display(); |
| 110 |
$hide_arrow_on_mobile = $settings['hide_arrow_on_mobile'] ? ' upk-visible@m' : ''; |
| 111 |
|
| 112 |
if ( 'arrows' == $settings['navigation'] ) : ?> |
| 113 |
<div class="upk-position-z-index upk-position-<?php echo esc_html( $settings['arrows_position'] . $hide_arrow_on_mobile ); ?>"> |
| 114 |
<div class="upk-arrows-container upk-slidenav-container"> |
| 115 |
<div class="upk-navigation-prev"> |
| 116 |
<i class="upk-icon-arrow-left-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 117 |
</div> |
| 118 |
<div class="upk-navigation-next"> |
| 119 |
<i class="upk-icon-arrow-right-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
<?php endif; |
| 124 |
} |
| 125 |
|
| 126 |
function render_pagination() { |
| 127 |
$settings = $this->get_settings_for_display(); |
| 128 |
|
| 129 |
if ( 'dots' == $settings['navigation'] or 'arrows-fraction' == $settings['navigation'] ) : ?> |
| 130 |
<div class="upk-position-z-index upk-position-<?php echo esc_html($settings['dots_position']); ?>"> |
| 131 |
<div class="upk-dots-container"> |
| 132 |
<div class="swiper-pagination"></div> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
|
| 136 |
<?php elseif ( 'progressbar' == $settings['navigation'] ) : ?> |
| 137 |
<div class="swiper-pagination upk-position-z-index upk-position-<?php echo esc_html( $settings['progress_position'] ?? 'bottom' ); ?>"></div> |
| 138 |
<?php endif; |
| 139 |
} |
| 140 |
|
| 141 |
function render_both_navigation() { |
| 142 |
$settings = $this->get_settings_for_display(); |
| 143 |
$hide_arrow_on_mobile = $settings['hide_arrow_on_mobile'] ? 'upk-visible@m upk-flex' : 'upk-flex'; |
| 144 |
|
| 145 |
?> |
| 146 |
<div class="upk-position-z-index upk-position-<?php echo esc_html($settings['both_position']); ?>"> |
| 147 |
<div class="upk-arrows-dots-container upk-slidenav-container "> |
| 148 |
|
| 149 |
<div class="upk-flex upk-flex-middle"> |
| 150 |
<div class="<?php echo esc_html( $hide_arrow_on_mobile ); ?>"> |
| 151 |
<div class="upk-navigation-prev"> |
| 152 |
<i class="upk-icon-arrow-left-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
|
| 156 |
<?php if ('center' !== $settings['both_position']) : ?> |
| 157 |
<div class="swiper-pagination"></div> |
| 158 |
<?php endif; ?> |
| 159 |
|
| 160 |
<div class="<?php echo esc_html( $hide_arrow_on_mobile ); ?>"> |
| 161 |
<div class="upk-navigation-next"> |
| 162 |
<i class="upk-icon-arrow-right-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 163 |
</div> |
| 164 |
</div> |
| 165 |
|
| 166 |
</div> |
| 167 |
</div> |
| 168 |
</div> |
| 169 |
<?php |
| 170 |
} |
| 171 |
|
| 172 |
function render_arrows_fraction() { |
| 173 |
$settings = $this->get_settings_for_display(); |
| 174 |
$hide_arrow_on_mobile = $settings['hide_arrow_on_mobile'] ? 'upk-visible@m' : ''; |
| 175 |
|
| 176 |
?> |
| 177 |
<div class="upk-position-z-index upk-position-<?php echo esc_html($settings['arrows_fraction_position']); ?>"> |
| 178 |
<div class="upk-arrows-fraction-container upk-slidenav-container "> |
| 179 |
|
| 180 |
<div class="upk-flex upk-flex-middle"> |
| 181 |
<div class="<?php echo esc_html( $hide_arrow_on_mobile ); ?>"> |
| 182 |
<div class="upk-navigation-prev"> |
| 183 |
<i class="upk-icon-arrow-left-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 184 |
</div> |
| 185 |
</div> |
| 186 |
|
| 187 |
<?php if ('center' !== $settings['arrows_fraction_position']) : ?> |
| 188 |
<div class="swiper-pagination"></div> |
| 189 |
<?php endif; ?> |
| 190 |
|
| 191 |
<div class="<?php echo esc_html( $hide_arrow_on_mobile ); ?>"> |
| 192 |
<div class="upk-navigation-next"> |
| 193 |
<i class="upk-icon-arrow-right-<?php echo esc_html($settings['nav_arrows_icon']); ?>" aria-hidden="true"></i> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
|
| 197 |
</div> |
| 198 |
</div> |
| 199 |
</div> |
| 200 |
<?php |
| 201 |
} |
| 202 |
|
| 203 |
function render_footer() { |
| 204 |
$settings = $this->get_settings_for_display(); |
| 205 |
|
| 206 |
?> |
| 207 |
</div> |
| 208 |
<?php if ( 'yes' === $settings['show_scrollbar'] ) : ?> |
| 209 |
<div class="swiper-scrollbar"></div> |
| 210 |
<?php endif; ?> |
| 211 |
</div> |
| 212 |
|
| 213 |
<?php if ('both' == $settings['navigation']) : ?> |
| 214 |
<?php $this->render_both_navigation(); ?> |
| 215 |
<?php if ( 'center' === $settings['both_position'] ) : ?> |
| 216 |
<div class="upk-position-z-index upk-position-bottom"> |
| 217 |
<div class="upk-dots-container"> |
| 218 |
<div class="swiper-pagination"></div> |
| 219 |
</div> |
| 220 |
</div> |
| 221 |
<?php endif; ?> |
| 222 |
<?php elseif ('arrows-fraction' == $settings['navigation']) : ?> |
| 223 |
<?php $this->render_arrows_fraction(); ?> |
| 224 |
<?php if ( 'center' === $settings['arrows_fraction_position'] ) : ?> |
| 225 |
<div class="upk-dots-container"> |
| 226 |
<div class="swiper-pagination"></div> |
| 227 |
</div> |
| 228 |
<?php endif; ?> |
| 229 |
<?php else : ?> |
| 230 |
<?php $this->render_pagination(); ?> |
| 231 |
<?php $this->render_navigation(); ?> |
| 232 |
<?php endif; ?> |
| 233 |
|
| 234 |
</div> |
| 235 |
</div> |
| 236 |
<?php |
| 237 |
} |
| 238 |
} |