• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/assets/preprocessing/lazyload.php
  • Класс: BitrixLandingAssetsPreProcessingLazyload
  • Вызов: Lazyload::parseBg
protected function parseBg(DOMElement $node, string $selector): void
{
	$styles = DOMStyleInliner::getStyle($node, false);
	if (!$styles['background-image'])
	{
		return;
	}
	$origBg = implode('|', $styles['background-image']);

	// get sizes for placeholder
	if (
		($fileId = $node->getAttribute('data-fileid'))
		&& $fileId > 0
		&& ($fileArray = File::getFileArray($fileId))
	)
	{
		$width = $fileArray['WIDTH'];
		$height = $fileArray['HEIGHT'];
	}
	else if ($manifestSize = $this->getPlaceholderSizeFromManifest($selector))
	{
		[$width, $height] = $manifestSize;
	}
	else
	{
		$width = $height = self::BG_PLACEHOLDER_SIZE_DEFAULT;
	}

	$node->setAttribute('data-lazy-bg', 'Y');
	$node->setAttribute('data-bg', $origBg);

	$lazySrc = $this->createPlaceholderImage($width, $height);
	DOMStyleInliner::setStyle($node, array_merge($styles, ['background-image' => ["url({$lazySrc})"]]));
	if ($origSrc = self::getSrcByBgStyle($origBg))
	{
		if (isset($origSrc['src']))
		{
			$node->setAttribute('data-src', $origSrc['src']);
		}
		if (isset($origSrc['src2x']))
		{
			$node->setAttribute('data-src2x', $origSrc['src2x']);
		}
	}
}