block.json
3 weeks ago
controller.php
10 months ago
empty.php
1 year ago
image.php
10 months ago
index.asset.php
4 months ago
index.js
4 months ago
slideshow.php
10 months ago
style-index-rtl.css
1 week ago
style-index.css
1 week ago
video.php
8 months ago
controller.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | $product = sc_get_product(); |
| 4 | |
| 5 | $gallery = $product->gallery ?? []; |
| 6 | $media = $gallery[0] ?? null; |
| 7 | |
| 8 | // get the width. |
| 9 | $width = false; |
| 10 | if ( ! empty( $attributes['width'] ) ) { |
| 11 | $width = is_numeric( $attributes['width'] ) ? $attributes['width'] . 'px' : $attributes['width']; |
| 12 | } |
| 13 | |
| 14 | // handle empty. |
| 15 | if ( empty( $gallery ) ) { |
| 16 | return ! empty( $attributes['hide_empty'] ) ? '' : 'file:./empty.php'; |
| 17 | } |
| 18 | |
| 19 | if ( ! empty( $attributes['lightbox'] ) ) { |
| 20 | wp_enqueue_style( 'surecart-lightbox' ); |
| 21 | wp_enqueue_script_module( 'surecart/lightbox' ); |
| 22 | } |
| 23 | |
| 24 | // Don't enqueue video script if there is no video in the gallery. |
| 25 | if ( $product->has_videos ) { |
| 26 | wp_enqueue_script_module( '@surecart/video' ); |
| 27 | wp_enqueue_style( 'surecart-video' ); |
| 28 | } |
| 29 | |
| 30 | $auto_height = ! empty( $attributes['desktop_gallery'] ) ? true : ! empty( $attributes['auto_height'] ) && $attributes['auto_height']; |
| 31 | |
| 32 | // handle image. |
| 33 | if ( count( $gallery ) === 1 ) { |
| 34 | $style = ! empty( $width ) ? 'max-width: min(' . esc_attr( $width ) . ', 100%);' : ''; |
| 35 | return $media->isVideo() ? 'file:./video.php' : 'file:./image.php'; |
| 36 | } |
| 37 | |
| 38 | // only enqueue if we are needing a slideshow. |
| 39 | wp_enqueue_style( 'surecart-image-slider' ); |
| 40 | wp_enqueue_script_module( '@surecart/image-slider' ); |
| 41 | |
| 42 | // handle slideshow. |
| 43 | $slider_options = array( |
| 44 | 'activeBreakpoint' => apply_filters( 'surecart/image-slider/active-breakpoint', $attributes['desktop_gallery'] ? 782 : false ), |
| 45 | 'sliderOptions' => array( |
| 46 | 'autoHeight' => $auto_height, |
| 47 | 'spaceBetween' => 40, |
| 48 | ), |
| 49 | 'thumbSliderOptions' => array( |
| 50 | 'slidesPerView' => $attributes['thumbnails_per_page'] ?? 5, |
| 51 | 'slidesPerGroup' => $attributes['thumbnails_per_page'] ?? 5, |
| 52 | 'breakpoints' => array( |
| 53 | 320 => array( |
| 54 | 'slidesPerView' => $attributes['thumbnails_per_page'] ?? 5, |
| 55 | 'slidesPerGroup' => $attributes['thumbnails_per_page'] ?? 5, |
| 56 | ), |
| 57 | ), |
| 58 | ), |
| 59 | ); |
| 60 | |
| 61 | $height = 'auto'; |
| 62 | if ( ! $auto_height && ! empty( $attributes['height'] ) ) { |
| 63 | $height = $attributes['height']; |
| 64 | } |
| 65 | |
| 66 | wp_interactivity_state( |
| 67 | 'surecart/image-slider', |
| 68 | array( |
| 69 | 'active' => true, // to prevent flash of unstyled content. |
| 70 | ) |
| 71 | ); |
| 72 | |
| 73 | return 'file:./slideshow.php'; |
| 74 |