Add 'finalize' option to getCSSFileList() and getJSFileList(), to be used only by the final layout

This commit is contained in:
Kijin Sung 2016-05-06 22:01:58 +09:00
parent 1c43cbb126
commit 4290f5110c
3 changed files with 34 additions and 24 deletions

View file

@ -2270,11 +2270,12 @@ class Context
* Returns the list of javascripts that matches the given type.
*
* @param string $type Added position. (head:<head>..</head>, body:<body>..</body>)
* @param bool $finalize (optional)
* @return array Returns javascript file list. Array contains file, targetie.
*/
public static function getJsFile($type = 'head')
public static function getJsFile($type = 'head', $finalize = false)
{
return self::$_instance->oFrontEndFileHandler->getJsFileList($type);
return self::$_instance->oFrontEndFileHandler->getJsFileList($type, $finalize);
}
/**
@ -2322,11 +2323,12 @@ class Context
/**
* Return a list of css files
*
* @param bool $finalize (optional)
* @return array Returns css file list. Array contains file, media, targetie.
*/
public static function getCSSFile()
public static function getCSSFile($finalize = false)
{
return self::$_instance->oFrontEndFileHandler->getCssFileList();
return self::$_instance->oFrontEndFileHandler->getCssFileList($finalize);
}
/**

View file

@ -359,9 +359,10 @@ class FrontEndFileHandler extends Handler
/**
* Get css file list
*
* @param bool $finalize (optional)
* @return array Returns css file list. Array contains file, media, targetie.
*/
public function getCssFileList()
public function getCssFileList($finalize = false)
{
$map = &$this->cssMap;
$mapIndex = &$this->cssMapIndex;
@ -370,25 +371,28 @@ class FrontEndFileHandler extends Handler
$this->_sortMap($map, $mapIndex);
// Minify all scripts, and compile LESS/SCSS into CSS.
foreach ($map as $indexedMap)
if ($finalize)
{
foreach ($indexedMap as $file)
foreach ($map as $indexedMap)
{
$minify_this_file = !$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && (($file->isCommon && $minify !== 'none') || $minify === 'all');
if ($file->fileExtension === 'css')
foreach ($indexedMap as $file)
{
$this->proc_CSS_JS($file, $minify_this_file);
}
else
{
$this->proc_LESS_SCSS($file, $minify_this_file);
$minify_this_file = !$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && (($file->isCommon && $minify !== 'none') || $minify === 'all');
if ($file->fileExtension === 'css')
{
$this->proc_CSS_JS($file, $minify_this_file);
}
else
{
$this->proc_LESS_SCSS($file, $minify_this_file);
}
}
}
}
// Add all files to the final result.
$result = array();
if ($concat && count($concat_list = $this->_concatMap($map)))
if ($concat && $finalize && count($concat_list = $this->_concatMap($map)))
{
foreach ($concat_list as $concat_fileset)
{
@ -443,9 +447,10 @@ class FrontEndFileHandler extends Handler
* Get javascript file list
*
* @param string $type Type of javascript. head, body
* @param bool $finalize (optional)
* @return array Returns javascript file list. Array contains file, targetie.
*/
public function getJsFileList($type = 'head')
public function getJsFileList($type = 'head', $finalize = false)
{
if($type == 'head')
{
@ -463,20 +468,23 @@ class FrontEndFileHandler extends Handler
$this->_sortMap($map, $mapIndex);
// Minify all scripts.
foreach ($map as $indexedMap)
if ($finalize)
{
foreach ($indexedMap as $file)
foreach ($map as $indexedMap)
{
if (!$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && (($file->isCommon && $minify !== 'none') || $minify === 'all'))
foreach ($indexedMap as $file)
{
$this->proc_CSS_JS($file, true);
if (!$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && (($file->isCommon && $minify !== 'none') || $minify === 'all'))
{
$this->proc_CSS_JS($file, true);
}
}
}
}
// Add all files to the final result.
$result = array();
if ($concat && $type === 'head' && count($concat_list = $this->_concatMap($map)))
if ($concat && $finalize && $type === 'head' && count($concat_list = $this->_concatMap($map)))
{
foreach ($concat_list as $concat_fileset)
{

View file

@ -15,14 +15,14 @@
<title>{Context::getBrowserTitle()}</title>
<!-- CSS -->
<block loop="Context::getCssFile() => $key, $css_file">
<block loop="Context::getCssFile(true) => $key, $css_file">
<block cond="$css_file['targetie']"><!--[if {$css_file['targetie']}]><block cond="stripos($css_file['targetie'], 'gt') === 0"><!--></block></block>
<link rel="stylesheet" href="{$css_file['file']}" media="{$css_file['media']}"|cond="$css_file['media'] != 'all'" />
<block cond="$css_file['targetie']"><block cond="stripos($css_file['targetie'], 'gt') === 0"><!--</block><![endif]-->{"\n"}</block>
</block>
<!-- JS -->
<block loop="Context::getJsFile() => $key, $js_file">
<block loop="Context::getJsFile('head', true) => $key, $js_file">
<block cond="$js_file['targetie']"><!--[if {$js_file['targetie']}]><block cond="stripos($js_file['targetie'], 'gt') === 0"><!--></block></block>
<script src="{$js_file['file']}"></script>
<block cond="$js_file['targetie']"><block cond="stripos($js_file['targetie'], 'gt') === 0"><!--</block><![endif]-->{"\n"}</block>
@ -70,7 +70,7 @@
<div id="rhymix_debug_button"></div>
<!-- BODY JS -->
<block loop="Context::getJsFile('body') => $key, $js_file">
<block loop="Context::getJsFile('body', true) => $key, $js_file">
<block cond="$js_file['targetie']"><!--[if {$js_file['targetie']}]></block>
<script src="{$js_file['file']}"></script>
<block cond="$js_file['targetie']"><![endif]-->{"\n"}</block>