Revert "js: Don't serve scripts utilizing ECMA2016+ features"

This reverts commit 4d4f5b3a69f74b939c85fa9510c11ec1be75377c.
This commit is contained in:
Sukhwinder Dhillon 2022-04-29 11:25:03 +02:00 committed by Johannes Meyer
parent f1e8280c3e
commit e4450e7368
3 changed files with 26 additions and 38 deletions

View File

@ -63,13 +63,11 @@ if (in_array($path, $special)) {
exit; exit;
case 'js/icinga.dev.js': case 'js/icinga.dev.js':
$forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']); JavaScript::send();
JavaScript::send(false, $forIe11);
exit; exit;
case 'js/icinga.min.js': case 'js/icinga.min.js':
$forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']); JavaScript::sendMinified();
JavaScript::sendMinified($forIe11);
break; break;
default: default:

View File

@ -53,9 +53,9 @@ class JavaScript
'js/define.js' 'js/define.js'
]; ];
public static function sendMinified($forIe11 = false) public static function sendMinified()
{ {
self::send(true, $forIe11); self::send(true);
} }
/** /**
@ -65,7 +65,7 @@ class JavaScript
* *
* @param bool $minified Whether to compress the client side script code * @param bool $minified Whether to compress the client side script code
*/ */
public static function send($minified = false, $forIe11 = false) public static function send($minified = false)
{ {
header('Content-Type: application/javascript'); header('Content-Type: application/javascript');
$basedir = Icinga::app()->getBootstrapDirectory(); $basedir = Icinga::app()->getBootstrapDirectory();
@ -91,11 +91,9 @@ class JavaScript
$files[] = $filePath; $files[] = $filePath;
} }
if (! $forIe11) { // Prepare library file list
// Prepare library file list foreach (Icinga::app()->getLibraries() as $library) {
foreach (Icinga::app()->getLibraries() as $library) { $files = array_merge($files, $library->getJsAssets());
$files = array_merge($files, $library->getJsAssets());
}
} }
// Prepare core file list // Prepare core file list
@ -151,28 +149,26 @@ class JavaScript
$baseJs .= file_get_contents($file) . "\n\n\n"; $baseJs .= file_get_contents($file) . "\n\n\n";
} }
if (! $forIe11) { // Library files need to be namespaced first before they can be included
// Library files need to be namespaced first before they can be included foreach (Icinga::app()->getLibraries() as $library) {
foreach (Icinga::app()->getLibraries() as $library) { foreach ($library->getJsAssets() as $file) {
foreach ($library->getJsAssets() as $file) { $alreadyMinified = false;
$alreadyMinified = false; if ($minified && file_exists(($minFile = substr($file, 0, -3) . '.min.js'))) {
if ($minified && file_exists(($minFile = substr($file, 0, -3) . '.min.js'))) { $alreadyMinified = true;
$alreadyMinified = true; $file = $minFile;
$file = $minFile; }
}
$content = self::optimizeDefine( $content = self::optimizeDefine(
file_get_contents($file), file_get_contents($file),
$file, $file,
$library->getJsAssetPath(), $library->getJsAssetPath(),
$library->getName() $library->getName()
); );
if ($alreadyMinified) { if ($alreadyMinified) {
$out .= ';' . ltrim(trim($content), ';') . "\n"; $out .= ';' . ltrim(trim($content), ';') . "\n";
} else { } else {
$js .= $content . "\n\n\n"; $js .= $content . "\n\n\n";
}
} }
} }
} }

View File

@ -1,11 +1,5 @@
/*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */ /*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
/* IE11 Polyfills */
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
/* jQuery Plugins */ /* jQuery Plugins */
(function ($) { (function ($) {