'none', 'borderTopWidth' => 4, 'borderRightWidth' => 4, 'borderLeftWidth' => 4, 'borderBottomWidth' => 4, 'borderTopLeftRadius' => 50, 'borderTopRightRadius' => 50, 'borderBottomLeftRadius' => 50, 'borderBottomRightRadius' => 50, ) ); $btn_border_attributes = UAGB_Block_Helper::uag_generate_php_border_attribute( 'btn' ); $image_border_attributes = UAGB_Block_Helper::uag_generate_php_border_attribute( 'image' ); $main_title_border_attributes = UAGB_Block_Helper::uag_generate_php_border_attribute( 'mainTitle', array( 'borderTopWidth' => 2, 'borderRightWidth' => 0, 'borderBottomWidth' => 2, 'borderLeftWidth' => 0, ) ); } $pro_attributes = apply_filters( 'uagb_image_gallery_dynamic_attributes', array() ); register_block_type( 'uagb/image-gallery', array( 'attributes' => array_merge( // Block Requirements. array( 'block_id' => array( 'type' => 'string', ), 'classMigrate' => array( 'type' => 'boolean', 'default' => false, ), ), // Editor Requirements. array( 'readyToRender' => array( 'type' => 'boolean', 'default' => false, ), 'tileSize' => array( 'type' => 'number', 'default' => 0, ), 'tileSizeFrontEnd' => array( 'type' => 'number', 'default' => 0, ), 'focusList' => array( 'type' => 'array', 'default' => array(), ), 'focusListObject' => array( 'type' => 'object', 'default' => array(), ), ), // Gallery Settings. array( 'mediaGallery' => array( 'type' => 'array', 'default' => array(), ), 'mediaIDs' => array( 'type' => 'array', 'default' => array(), ), 'feedLayout' => array( 'type' => 'string', 'default' => 'grid', ), 'imageDisplayCaption' => array( 'type' => 'boolean', 'default' => true, ), 'galleryImageSize' => array( 'type' => 'string', 'default' => 'large', ), 'galleryImageSizeTablet' => array( 'type' => 'string', 'default' => 'large', ), 'galleryImageSizeMobile' => array( 'type' => 'string', 'default' => 'medium', ), 'imageClickEvent' => array( 'type' => 'string', 'default' => 'none', ), ), // Lightbox Settings. array( 'lightboxDisplayCaptions' => array( 'type' => 'boolean', 'default' => false, ), 'lightboxThumbnails' => array( 'type' => 'boolean', 'default' => false, ), 'lightboxDisplayCount' => array( 'type' => 'boolean', 'default' => false, ), 'lightboxCloseIcon' => array( 'type' => 'string', 'default' => 'xmark', ), 'lightboxCaptionHeight' => array( 'type' => 'number', 'default' => 50, ), 'lightboxCaptionHeightTablet' => array( 'type' => 'number', ), 'lightboxCaptionHeightMobile' => array( 'type' => 'number', ), 'lightboxIconSize' => array( 'type' => 'number', 'default' => 24, ), 'lightboxIconSizeTablet' => array( 'type' => 'number', ), 'lightboxIconSizeMobile' => array( 'type' => 'number', ), ), // Caption Settings. array( 'captionVisibility' => array( 'type' => 'string', 'default' => 'hover', ), 'captionDisplayType' => array( 'type' => 'string', 'default' => 'overlay', ), 'imageCaptionAlignment' => array( 'type' => 'string', 'default' => 'center center', ), 'imageCaptionAlignment01' => array( 'type' => 'string', 'default' => 'center', ), 'imageCaptionAlignment02' => array( 'type' => 'string', 'default' => 'center', ), 'imageDefaultCaption' => array( 'type' => 'string', 'default' => __( 'No Caption', 'ultimate-addons-for-gutenberg' ), ), 'captionPaddingTop' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingRight' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingBottom' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingLeft' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingTopTab' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingRightTab' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingBottomTab' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingLeftTab' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingTopMob' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingRightMob' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingBottomMob' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingLeftMob' => array( 'type' => 'number', 'default' => 8, ), 'captionPaddingUnit' => array( 'type' => 'string', 'default' => 'px', ), 'captionPaddingUnitTab' => array( 'type' => 'string', 'default' => 'px', ), 'captionPaddingUnitMob' => array( 'type' => 'string', 'default' => 'px', ), 'captionPaddingUnitLink' => array( 'type' => 'boolean', 'default' => true, ), 'captionGap' => array( 'type' => 'number', 'default' => 4, ), 'captionGapUnit' => array( 'type' => 'string', 'default' => 'px', ), ), // Layout Settings. array( 'columnsDesk' => array( 'type' => 'number', 'default' => 3, ), 'columnsTab' => array( 'type' => 'number', 'default' => 3, ), 'columnsMob' => array( 'type' => 'number', 'default' => 2, ), 'gridImageGap' => array( 'type' => 'number', 'default' => 8, ), 'gridImageGapTab' => array( 'type' => 'number', ), 'gridImageGapMob' => array( 'type' => 'number', ), 'gridImageGapUnit' => array( 'type' => 'string', 'default' => 'px', ), 'gridImageGapUnitTab' => array( 'type' => 'string', 'default' => 'px', ), 'gridImageGapUnitMob' => array( 'type' => 'string', 'default' => 'px', ), 'feedMarginTop' => array( 'type' => 'number', ), 'feedMarginRight' => array( 'type' => 'number', ), 'feedMarginBottom' => array( 'type' => 'number', ), 'feedMarginLeft' => array( 'type' => 'number', ), 'feedMarginTopTab' => array( 'type' => 'number', ), 'feedMarginRightTab' => array( 'type' => 'number', ), 'feedMarginBottomTab' => array( 'type' => 'number', ), 'feedMarginLeftTab' => array( 'type' => 'number', ), 'feedMarginTopMob' => array( 'type' => 'number', ), 'feedMarginRightMob' => array( 'type' => 'number', ), 'feedMarginBottomMob' => array( 'type' => 'number', ), 'feedMarginLeftMob' => array( 'type' => 'number', ), 'feedMarginUnit' => array( 'type' => 'string', 'default' => 'px', ), 'feedMarginUnitTab' => array( 'type' => 'string', 'default' => 'px', ), 'feedMarginUnitMob' => array( 'type' => 'string', 'default' => 'px', ), 'feedMarginUnitLink' => array( 'type' => 'boolean', 'default' => true, ), ), // Layout Specific Settings. array( 'carouselStartAt' => array( 'type' => 'number', 'default' => 0, ), 'carouselSquares' => array( 'type' => 'boolean', 'default' => false, ), 'carouselLoop' => array( 'type' => 'boolean', 'default' => true, ), 'carouselAutoplay' => array( 'type' => 'boolean', 'default' => true, ), 'carouselAutoplaySpeed' => array( 'type' => 'number', 'default' => 2000, ), 'carouselPauseOnHover' => array( 'type' => 'boolean', 'default' => true, ), 'carouselTransitionSpeed' => array( 'type' => 'number', 'default' => 500, ), 'gridPages' => array( 'type' => 'number', 'default' => 1, ), 'gridPageNumber' => array( 'type' => 'number', 'default' => 1, ), ), // Pagination Settings. array( 'feedPagination' => array( 'type' => 'boolean', 'default' => false, ), 'paginateUseArrows' => array( 'type' => 'boolean', 'default' => true, ), 'paginateUseDots' => array( 'type' => 'boolean', 'default' => true, ), 'paginateUseLoader' => array( 'type' => 'boolean', 'default' => true, ), 'paginateLimit' => array( 'type' => 'number', 'default' => 9, ), 'paginateButtonAlign' => array( 'type' => 'string', 'default' => 'center', ), 'paginateButtonText' => array( 'type' => 'string', 'default' => __( 'Load More Images', 'ultimate-addons-for-gutenberg' ), ), 'paginateButtonPaddingTop' => array( 'type' => 'number', ), 'paginateButtonPaddingRight' => array( 'type' => 'number', ), 'paginateButtonPaddingBottom' => array( 'type' => 'number', ), 'paginateButtonPaddingLeft' => array( 'type' => 'number', ), 'paginateButtonPaddingTopTab' => array( 'type' => 'number', ), 'paginateButtonPaddingRightTab' => array( 'type' => 'number', ), 'paginateButtonPaddingBottomTab' => array( 'type' => 'number', ), 'paginateButtonPaddingLeftTab' => array( 'type' => 'number', ), 'paginateButtonPaddingTopMob' => array( 'type' => 'number', ), 'paginateButtonPaddingRightMob' => array( 'type' => 'number', ), 'paginateButtonPaddingBottomMob' => array( 'type' => 'number', ), 'paginateButtonPaddingLeftMob' => array( 'type' => 'number', ), 'paginateButtonPaddingUnit' => array( 'type' => 'string', 'default' => 'px', ), 'paginateButtonPaddingUnitTab' => array( 'type' => 'string', 'default' => 'px', ), 'paginateButtonPaddingUnitMob' => array( 'type' => 'string', 'default' => 'px', ), 'paginateButtonPaddingUnitLink' => array( 'type' => 'boolean', 'default' => true, ), ), // Image Styling. array( 'imageEnableZoom' => array( 'type' => 'boolean', 'default' => true, ), 'imageZoomType' => array( 'type' => 'string', 'default' => 'zoom-in', ), 'captionBackgroundEnableBlur' => array( 'type' => 'boolean', 'default' => false, ), 'captionBackgroundBlurAmount' => array( 'type' => 'number', 'default' => 0, ), 'captionBackgroundBlurAmountHover' => array( 'type' => 'number', 'default' => 5, ), ), // Lightbox Styling. array( 'lightboxEdgeDistance' => array( 'type' => 'number', 'default' => 10, ), 'lightboxEdgeDistanceTablet' => array( 'type' => 'number', ), 'lightboxEdgeDistanceMobile' => array( 'type' => 'number', ), 'lightboxBackgroundEnableBlur' => array( 'type' => 'boolean', 'default' => true, ), 'lightboxBackgroundBlurAmount' => array( 'type' => 'number', 'default' => 5, ), 'lightboxBackgroundColor' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,0.75)', ), 'lightboxIconColor' => array( 'type' => 'string', 'default' => 'rgba(255,255,255,1)', ), 'lightboxCaptionColor' => array( 'type' => 'string', 'default' => 'rgba(255,255,255,1)', ), 'lightboxCaptionBackgroundColor' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,1)', ), ), // Caption Typography Styling. array( 'captionLoadGoogleFonts' => array( 'type' => 'boolean', 'default' => false, ), 'captionFontFamily' => array( 'type' => 'string', 'default' => 'Default', ), 'captionFontWeight' => array( 'type' => 'string', ), 'captionFontStyle' => array( 'type' => 'string', 'default' => 'normal', ), 'captionTransform' => array( 'type' => 'string', ), 'captionDecoration' => array( 'type' => 'string', 'default' => 'none', ), 'captionFontSizeType' => array( 'type' => 'string', 'default' => 'px', ), 'captionFontSize' => array( 'type' => 'number', ), 'captionFontSizeTab' => array( 'type' => 'number', ), 'captionFontSizeMob' => array( 'type' => 'number', ), 'captionLineHeightType' => array( 'type' => 'string', 'default' => 'em', ), 'captionLineHeight' => array( 'type' => 'number', ), 'captionLineHeightTab' => array( 'type' => 'number', ), 'captionLineHeightMob' => array( 'type' => 'number', ), ), // Pagination Button Typography Styling. array( 'loadMoreLoadGoogleFonts' => array( 'type' => 'boolean', 'default' => false, ), 'loadMoreFontFamily' => array( 'type' => 'string', 'default' => 'Default', ), 'loadMoreFontWeight' => array( 'type' => 'string', ), 'loadMoreFontStyle' => array( 'type' => 'string', 'default' => 'normal', ), 'loadMoreTransform' => array( 'type' => 'string', ), 'loadMoreDecoration' => array( 'type' => 'string', 'default' => 'none', ), 'loadMoreFontSizeType' => array( 'type' => 'string', 'default' => 'px', ), 'loadMoreFontSize' => array( 'type' => 'number', ), 'loadMoreFontSizeTab' => array( 'type' => 'number', ), 'loadMoreFontSizeMob' => array( 'type' => 'number', ), 'loadMoreLineHeightType' => array( 'type' => 'string', 'default' => 'em', ), 'loadMoreLineHeight' => array( 'type' => 'number', ), 'loadMoreLineHeightTab' => array( 'type' => 'number', ), 'loadMoreLineHeightMob' => array( 'type' => 'number', ), ), // Lightbox Typography Styling. array( 'lightboxLoadGoogleFonts' => array( 'type' => 'boolean', 'default' => false, ), 'lightboxFontFamily' => array( 'type' => 'string', 'default' => 'Default', ), 'lightboxFontWeight' => array( 'type' => 'string', ), 'lightboxFontStyle' => array( 'type' => 'string', 'default' => 'normal', ), 'lightboxTransform' => array( 'type' => 'string', ), 'lightboxDecoration' => array( 'type' => 'string', 'default' => 'none', ), 'lightboxFontSizeType' => array( 'type' => 'string', 'default' => 'px', ), 'lightboxFontSize' => array( 'type' => 'number', ), 'lightboxFontSizeTab' => array( 'type' => 'number', ), 'lightboxFontSizeMob' => array( 'type' => 'number', ), 'lightboxLineHeightType' => array( 'type' => 'string', 'default' => 'em', ), 'lightboxLineHeight' => array( 'type' => 'number', ), 'lightboxLineHeightTab' => array( 'type' => 'number', ), 'lightboxLineHeightMob' => array( 'type' => 'number', ), ), // Hoverable Styling. array( 'captionBackgroundEffect' => array( 'type' => 'string', 'default' => 'none', ), 'captionBackgroundEffectHover' => array( 'type' => 'string', 'default' => 'none', ), 'captionBackgroundEffectAmount' => array( 'type' => 'number', 'default' => 100, ), 'captionBackgroundEffectAmountHover' => array( 'type' => 'number', 'default' => 0, ), 'captionColor' => array( 'type' => 'string', 'default' => 'rgba(255,255,255,1)', ), 'captionColorHover' => array( 'type' => 'string', 'default' => 'rgba(255,255,255,1)', ), 'captionBackgroundColor' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,0.75)', ), 'captionBackgroundColorHover' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,0.75)', ), 'overlayColor' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,0)', ), 'overlayColorHover' => array( 'type' => 'string', 'default' => 'rgba(0,0,0,0)', ), 'captionSeparateColors' => array( 'type' => 'boolean', 'default' => false, ), ), // Pagination Styling. array( 'paginateArrowDistance' => array( 'type' => 'number', 'default' => -24, ), 'paginateArrowDistanceUnit' => array( 'type' => 'string', 'default' => 'px', ), 'paginateArrowSize' => array( 'type' => 'number', 'default' => 24, ), 'paginateDotDistance' => array( 'type' => 'number', 'default' => 8, ), 'paginateDotDistanceUnit' => array( 'type' => 'string', 'default' => 'px', ), 'paginateLoaderSize' => array( 'type' => 'number', 'default' => 18, ), 'paginateButtonTextColor' => array( 'type' => 'string', ), 'paginateButtonTextColorHover' => array( 'type' => 'string', ), 'paginateColor' => array( 'type' => 'string', ), 'paginateColorHover' => array( 'type' => 'string', ), ), // Box Shadow Styling. array( 'imageBoxShadowColor' => array( 'type' => 'string', ), 'imageBoxShadowHOffset' => array( 'type' => 'number', 'default' => 0, ), 'imageBoxShadowVOffset' => array( 'type' => 'number', 'default' => 0, ), 'imageBoxShadowBlur' => array( 'type' => 'number', ), 'imageBoxShadowSpread' => array( 'type' => 'number', ), 'imageBoxShadowPosition' => array( 'type' => 'string', 'default' => 'outset', ), 'imageBoxShadowColorHover' => array( 'type' => 'string', ), 'imageBoxShadowHOffsetHover' => array( 'type' => 'number', 'default' => 0, ), 'imageBoxShadowVOffsetHover' => array( 'type' => 'number', 'default' => 0, ), 'imageBoxShadowBlurHover' => array( 'type' => 'number', ), 'imageBoxShadowSpreadHover' => array( 'type' => 'number', ), 'imageBoxShadowPositionHover' => array( 'type' => 'string', 'default' => 'outset', ), ), // Pro Attributes. $pro_attributes, // Responsive Borders. $arrow_border_attributes, $btn_border_attributes, $image_border_attributes, $main_title_border_attributes ), 'render_callback' => array( $this, 'render_initial_grid' ), ) ); } /** * Renders All Images. * * @param array $attributes Array of block attributes. * * @since 2.1 */ public function render_initial_grid( $attributes ) { $allMedia = ''; if ( $attributes['readyToRender'] ) { $media = ( ( 'carousel' !== $attributes['feedLayout'] && 'tiled' !== $attributes['feedLayout'] ) && $attributes['feedPagination'] ) ? $this->get_gallery_images( $attributes, 'paginated' ) : $this->get_gallery_images( $attributes, 'full' ); if ( ! $media ) { ob_start(); ?> $attribute ) { $attributes[ $key ] = ( 'false' === $attribute ) ? false : ( ( 'true' === $attribute ) ? true : $attribute ); } $desktop_class = ''; $tab_class = ''; $mob_class = ''; $uagb_common_selector_class = ''; // Required for z-index. if ( array_key_exists( 'UAGHideDesktop', $attributes ) || array_key_exists( 'UAGHideTab', $attributes ) || array_key_exists( 'UAGHideMob', $attributes ) ) { $desktop_class = ( isset( $attributes['UAGHideDesktop'] ) ) ? 'uag-hide-desktop' : ''; $tab_class = ( isset( $attributes['UAGHideTab'] ) ) ? 'uag-hide-tab' : ''; $mob_class = ( isset( $attributes['UAGHideMob'] ) ) ? 'uag-hide-mob' : ''; } $zindex_desktop = ''; $zindex_tablet = ''; $zindex_mobile = ''; $zindex_wrap = array(); if ( array_key_exists( 'zIndex', $attributes ) || array_key_exists( 'zIndexTablet', $attributes ) || array_key_exists( 'zIndexMobile', $attributes ) ) { $uagb_common_selector_class = 'uag-blocks-common-selector'; $zindex_desktop = array_key_exists( 'zIndex', $attributes ) && ( '' !== $attributes['zIndex'] ) ? '--z-index-desktop:' . $attributes['zIndex'] . ';' : false; $zindex_tablet = array_key_exists( 'zIndexTablet', $attributes ) && ( '' !== $attributes['zIndexTablet'] ) ? '--z-index-tablet:' . $attributes['zIndexTablet'] . ';' : false; $zindex_mobile = array_key_exists( 'zIndexMobile', $attributes ) && ( '' !== $attributes['zIndexMobile'] ) ? '--z-index-mobile:' . $attributes['zIndexMobile'] . ';' : false; if ( $zindex_desktop ) { array_push( $zindex_wrap, $zindex_desktop ); } if ( $zindex_tablet ) { array_push( $zindex_wrap, $zindex_tablet ); } if ( $zindex_mobile ) { array_push( $zindex_wrap, $zindex_mobile ); } } // Check if the new Object Focus List is empty and the old Array Focus List is not - if so, transfer it. if ( empty( $attributes['focusListObject'] ) && is_array( $attributes['focusList'] ) && ! empty( $attributes['focusList'] ) ) { foreach ( $attributes['focusList'] as $image_id => $focus_value ) { if ( true === $focus_value ) { $attributes['focusListObject'][ $image_id ] = $focus_value; } } } $wrap = array( 'wp-block-uagb-image-gallery', 'uagb-block-' . $attributes['block_id'], ( isset( $attributes['className'] ) ) ? $attributes['className'] : '', $desktop_class, $tab_class, $mob_class, $uagb_common_selector_class, ); $allMedia = $this->render_media_markup( $media, $attributes ); $grid_page_kses = wp_kses_allowed_html( 'post' ); $grid_page_args = array( 'div' => array( 'class' => true ), 'button' => array( 'data-role' => true, 'class' => true, 'aria-label' => true, 'tabindex' => true, 'data-direction' => true, 'disabled' => true, ), 'svg' => array( 'width' => true, 'height' => true, 'viewbox' => true, 'aria-hidden' => true, ), 'path' => array( 'd' => true ), 'ul' => array( 'class' => true ), 'li' => array( 'class' => true, 'data-go-to' => true, ), ); $media_args = array( 'div' => array( 'class' => true, 'data-spectra-gallery-image-id' => true, ), 'picture' => array(), 'source' => array( 'media' => true, 'srcset' => true, ), ); $grid_page_allowed_tags = array_merge( $grid_page_kses, $grid_page_args ); $media_allowed_tags = array_merge( $grid_page_kses, $media_args ); ob_start(); ?>
render_grid_pagination_controls( $attributes ), $grid_page_allowed_tags ) : ''; ?> render_masonry_pagination_controls( $attributes ) ) : ''; ?>
( isset( $attributes['mediaGallery'] ) ) ? wp_json_encode( $attributes['mediaGallery'] ) : array(), 'feedPagination' => ( isset( $attributes['feedPagination'] ) ) ? sanitize_text_field( $attributes['feedPagination'] ) : false, 'gridPages' => ( isset( $attributes['gridPages'] ) ) ? sanitize_text_field( $attributes['gridPages'] ) : 1, 'gridPageNumber' => ( isset( $attributes['gridPageNumber'] ) ) ? sanitize_text_field( $attributes['gridPageNumber'] ) : 1, 'paginateLimit' => ( isset( $attributes['paginateLimit'] ) ) ? sanitize_text_field( $attributes['paginateLimit'] ) : 9, ); } /** * Sends the Images to Masonry AJAX. * * @since 2.1 */ public function render_masonry_pagination() { check_ajax_referer( 'uagb_image_gallery_masonry_ajax_nonce', 'nonce' ); $media_atts = array(); // sanitizing $attr elements in later stage. $attr = isset( $_POST['attr'] ) ? json_decode( stripslashes( $_POST['attr'] ), true ) : array(); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $attr['gridPageNumber'] = isset( $_POST['page_number'] ) ? sanitize_text_field( $_POST['page_number'] ) : ''; $media_atts = $this->required_atts( $attr ); $media_atts['mediaGallery'] = json_decode( $media_atts['mediaGallery'], true ); $media = $this->get_gallery_images( $media_atts, 'paginated' ); if ( ! $media ) { wp_send_json_error(); } foreach ( $attr as $key => $attribute ) { $attr[ $key ] = ( 'false' === $attribute ) ? false : ( ( 'true' === $attribute ) ? true : $attribute ); } $htmlArray = $this->render_media_markup( $media, $attr ); wp_send_json_success( $htmlArray ); } /** * Sends the Imsges to Grid AJAX. * * @since 2.1 */ public function render_grid_pagination() { check_ajax_referer( 'uagb_image_gallery_grid_pagination_ajax_nonce', 'nonce' ); $media_atts = array(); // sanitizing $attr elements in later stage. $attr = isset( $_POST['attr'] ) ? json_decode( stripslashes( $_POST['attr'] ), true ) : array(); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $attr['gridPageNumber'] = isset( $_POST['page_number'] ) ? sanitize_text_field( $_POST['page_number'] ) : ''; $media_atts = $this->required_atts( $attr ); $media_atts['mediaGallery'] = json_decode( $media_atts['mediaGallery'], true ); $media = $this->get_gallery_images( $media_atts, 'paginated' ); if ( ! $media ) { wp_send_json_error(); } foreach ( $attr as $key => $attribute ) { $attr[ $key ] = ( 'false' === $attribute ) ? false : ( ( 'true' === $attribute ) ? true : $attribute ); } $htmlArray = $this->render_media_markup( $media, $attr ); wp_send_json_success( $htmlArray ); } /** * Renders Entire Gallery HTML. * * @param array $media Part of Gallery Images. * @param array $attributes Array of block attributes. * * @since 2.1 */ private function render_media_markup( $media, $attributes ) { $totalImages = count( $media ); ob_start(); if ( 'masonry' === $attributes['feedLayout'] || ( 'grid' === $attributes['feedLayout'] && $attributes['feedPagination'] ) ) { for ( $i = 0; $i < $totalImages; $i++ ) { $this->render_masonry_hover_handler( (array) $media[ $i ], $attributes ); } } else { for ( $i = 0; $i < $totalImages; $i++ ) { $this->render_single_media( (array) $media[ $i ], $attributes ); } } return ob_get_clean(); } /** * Renders the Isotope Required Hover Handler to avoid padding triggering hover effects. * * @param array $mediaArray Array of current image's details. * @param array $atts Array of attributes. * * @since 2.1 */ private function render_masonry_hover_handler( $mediaArray, $atts ) { ?> window.addEventListener( 'DOMContentLoaded', function() { const scope = document.querySelector( '.uagb-block-' ); if ( scope ){ if ( scope.children[0].classList.contains( 'spectra-image-gallery__layout--masonry' ) ) { const element = scope.querySelector( '.spectra-image-gallery__layout--masonry' ); const isotope = new Isotope( element, { itemSelector: '.spectra-image-gallery__media-wrapper--isotope', } ); imagesLoaded( element ).on( 'progress', function() { isotope.layout(); }); imagesLoaded( element ).on( 'always', function() { element.parentNode.style.visibility = 'visible'; }); } UAGBImageGalleryMasonry.init( , '' ); } }); window.addEventListener( 'DOMContentLoaded', function() { const scope = document.querySelector( '.uagb-block-' ); if ( scope ){ if ( scope.children[0].classList.contains( 'spectra-image-gallery__layout--isogrid' ) ) { const element = scope.querySelector( '.spectra-image-gallery__layout--isogrid' ); const isotope = new Isotope( element, { itemSelector: '.spectra-image-gallery__media-wrapper--isotope', layoutMode: 'fitRows', } ); imagesLoaded( element ).on( 'progress', function() { isotope.layout(); }); } UAGBImageGalleryPagedGrid.init( , '' ); } }); window.addEventListener( 'DOMContentLoaded', function() { const scope = document.querySelector( '.uagb-block-' ); if ( scope ){ if ( scope.children[0].classList.contains( 'spectra-image-gallery__layout--tiled' ) ) { const element = scope.querySelector( '.spectra-image-gallery__layout--tiled' ); const tileSizer = scope.querySelector( '.spectra-image-gallery__media-sizer' ); element.style.gridAutoRows = `${ tileSizer.getBoundingClientRect().width }px`; imagesLoaded( element ).on( 'progress', ( theInstance, theImage ) => { if ( theImage.isLoaded ){ const imageElement = theImage.img; const imageWrapper = imageElement.parentElement.parentElement; const mediaWrapper = imageWrapper.parentElement; if( ! mediaWrapper.classList.contains( 'spectra-image-gallery__media-wrapper--focus' ) ){ if ( imageElement.naturalWidth >= ( imageElement.naturalHeight * 2 ) - ( imageElement.naturalHeight / 2 ) ){ mediaWrapper.classList.add( 'spectra-image-gallery__media-wrapper--wide'); imageWrapper.classList.add( 'spectra-image-gallery__media--tiled-wide'); } else if ( imageElement.naturalHeight >= ( imageElement.naturalWidth * 2 ) - ( imageElement.naturalWidth / 2 ) ){ mediaWrapper.classList.add( 'spectra-image-gallery__media-wrapper--tall'); imageWrapper.classList.add( 'spectra-image-gallery__media--tiled-tall'); } } } } ); tileSizer.style.display = 'none'; } } } ); window.addEventListener( 'DOMContentLoaded', () => { const blockScope = document.querySelector( '.uagb-block-' ); if ( ! blockScope ) { return; } let lightboxSwiper = null; let thumbnailSwiper = null; const theBody = document.querySelector( 'body' ); const updateCounter = ( curPage ) => { const lightbox = blockScope.nextElementSibling; const counter = lightbox.querySelector( '.spectra-image-gallery__control-lightbox--count-page' ); counter.innerHTML = parseInt( curPage ) + 1; }; const enableLightbox = ( goTo ) => { if ( ! lightboxSwiper ) { return; } const lightbox = blockScope.nextElementSibling; lightbox.style.display = ''; lightbox.focus(); setTimeout( () => { lightboxSwiper.slideTo( goTo ); }, 100 ); setTimeout( () => { lightbox.style.opacity = 1; theBody.style.overflow = 'hidden'; }, 250 ); } const images = blockScope.querySelectorAll( '.spectra-image-gallery__media-wrapper' ); for ( let i = 0; i < images.length; i++ ) { images[ i ].style.cursor = 'pointer'; images[ i ].addEventListener( 'click', () => enableLightbox( i ) ); } let lightboxSettings = ; thumbnailSwiper = new Swiper( "", ); lightboxSettings = { ...lightboxSettings, thumbs: { swiper: thumbnailSwiper, }, } lightboxSwiper = new Swiper( "", ); lightboxSwiper.on( 'activeIndexChange', ( swiperInstance ) => { thumbnailSwiper.slideTo( swiperInstance.activeIndex ); updateCounter( swiperInstance.activeIndex ); } ); thumbnailSwiper.on( 'activeIndexChange', ( swiperInstance ) => { lightboxSwiper.slideTo( swiperInstance.activeIndex ); } ); if ( blockScope.nextElementSibling.classList.contains( 'spectra-image-gallery__control-lightbox' ) ) { const lightbox = blockScope.nextElementSibling; lightbox.addEventListener( 'keydown', ( event ) => { if ( 27 === event.keyCode ) { theBody.style.overflow = ''; lightbox.style.opacity = 0; setTimeout( () => { lightbox.style.display = 'none'; }, 250 ); } } ); lightbox.style.display = 'none'; const closeButton = lightbox.querySelector( '.spectra-image-gallery__control-lightbox--close' ); if ( closeButton ) { closeButton.addEventListener( 'click', () => { theBody.style.overflow = ''; lightbox.style.opacity = 0; setTimeout( () => { lightbox.style.display = 'none'; }, 250 ); } ); } const lightboxTotal = lightbox.querySelector( '.spectra-image-gallery__control-lightbox--count-total' ); lightboxTotal.innerHTML = ''; } } ); window.addEventListener( 'DOMContentLoaded', () => { const blockScope = document.querySelector( '.uagb-block-' ); if ( ! blockScope ) { return; } const mediaGallery = ; const images = blockScope.querySelectorAll( '.spectra-image-gallery__media-wrapper' ); for ( let i = 0; i < images.length; i++ ) { const imageID = parseInt( images[ i ].getAttribute( 'data-spectra-gallery-image-id' ) ); const imageURL = mediaGallery[ imageID ]; images[ i ].style.cursor = 'pointer'; images[ i ].addEventListener( 'click', () => window.open( imageURL, '_blank' ) ); } } );