• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/page/asset.php
  • Класс: BitrixMainPageAsset
  • Вызов: Asset::moveJsToBody
public function moveJsToBody(&$content)
{
	if (!$this->getJsToBody())
	{
		return;
	}

	$js = "";
	$offset = 0;
	$newContent = "";
	$areas = $this->getScriptAreas($content);
	foreach ($areas as $area)
	{
		if (strpos($area->attrs, "data-skip-moving") !== false || !self::isValidScriptType($area->attrs))
		{
			continue;
		}

		$js .= substr($content, $area->openTagStart, $area->closingTagEnd - $area->openTagStart);
		$newContent .= substr($content, $offset, $area->openTagStart - $offset);
		$offset = $area->closingTagEnd;
	}

	if ($js === "")
	{
		return;
	}

	$newContent .= substr($content, $offset);
	$bodyEnd = strripos($newContent, "");
	if ($bodyEnd === false)
	{
		$content = $newContent.$js;
	}
	else
	{
		$content = substr_replace($newContent, $js, $bodyEnd, 0);
	}
}