- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/assets/preprocessing/lazyload.php
- Класс: BitrixLandingAssetsPreProcessingLazyload
- Вызов: Lazyload::parseImgTag
protected function parseImgTag(DOMElement $node, string $selector): void
{
$origSrc = $node->getAttribute('src');
if (!$origSrc)
{
return;
}
// 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::IMG_PLACEHOLDER_SIZE_DEFAULT;
}
$lazySrc = $this->createPlaceholderImage($width, $height);
$node->setAttribute('data-lazy-img', 'Y');
$node->setAttribute('data-src', $origSrc);
$node->setAttribute('src', $lazySrc);
$node->setAttribute('loading', 'lazy'); //for native
if ($srcset = $node->getAttribute('srcset'))
{
$node->removeAttribute('srcset');
$node->setAttribute('data-srcset', $srcset);
}
}