mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
New router needs JavaScript and Stylesheet handlers fitting it's needs
This commit is contained in:
parent
b677a631f0
commit
5c89512e05
@ -25,15 +25,11 @@ class JavaScript
|
|||||||
);
|
);
|
||||||
|
|
||||||
protected static $vendorFiles = array(
|
protected static $vendorFiles = array(
|
||||||
'js/vendor/jquery-2.1.0.min.js',
|
// 'js/vendor/jquery-1.11.0',
|
||||||
'js/vendor/jquery.sparkline.min.js'
|
'js/vendor/jquery-2.1.0',
|
||||||
|
'js/vendor/jquery.sparkline'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function listFiles()
|
|
||||||
{
|
|
||||||
return array_merge(self::$vendorFiles, self::$jsFiles, self::listModuleFiles());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function listModuleFiles()
|
public static function listModuleFiles()
|
||||||
{
|
{
|
||||||
$list = array();
|
$list = array();
|
||||||
@ -46,18 +42,29 @@ class JavaScript
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function sendMinified()
|
public static function sendMinified()
|
||||||
|
{
|
||||||
|
return self::send(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function send($minified = false)
|
||||||
{
|
{
|
||||||
header('Content-Type: application/javascript');
|
header('Content-Type: application/javascript');
|
||||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||||
|
|
||||||
$js = $out = '';
|
$js = $out = '';
|
||||||
|
$min = $minified ? '.min' : '';
|
||||||
|
|
||||||
// TODO: Cache header
|
// TODO: Cache header
|
||||||
header('Content-Type: text/css');
|
header('Content-Type: application/javascript');
|
||||||
|
$cacheFile = '/tmp/cache_icinga' . $min . '.js';
|
||||||
|
if (file_exists($cacheFile)) {
|
||||||
|
readfile($cacheFile);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// We do not minify vendor files
|
// We do not minify vendor files
|
||||||
foreach (self::$vendorFiles as $file) {
|
foreach (self::$vendorFiles as $file) {
|
||||||
$out .= file_get_contents($basedir . '/' . $file);
|
$out .= file_get_contents($basedir . '/' . $file . $min . '.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (self::$jsFiles as $file) {
|
foreach (self::$jsFiles as $file) {
|
||||||
@ -69,8 +76,13 @@ class JavaScript
|
|||||||
$js .= file_get_contents($module->getJsFilename());
|
$js .= file_get_contents($module->getJsFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($minified) {
|
||||||
$out .= Minifier::minify($js, array('flaggedComments' => false));
|
$out .= Minifier::minify($js, array('flaggedComments' => false));
|
||||||
|
} else {
|
||||||
|
$out .= $js;
|
||||||
|
}
|
||||||
|
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
|
||||||
|
// file_put_contents($cacheFile, $out);
|
||||||
echo $out;
|
echo $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,35 @@ class StyleSheet
|
|||||||
return $less->compile();
|
return $less->compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function send()
|
public static function sendMinified()
|
||||||
|
{
|
||||||
|
self::send(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function send($minified = false)
|
||||||
{
|
{
|
||||||
header('Content-Type: text/css');
|
header('Content-Type: text/css');
|
||||||
|
|
||||||
|
$min = $minified ? '.min' : '';
|
||||||
|
$cacheFile = '/tmp/cache_icinga' . $min . '.css';
|
||||||
|
if (file_exists($cacheFile)) {
|
||||||
|
readfile($cacheFile);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$less = new LessCompiler();
|
$less = new LessCompiler();
|
||||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||||
foreach (self::$lessFiles as $file) {
|
foreach (self::$lessFiles as $file) {
|
||||||
$less->addFile($basedir . '/' . $file);
|
$less->addFile($basedir . '/' . $file);
|
||||||
}
|
}
|
||||||
echo $less->addLoadedModules()->compile();
|
$less->addLoadedModules();
|
||||||
|
if ($minified) {
|
||||||
|
$less->compress();
|
||||||
|
}
|
||||||
|
$out = $less->compile();
|
||||||
|
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
|
||||||
|
// file_put_contents($cacheFile, $out);
|
||||||
|
echo $out;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user