Ordre de chargement des scripts et des styles
This commit is contained in:
parent
199ef99f3c
commit
ad962c7851
104
core/core.php
104
core/core.php
|
@ -107,22 +107,26 @@ class common {
|
|||
'state' => false,
|
||||
'style' => '',
|
||||
'title' => null, // Null car un titre peut être vide
|
||||
// Trié par ordre d'exécution
|
||||
'vendor' => [
|
||||
'jquery',
|
||||
'swiper',
|
||||
'simplelightbox'
|
||||
],
|
||||
'vendorCss' => [
|
||||
'normalize',
|
||||
'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',
|
||||
'zwiico',
|
||||
'imagemap',
|
||||
'simplelightbox',
|
||||
'swiper'
|
||||
],
|
||||
// Trié par ordre d'exécution
|
||||
'vendorJsBody' => [
|
||||
'lity',
|
||||
'filemanager',
|
||||
'tippy',
|
||||
'imagemap',
|
||||
],
|
||||
'view' => ''
|
||||
];
|
||||
// Langues proposées, conserver ces 5 variables $i18nList...
|
||||
|
@ -2134,9 +2138,8 @@ class common {
|
|||
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() {
|
||||
// Variables partagées
|
||||
|
@ -2149,39 +2152,86 @@ class common {
|
|||
$vars .= 'var privateKey = ' . json_encode(md5_file(self::DATA_DIR.'core.json')) . ';';
|
||||
}
|
||||
echo '<script>' . helper::minifyJs($vars) . '</script>';
|
||||
// Librairies
|
||||
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
|
||||
// Scripts
|
||||
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
|
||||
foreach($this->output['vendor'] as $vendorName) {
|
||||
// Coeur
|
||||
if(file_exists('core/vendor/' . $vendorName . '/inc.json')) {
|
||||
$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
|
||||
elseif(
|
||||
$moduleId
|
||||
$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>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* 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 file_exists('module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json')
|
||||
) {
|
||||
$vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/';
|
||||
}
|
||||
// Sinon continue
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
// Détermine le type d'import en fonction de l'extension de la librairie
|
||||
$vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
|
||||
foreach($vendorFiles as $vendorFile) {
|
||||
switch(pathinfo($vendorFile, PATHINFO_EXTENSION)) {
|
||||
case '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 . '">';
|
||||
break;
|
||||
case 'js':
|
||||
echo '<script src="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '"></script>';
|
||||
break;
|
||||
if(pathinfo($vendorFile, PATHINFO_EXTENSION) === 'css') {
|
||||
echo '<link rel="stylesheet" href="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '">';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Affiche à la fin du body l'import des scripts déclarés dans 'vendorJsBody'
|
||||
*/
|
||||
public function showVendorJsBody() {
|
||||
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>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,19 @@
|
|||
<?php
|
||||
$this->showMetaTitle();
|
||||
$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/mediaqueries.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">
|
||||
<?php $this->showStyle(); ?>
|
||||
<?php $this->showStyle();
|
||||
$this->showVendorCss();?>
|
||||
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css">
|
||||
<?php $this->showVendor(); ?>
|
||||
</head>
|
||||
<body>
|
||||
<?php $this->showContent(); ?>
|
||||
<?php $this->showScript(); ?>
|
||||
<?php $this->showVendorJsBody(); ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -6,14 +6,15 @@
|
|||
<?php
|
||||
$this->showMetaTitle();
|
||||
$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/mediaqueries.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">
|
||||
<?php $this->showStyle(); ?>
|
||||
<?php $this->showStyle();
|
||||
$this->showVendorCss(); ?>
|
||||
<link rel="stylesheet" href="<?php echo helper::baseUrl(false) . self::DATA_DIR; ?>custom.css">
|
||||
<?php $this->showVendor(); ?>
|
||||
</head>
|
||||
<body>
|
||||
<?php $this->showNotification(); ?>
|
||||
|
@ -21,5 +22,6 @@
|
|||
<section><?php $this->showContent(); ?></section>
|
||||
</div>
|
||||
<?php $this->showScript(); ?>
|
||||
<?php $this->showVendorJsBody(); ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -12,15 +12,14 @@ else { echo '<html lang="'.$lang.'">'; }
|
|||
$this->showMetaTitle();
|
||||
if( $this->getData(['config', 'social', 'headFacebook' ]) === true) $this->showMetaPropertyFacebook();
|
||||
?>
|
||||
<?php
|
||||
$this->showFavicon();
|
||||
$this->showVendor(); echo PHP_EOL;
|
||||
?>
|
||||
<?php $this->showFavicon(); ?>
|
||||
<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) . 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">
|
||||
<?php $this->showVendor(); ?>
|
||||
<!-- Détection RSS -->
|
||||
<?php if ( ( $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'blog'
|
||||
OR $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'news' )
|
||||
|
@ -246,6 +245,6 @@ else { echo '<html lang="'.$lang.'">'; }
|
|||
<?php $this->showCookies(); ?>
|
||||
<!-- Les scripts -->
|
||||
<?php $this->showScript();?>
|
||||
|
||||
<?php $this->showVendorJsBody(); ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue