js: Don't serve scripts utilizing ECMA2016+ features

i.e. library javascript assets
This commit is contained in:
Johannes Meyer 2021-02-22 16:01:42 +01:00
parent 64d1574972
commit 4d4f5b3a69
4 changed files with 46 additions and 29 deletions

View File

@ -63,11 +63,13 @@ if (in_array($path, $special)) {
exit; exit;
case 'js/icinga.dev.js': case 'js/icinga.dev.js':
JavaScript::send(); $forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']);
JavaScript::send(false, $forIe11);
exit; exit;
case 'js/icinga.min.js': case 'js/icinga.min.js':
JavaScript::sendMinified(); $forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']);
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() public static function sendMinified($forIe11 = false)
{ {
self::send(true); self::send(true, $forIe11);
} }
/** /**
@ -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) public static function send($minified = false, $forIe11 = false)
{ {
header('Content-Type: application/javascript'); header('Content-Type: application/javascript');
$basedir = Icinga::app()->getBootstrapDirectory(); $basedir = Icinga::app()->getBootstrapDirectory();
@ -91,10 +91,12 @@ 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
$coreFiles = []; $coreFiles = [];
@ -154,6 +156,7 @@ class JavaScript
$js .= file_get_contents($file) . "\n\n\n"; $js .= 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) {
@ -177,6 +180,7 @@ class JavaScript
} }
} }
} }
}
foreach ($coreFiles as $file) { foreach ($coreFiles as $file) {
$js .= file_get_contents($file) . "\n\n\n"; $js .= file_get_contents($file) . "\n\n\n";

View File

@ -1,5 +1,11 @@
/*! 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 ($) {

View File

@ -7,9 +7,14 @@
"use strict"; "use strict";
try {
var FilterInput = require('icinga/ipl/widget/FilterInput'); var FilterInput = require('icinga/ipl/widget/FilterInput');
var TermInput = require('icinga/ipl/widget/TermInput'); var TermInput = require('icinga/ipl/widget/TermInput');
var Completer = require('icinga/ipl/widget/Completer'); var Completer = require('icinga/ipl/widget/Completer');
} catch (e) {
console.warn('Unable to provide input enrichments. Libraries not available:', e);
return;
}
Icinga.Behaviors = Icinga.Behaviors || {}; Icinga.Behaviors = Icinga.Behaviors || {};