Ordre de chargement des scripts et des styles

This commit is contained in:
Deltacms 2023-02-02 11:23:37 +01:00
parent 199ef99f3c
commit ad962c7851
4 changed files with 90 additions and 37 deletions

View File

@ -107,22 +107,26 @@ class common {
'state' => false, 'state' => false,
'style' => '', 'style' => '',
'title' => null, // Null car un titre peut être vide 'title' => null, // Null car un titre peut être vide
// Trié par ordre d'exécution
'vendor' => [ 'vendor' => [
'jquery', 'jquery',
'swiper',
'simplelightbox'
],
'vendorCss' => [
'normalize', 'normalize',
'lity', 'lity',
'filemanager',
//'flatpickr', Appelé par les modules désactivé par défaut
// 'tinycolorpicker', Désactivé par défaut
// 'tinymce', Désactivé par défaut
// 'codemirror', // Désactivé par défaut
'tippy', 'tippy',
'zwiico', 'zwiico',
'imagemap',
'simplelightbox', 'simplelightbox',
'swiper' 'swiper'
], ],
// Trié par ordre d'exécution
'vendorJsBody' => [
'lity',
'filemanager',
'tippy',
'imagemap',
],
'view' => '' 'view' => ''
]; ];
// Langues proposées, conserver ces 5 variables $i18nList... // Langues proposées, conserver ces 5 variables $i18nList...
@ -2134,9 +2138,8 @@ class common {
echo '<style>' . helper::minifyCss($this->output['style']) . '</style>'; echo '<style>' . helper::minifyCss($this->output['style']) . '</style>';
} }
} }
/** /**
* Affiche l'import des librairies * Affiche dans le head l'import des scripts déclarés dans 'vendor' et ceux déclarés dans le dossier vendor des modules
*/ */
public function showVendor() { public function showVendor() {
// Variables partagées // Variables partagées
@ -2149,39 +2152,86 @@ class common {
$vars .= 'var privateKey = ' . json_encode(md5_file(self::DATA_DIR.'core.json')) . ';'; $vars .= 'var privateKey = ' . json_encode(md5_file(self::DATA_DIR.'core.json')) . ';';
} }
echo '<script>' . helper::minifyJs($vars) . '</script>'; echo '<script>' . helper::minifyJs($vars) . '</script>';
// Librairies // Scripts
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']); $moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
foreach($this->output['vendor'] as $vendorName) { foreach($this->output['vendor'] as $vendorName) {
// Coeur // Coeur
if(file_exists('core/vendor/' . $vendorName . '/inc.json')) { if(file_exists('core/vendor/' . $vendorName . '/inc.json')) {
$vendorPath = 'core/vendor/' . $vendorName . '/'; $vendorPath = 'core/vendor/' . $vendorName . '/';
}
// Modules
elseif( $moduleId
AND in_array($moduleId, self::$coreModuleIds) === false
AND file_exists('module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json')
) {
$vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/';
} else {
continue;
} }
// Module $vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
elseif( foreach($vendorFiles as $vendorFile) {
$moduleId if( pathinfo($vendorFile, PATHINFO_EXTENSION) === 'js') {
echo '<script src="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '"></script>';
}
}
}
}
/**
/**
* Affiche dans le head l'import des styles déclarés dans 'vendorCss' et ceux déclarés dans le dossier vendor des modules
*/
public function showVendorCss() {
foreach($this->output['vendorCss'] as $vendorName) {
if(file_exists('core/vendor/' . $vendorName . '/inc.json')) {
$vendorPath = 'core/vendor/' . $vendorName . '/';
} else {
continue;
}
$vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
foreach($vendorFiles as $vendorFile) {
if( pathinfo($vendorFile, PATHINFO_EXTENSION) === 'css') {
// Force le rechargement lors d'une mise à jour du jeu d'icônes
$reload = $vendorPath === 'core/vendor/zwiico/'
? '?' . md5_file('core/vendor/zwiico/css/zwiico-codes.css')
: '';
echo '<link rel="stylesheet" href="' . helper::baseUrl(false) . $vendorPath . $vendorFile . $reload . '">';
}
}
}
// Css du module avec fichier inc.json
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
foreach($this->output['vendor'] as $vendorName) {
if( $moduleId
AND in_array($moduleId, self::$coreModuleIds) === false AND in_array($moduleId, self::$coreModuleIds) === false
AND file_exists('module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json') AND file_exists('module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json')
) { ) {
$vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/'; $vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/';
} }
// Sinon continue
else { else {
continue; continue;
} }
// Détermine le type d'import en fonction de l'extension de la librairie
$vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json')); $vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
foreach($vendorFiles as $vendorFile) { foreach($vendorFiles as $vendorFile) {
switch(pathinfo($vendorFile, PATHINFO_EXTENSION)) { if(pathinfo($vendorFile, PATHINFO_EXTENSION) === 'css') {
case 'css': echo '<link rel="stylesheet" href="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '">';
// Force le rechargement lors d'une mise à jour du jeu d'icônes }
$reload = $vendorPath === 'core/vendor/zwiico/' }
? '?' . md5_file('core/vendor/zwiico/css/zwiico-codes.css') }
: ''; }
echo '<link rel="stylesheet" href="' . helper::baseUrl(false) . $vendorPath . $vendorFile . $reload . '">'; /**
break; * Affiche à la fin du body l'import des scripts déclarés dans 'vendorJsBody'
case 'js': */
echo '<script src="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '"></script>'; public function showVendorJsBody() {
break; foreach($this->output['vendorJsBody'] as $vendorName) {
if(file_exists('core/vendor/' . $vendorName . '/inc.json')) {
$vendorPath = 'core/vendor/' . $vendorName . '/';
} else {
continue;
}
$vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
foreach($vendorFiles as $vendorFile) {
if(pathinfo($vendorFile, PATHINFO_EXTENSION) === 'js') {
echo '<script src="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '"></script>';
} }
} }
} }

View File

@ -6,17 +6,19 @@
<?php <?php
$this->showMetaTitle(); $this->showMetaTitle();
$this->showFavicon(); $this->showFavicon();
$this->showVendor();
?> ?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/blank.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/blank.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css">
<?php $this->showStyle(); ?> <?php $this->showStyle();
$this->showVendorCss();?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css">
<?php $this->showVendor(); ?>
</head> </head>
<body> <body>
<?php $this->showContent(); ?> <?php $this->showContent(); ?>
<?php $this->showScript(); ?> <?php $this->showScript(); ?>
<?php $this->showVendorJsBody(); ?>
</body> </body>
</html> </html>

View File

@ -6,14 +6,15 @@
<?php <?php
$this->showMetaTitle(); $this->showMetaTitle();
$this->showFavicon(); $this->showFavicon();
$this->showVendor();
?> ?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/light.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/light.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css">
<?php $this->showStyle(); ?> <?php $this->showStyle();
$this->showVendorCss(); ?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css">
<?php $this->showVendor(); ?>
</head> </head>
<body> <body>
<?php $this->showNotification(); ?> <?php $this->showNotification(); ?>
@ -21,5 +22,6 @@
<section><?php $this->showContent(); ?></section> <section><?php $this->showContent(); ?></section>
</div> </div>
<?php $this->showScript(); ?> <?php $this->showScript(); ?>
<?php $this->showVendorJsBody(); ?>
</body> </body>
</html> </html>

View File

@ -12,15 +12,14 @@ else { echo '<html lang="'.$lang.'">'; }
$this->showMetaTitle(); $this->showMetaTitle();
if( $this->getData(['config', 'social', 'headFacebook' ]) === true) $this->showMetaPropertyFacebook(); if( $this->getData(['config', 'social', 'headFacebook' ]) === true) $this->showMetaPropertyFacebook();
?> ?>
<?php <?php $this->showFavicon(); ?>
$this->showFavicon();
$this->showVendor(); echo PHP_EOL;
?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/common.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false); ?>core/layout/mediaqueries.css">
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>theme.css">
<?php $this->showStyle(); ?> <?php $this->showStyle();
$this->showVendorCss(); echo PHP_EOL;?>
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css"> <link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css">
<?php $this->showVendor(); ?>
<!-- Détection RSS --> <!-- Détection RSS -->
<?php if ( ( $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'blog' <?php if ( ( $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'blog'
OR $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'news' ) OR $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'news' )
@ -246,6 +245,6 @@ else { echo '<html lang="'.$lang.'">'; }
<?php $this->showCookies(); ?> <?php $this->showCookies(); ?>
<!-- Les scripts --> <!-- Les scripts -->
<?php $this->showScript();?> <?php $this->showScript();?>
<?php $this->showVendorJsBody(); ?>
</body> </body>
</html> </html>