Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryLargeImage::update_single_imageprivateWC 1.0

Update the single image html.

Method of the class: ProductGalleryLargeImage{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->update_single_image( $image_html, $context, $index );
$image_html(string) (required)
The image html.
$context(array) (required)
The block context.
$index(int) (required)
The index of the image.

ProductGalleryLargeImage::update_single_image() code WC 10.9.4

private function update_single_image( $image_html, $context, $index ) {
	$p = new \WP_HTML_Tag_Processor( $image_html );

	if ( $p->next_tag( 'a' ) ) {
		$p->remove_attribute( 'onclick' );
		$p->remove_attribute( 'style' );
		$p->set_attribute( 'tabindex', '-1' );
	} else {
		/**
		 * If we can't find and <a> tag, we're at the end of the document.
		 * We need to reinitialize the processor instance to search for <img> tag.
		 */
		$p = new \WP_HTML_Tag_Processor( $image_html );
	}

	// Bail out early if we don't find any image.
	if ( ! $p->next_tag( 'img' ) ) {
		return $image_html;
	}

	$p->set_attribute( 'tabindex', '-1' );
	$p->set_attribute( 'draggable', 'false' );
	$p->set_attribute( 'data-wp-watch', 'callbacks.toggleImageVisibility' );
	$p->set_attribute( 'data-wp-on--click', 'actions.onViewerClick' );
	$p->set_attribute( 'data-wp-on--touchstart', 'actions.onTouchStart' );
	$p->set_attribute( 'data-wp-on--touchmove', 'actions.onTouchMove' );
	$p->set_attribute( 'data-wp-on--touchend', 'actions.onTouchEnd' );

	if ( 0 === $index ) {
		$p->set_attribute( 'fetchpriority', 'high' );
		$p->set_attribute( 'loading', 'eager' );
	} else {
		$p->set_attribute( 'fetchpriority', 'low' );
		$p->set_attribute( 'loading', 'lazy' );
	}

	$img_classes = 'wc-block-woocommerce-product-gallery-large-image__image';

	if ( ! empty( $context['fullScreenOnClick'] ) ) {
		$img_classes .= ' wc-block-woocommerce-product-gallery-large-image__image--full-screen-on-click';

		$p->set_attribute( 'data-wp-on--click', 'actions.openDialog' );
	}
	if ( ! empty( $context['hoverZoom'] ) ) {
		$img_classes .= ' wc-block-woocommerce-product-gallery-large-image__image--hoverZoom';

		$p->set_attribute( 'data-wp-on--mousemove', 'actions.startZoom' );
		$p->set_attribute( 'data-wp-on--mouseleave', 'actions.resetZoom' );
	}

	$p->add_class( $img_classes );

	return $p->get_updated_html();
}