/** * Adds a JS file to be loaded upon clientside rendering. Leave the localpath empty for remote files * @param \SimpleXMLElement The XML root * @param string The (full)path to the local JS file * @param string The (full)path to the remote file * @param int The \System\Web\BasePage\Page\InclusionLocation for inclusion location */ public function addJSFile(\SimpleXMLElement $xml, $localFile, $remoteFile, $location = \System\Web\BasePage\Page\InclusionLocation::LOCATION_HEAD) { if (!isset($xml->jsfiles)) { $xml->addChild('jsfiles'); } $jsFiles = $xml->jsfiles; $jsFile = $jsFiles->addChild('jsfile'); if ($localFile) { $file = new \System\IO\File($localFile); if (MINIFY_ENABLE && mb_strpos($file->getFilename(), self::JS_MIN_EXTENSION) === false && mb_strpos($file->getFilename(), self::JS_MIN_PACKED) === false) { $localMinFile = $file->getPath() . basename($file->getFilename(), self::JS_EXTENSION) . self::JS_MIN_EXTENSION; if (!file_exists($localMinFile)) { $file = \System\IO\File::writeContents($localMinFile, \System\Web\Minify\JS\Minify::minify($file->getContents())); } else { $file = new \System\IO\File($localMinFile); } $remoteFile = str_ireplace(self::JS_EXTENSION, self::JS_MIN_EXTENSION, $remoteFile); } $jsFile->addChild('filesize', $file->getFileSizeInBytes()); } $jsFile->addChild('name', $remoteFile); $jsFile->addChild('location', $location); }