コード例 #1
0
ファイル: asset.php プロジェクト: andy-profi/bxApiDocs
 /**
  *
  * Moves all of scripts in front of </body>
  * @param string $content
  *
  * @internal
  */
 public function moveJsToBody(&$content)
 {
     if (!$this->getJsToBody()) {
         return;
     }
     $js = "";
     $offset = 0;
     $newContent = "";
     $areas = $this->getScriptAreas($content);
     foreach ($areas as $area) {
         if (String::getBinaryStrpos($area->attrs, "data-skip-moving") !== false || !self::isValidScriptType($area->attrs)) {
             continue;
         }
         $js .= String::getBinarySubstring($content, $area->openTagStart, $area->closingTagEnd - $area->openTagStart);
         $newContent .= String::getBinarySubstring($content, $offset, $area->openTagStart - $offset);
         $offset = $area->closingTagEnd;
     }
     if ($js === "") {
         return;
     }
     $newContent .= String::getBinarySubstring($content, $offset);
     $bodyEnd = String::getBinaryStrripos($newContent, "</body>");
     if ($bodyEnd === false) {
         $content = $newContent . $js;
     } else {
         $content = substr_replace($newContent, $js, $bodyEnd, 0);
     }
 }