2018-04-02 08:29:19 +02:00
/**
* This file is part of Zwii .
* For full copyright and license information , please see the LICENSE
* file that was distributed with this source code .
*
* @ author Rémi Jean < remi . jean @ outlook . com >
* @ copyright Copyright ( C ) 2008 - 2018 , Rémi Jean
2021-02-17 13:49:58 +01:00
* @ author Frédéric Tempez < frederic . tempez @ outlook . com >
* @ copyright Copyright ( C ) 2018 - 2021 , Frédéric Tempez
2018-04-02 08:29:19 +02:00
* @ license GNU General Public License , version 3
2020-09-01 20:48:40 +02:00
* @ link http :// zwiicms . fr /
2018-04-02 08:29:19 +02:00
*/
var core = {};
/**
* Crée un message d ' alerte
*/
core . alert = function ( text ) {
var lightbox = lity ( function ( $ ) {
return $ ( " <div> " )
. addClass ( " lightbox " )
. append (
$ ( " <span> " ) . text ( text ),
$ ( " <div> " )
. addClass ( " lightboxButtons " )
. append (
$ ( " <a> " )
. addClass ( " button " )
. text ( " Ok " )
. on ( " click " , function () {
lightbox . close ();
})
)
)
}( jQuery ));
// Validation de la lightbox avec le bouton entrée
$ ( document ) . on ( " keyup " , function ( event ) {
if ( event . keyCode === 13 ) {
lightbox . close ();
}
});
return false ;
};
/**
* Génère des variations d ' une couleur
*/
core . colorVariants = function ( rgba ) {
rgba = rgba . match ( / \ ( + ( .* ) \ ) / );
rgba = rgba [ 1 ] . split ( " , " );
return {
" normal " : " rgba( " + rgba [ 0 ] + " , " + rgba [ 1 ] + " , " + rgba [ 2 ] + " , " + rgba [ 3 ] + " ) " ,
" darken " : " rgba( " + Math . max ( 0 , rgba [ 0 ] - 15 ) + " , " + Math . max ( 0 , rgba [ 1 ] - 15 ) + " , " + Math . max ( 0 , rgba [ 2 ] - 15 ) + " , " + rgba [ 3 ] + " ) " ,
" veryDarken " : " rgba( " + Math . max ( 0 , rgba [ 0 ] - 20 ) + " , " + Math . max ( 0 , rgba [ 1 ] - 20 ) + " , " + Math . max ( 0 , rgba [ 2 ] - 20 ) + " , " + rgba [ 3 ] + " ) " ,
2020-05-22 17:57:03 +02:00
//"text": core.relativeLuminanceW3C(rgba) > .22 ? "inherit" : "white"
" text " : core . relativeLuminanceW3C ( rgba ) > . 22 ? " #222 " : " #DDD "
2018-04-02 08:29:19 +02:00
};
};
/**
* Crée un message de confirmation
*/
core . confirm = function ( text , yesCallback , noCallback ) {
var lightbox = lity ( function ( $ ) {
return $ ( " <div> " )
. addClass ( " lightbox " )
. append (
$ ( " <span> " ) . text ( text ),
$ ( " <div> " )
. addClass ( " lightboxButtons " )
. append (
$ ( " <a> " )
. addClass ( " button grey " )
. text ( " Non " )
. on ( " click " , function () {
lightbox . options ( 'button' , true );
lightbox . close ();
if ( typeof noCallback !== " undefined " ) {
noCallback ();
}
}),
$ ( " <a> " )
. addClass ( " button " )
. text ( " Oui " )
. on ( " click " , function () {
lightbox . options ( 'button' , true );
lightbox . close ();
if ( typeof yesCallback !== " undefined " ) {
yesCallback ();
}
})
)
)
}( jQuery ));
// Callback lors d'un clic sur le fond et sur la croix de fermeture
lightbox . options ( 'button' , false );
$ ( document ) . on ( 'lity:close' , function ( event , instance ) {
if (
instance . options ( 'button' ) === false
&& typeof noCallback !== " undefined "
) {
noCallback ();
}
});
// Validation de la lightbox avec le bouton entrée
$ ( document ) . on ( " keyup " , function ( event ) {
if ( event . keyCode === 13 ) {
lightbox . close ();
if ( typeof yesCallback !== " undefined " ) {
yesCallback ();
}
}
});
return false ;
};
/**
* Scripts à exécuter en dernier
*/
core . end = function () {
/**
* Modifications non enregistrées du formulaire
*/
var formDOM = $ ( " form " );
// Ignore :
// - TinyMCE car il gère lui même le message
// - Les champs avec data-no-dirty
var inputsDOM = formDOM . find ( " input:not([data-no-dirty]), select:not([data-no-dirty]), textarea:not(.editorWysiwyg):not([data-no-dirty]) " );
var inputSerialize = inputsDOM . serialize ();
$ ( window ) . on ( " beforeunload " , function () {
if ( inputsDOM . serialize () !== inputSerialize ) {
return " Les modifications que vous avez apportées ne seront peut-être pas enregistrées. " ;
}
});
formDOM . submit ( function () {
$ ( window ) . off ( " beforeunload " );
});
};
$ ( function () {
core . end ();
});
/**
* Ajoute une notice
*/
core . noticeAdd = function ( id , notice ) {
$ ( " # " + id + " Notice " ) . text ( notice ) . removeClass ( " displayNone " );
$ ( " # " + id ) . addClass ( " notice " );
};
/**
* Supprime une notice
*/
core . noticeRemove = function ( id ) {
$ ( " # " + id + " Notice " ) . text ( " " ) . addClass ( " displayNone " );
$ ( " # " + id ) . removeClass ( " notice " );
};
/**
* Scripts à exécuter en premier
*/
core . start = function () {
/**
* Remonter en haut au clic sur le bouton
*/
var backToTopDOM = $ ( " #backToTop " );
backToTopDOM . on ( " click " , function () {
$ ( " body, html " ) . animate ({ scrollTop : 0 }, " 400 " );
});
/**
* Affiche / Cache le bouton pour remonter en haut
*/
$ ( window ) . on ( " scroll " , function () {
if ( $ ( this ) . scrollTop () > 200 ) {
backToTopDOM . fadeIn ();
}
else {
backToTopDOM . fadeOut ();
}
});
/**
* Cache les notifications
*/
var notificationTimer ;
$ ( " #notification " )
. on ( " mouseenter " , function () {
clearTimeout ( notificationTimer );
$ ( " #notificationProgress " )
. stop ()
. width ( " 100% " );
})
. on ( " mouseleave " , function () {
// Disparition de la notification
notificationTimer = setTimeout ( function () {
$ ( " #notification " ) . fadeOut ();
2018-12-28 16:53:18 +01:00
}, 2000 );
2018-04-02 08:29:19 +02:00
// Barre de progression
$ ( " #notificationProgress " ) . animate ({
" width " : " 0% "
2018-12-28 16:53:18 +01:00
}, 2000 , " linear " );
2018-04-02 08:29:19 +02:00
})
. trigger ( " mouseleave " );
$ ( " #notificationClose " ) . on ( " click " , function () {
clearTimeout ( notificationTimer );
$ ( " #notification " ) . fadeOut ();
$ ( " #notificationProgress " ) . stop ();
});
/**
* Affiche / Cache le menu en mode responsive
*/
var menuDOM = $ ( " #menu " );
$ ( " #toggle " ) . on ( " click " , function () {
menuDOM . slideToggle ();
});
$ ( window ) . on ( " resize " , function () {
if ( $ ( window ) . width () > 768 ) {
menuDOM . css ( " display " , " " );
}
});
2019-07-31 17:47:26 +02:00
2018-04-02 08:29:19 +02:00
/**
* Message sur l ' utilisation des cookies
*/
2020-12-12 18:34:07 +01:00
var analytics = " " ;
2021-11-12 09:17:28 +01:00
if ( < ? php echo json_encode ( $this -> getData ([ 'config' , 'seo' , 'analyticsId' ])); ?> ) {
2020-12-12 18:34:07 +01:00
analytics = ' grâce au cookie Google Analytics'
}
2018-04-02 08:29:19 +02:00
if ( < ? php echo json_encode ( $this -> getData ([ 'config' , 'cookieConsent' ])); ?> ) {
if ( document . cookie . indexOf ( " ZWII_COOKIE_CONSENT " ) === - 1 ) {
$ ( " body " ) . append (
$ ( " <div> " ) . attr ( " id " , " cookieConsent " ) . append (
2020-12-12 18:34:07 +01:00
$ ( " <span> " ) . html ( " <p>Ce site utilise des cookies pour assurer l'authentification, améliorer l'expérience utilisateur " + analytics + " . <br/>En cliquant sur ”J’ accepte”, vous acceptez l’ utilisation de ces cookies.</p> " ),
2018-04-02 08:29:19 +02:00
$ ( " <span> " )
. attr ( " id " , " cookieConsentConfirm " )
2020-12-12 18:34:07 +01:00
. text ( " Accepter " )
2018-04-02 08:29:19 +02:00
. on ( " click " , function () {
// Créé le cookie d'acceptation
var expires = new Date ();
expires . setFullYear ( expires . getFullYear () + 1 );
expires = " expires= " + expires . toUTCString ();
document . cookie = " ZWII_COOKIE_CONSENT=true; " + expires ;
// Ferme le message
$ ( this ) . parents ( " #cookieConsent " ) . fadeOut ();
2020-12-12 18:34:07 +01:00
}),
$ ( " <span> " )
. attr ( " id " , " cookieConsentRefuse " )
. text ( " Refuser " )
. on ( " click " , function () {
// Créé le cookie d'acceptation
var expires = new Date ();
expires . setFullYear ( expires . getFullYear () + 1 );
expires = " expires= " + expires . toUTCString ();
document . cookie = " ZWII_COOKIE_CONSENT=false; " + expires ;
// Ferme le message
$ ( this ) . parents ( " #cookieConsent " ) . fadeOut ();
}),
2018-04-02 08:29:19 +02:00
)
);
}
}
/**
* Choix de page dans la barre de membre
*/
$ ( " #barSelectPage " ) . on ( " change " , function () {
var pageUrl = $ ( this ) . val ();
if ( pageUrl ) {
$ ( location ) . attr ( " href " , pageUrl );
}
});
/**
* Champs d ' upload de fichiers
*/
// Mise à jour de l'affichage des champs d'upload
$ ( " .inputFileHidden " ) . on ( " change " , function () {
var inputFileHiddenDOM = $ ( this );
var fileName = inputFileHiddenDOM . val ();
if ( fileName === " " ) {
fileName = " Choisissez un fichier " ;
2020-06-06 11:55:56 +02:00
$ ( inputFileHiddenDOM ) . addClass ( " disabled " );
2018-04-02 08:29:19 +02:00
}
else {
2020-06-06 11:55:56 +02:00
$ ( inputFileHiddenDOM ) . removeClass ( " disabled " );
2018-04-02 08:29:19 +02:00
}
inputFileHiddenDOM . parent () . find ( " .inputFileLabel " ) . text ( fileName );
}) . trigger ( " change " );
// Suppression du fichier contenu dans le champ
$ ( " .inputFileDelete " ) . on ( " click " , function () {
$ ( this ) . parents ( " .inputWrapper " ) . find ( " .inputFileHidden " ) . val ( " " ) . trigger ( " change " );
});
2021-05-14 19:14:59 +02:00
// Suppression de la date contenu dans le champ
$ ( " .inputDateDelete " ) . on ( " click " , function () {
$ ( this ) . parents ( " .inputWrapper " ) . find ( " .datepicker " ) . val ( " " ) . trigger ( " change " );
});
2018-04-02 08:29:19 +02:00
// Confirmation de mise à jour
$ ( " #barUpdate " ) . on ( " click " , function () {
return core . confirm ( " Effectuer la mise à jour ? " , function () {
$ ( location ) . attr ( " href " , $ ( " #barUpdate " ) . attr ( " href " ));
});
});
// Confirmation de déconnexion
$ ( " #barLogout " ) . on ( " click " , function () {
return core . confirm ( " Se déconnecter ? " , function () {
$ ( location ) . attr ( " href " , $ ( " #barLogout " ) . attr ( " href " ));
});
});
/**
* Bloque la multi - soumission des boutons
*/
$ ( " form " ) . on ( " submit " , function () {
$ ( this ) . find ( " .uniqueSubmission " )
. addClass ( " disabled " )
. prop ( " disabled " , true )
. empty ()
. append (
$ ( " <span> " ) . addClass ( " zwiico-spin animate-spin " )
)
});
/**
* Check adresse email
*/
$ ( " [type=email] " ) . on ( " change " , function () {
var _this = $ ( this );
var pattern = /^ ([ a - z\d ! #$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
if ( pattern . test ( _this . val ())) {
core . noticeRemove ( _this . attr ( " id " ));
}
else {
core . noticeAdd ( _this . attr ( " id " ), " Format incorrect " );
}
});
2019-11-11 19:12:19 +01:00
2018-04-02 08:29:19 +02:00
/**
* Iframes et vidéos responsives
*/
2019-09-23 20:36:41 +02:00
var elementDOM = $ ( " iframe, video, embed, object " );
2018-04-02 08:29:19 +02:00
// Calcul du ratio et suppression de la hauteur / largeur des iframes
elementDOM . each ( function () {
var _this = $ ( this );
_this
. data ( " ratio " , _this . height () / _this . width ())
2019-11-23 23:07:12 +01:00
. data ( " maxwidth " , _this . width ())
2018-04-02 08:29:19 +02:00
. removeAttr ( " width height " );
});
// Prend la largeur du parent et détermine la hauteur à l'aide du ratio lors du resize de la fenêtre
$ ( window ) . on ( " resize " , function () {
elementDOM . each ( function () {
var _this = $ ( this );
var width = _this . parent () . first () . width ();
2019-11-23 23:07:12 +01:00
if ( width > _this . data ( " maxwidth " )){ width = _this . data ( " maxwidth " );}
2018-04-02 08:29:19 +02:00
_this
. width ( width )
. height ( width * _this . data ( " ratio " ));
});
}) . trigger ( " resize " );
2019-03-14 19:04:03 +01:00
2019-11-11 19:12:19 +01:00
/*
* Header responsive
*/
$ ( window ) . on ( " resize " , function () {
var responsive = " <?php echo $this->getdata (['theme','header','imageContainer']);?> " ;
if ( responsive === " cover " || responsive === " contain " ) {
var widthpx = " <?php echo $this->getdata (['theme','site','width']);?> " ;
var width = widthpx . substr ( 0 , widthpx . length - 2 );
var heightpx = " <?php echo $this->getdata (['theme','header','height']);?> " ;
var height = heightpx . substr ( 0 , heightpx . length - 2 );
var ratio = width / height ;
2019-11-12 21:46:57 +01:00
if ( ( $ ( window ) . width () / ratio ) <= height ) {
$ ( " header " ) . height ( $ ( window ) . width () / ratio );
2020-08-08 17:06:06 +02:00
$ ( " header " ) . css ( " line-height " , $ ( window ) . width () / ratio + " px " );
}
2019-11-11 19:12:19 +01:00
}
}) . trigger ( " resize " );
2018-04-02 08:29:19 +02:00
};
2019-11-11 19:12:19 +01:00
2018-04-02 08:29:19 +02:00
core . start ();
2019-05-02 13:21:48 +02:00
/**
* Confirmation de suppression
*/
$ ( " #pageDelete " ) . on ( " click " , function () {
var _this = $ ( this );
return core . confirm ( " Êtes-vous sûr de vouloir supprimer cette page ? " , function () {
$ ( location ) . attr ( " href " , _this . attr ( " href " ));
});
});
2018-04-02 08:29:19 +02:00
/**
* Calcul de la luminance relative d ' une couleur
*/
core . relativeLuminanceW3C = function ( rgba ) {
// Conversion en sRGB
var RsRGB = rgba [ 0 ] / 255 ;
var GsRGB = rgba [ 1 ] / 255 ;
var BsRGB = rgba [ 2 ] / 255 ;
// Ajout de la transparence
var RsRGBA = rgba [ 3 ] * RsRGB + ( 1 - rgba [ 3 ]);
var GsRGBA = rgba [ 3 ] * GsRGB + ( 1 - rgba [ 3 ]);
var BsRGBA = rgba [ 3 ] * BsRGB + ( 1 - rgba [ 3 ]);
// Calcul de la luminance
var R = ( RsRGBA <= . 03 928 ) ? RsRGBA / 12.92 : Math . pow (( RsRGBA + . 055 ) / 1.055 , 2.4 );
var G = ( GsRGBA <= . 03 928 ) ? GsRGBA / 12.92 : Math . pow (( GsRGBA + . 055 ) / 1.055 , 2.4 );
var B = ( BsRGBA <= . 03 928 ) ? BsRGBA / 12.92 : Math . pow (( BsRGBA + . 055 ) / 1.055 , 2.4 );
return . 2126 * R + . 7152 * G + . 0722 * B ;
2019-07-31 17:47:26 +02:00
};
$ ( document ) . ready ( function (){
/**
2020-08-08 17:06:06 +02:00
* Affiche le sous - menu quand il est sticky
2019-07-31 17:47:26 +02:00
*/
$ ( " nav " ) . mouseenter ( function (){
2020-11-01 20:19:02 +01:00
$ ( " #navfixedlogout .navSub " ) . css ({ 'pointer-events' : 'auto' });
$ ( " #navfixedconnected .navSub " ) . css ({ 'pointer-events' : 'auto' });
2019-07-31 17:47:26 +02:00
});
$ ( " nav " ) . mouseleave ( function (){
2020-11-01 20:19:02 +01:00
$ ( " #navfixedlogout .navSub " ) . css ({ 'pointer-events' : 'none' });
$ ( " #navfixedconnected .navSub " ) . css ({ 'pointer-events' : 'none' });
2019-07-31 17:47:26 +02:00
});
2019-11-28 14:55:02 +01:00
2020-01-07 10:15:16 +01:00
/**
* Chargement paresseux des images et des iframes
*/
$ ( " img,picture,iframe " ) . attr ( " loading " , " lazy " );
2019-11-28 14:55:02 +01:00
/**
* Effet accordéon
*/
$ ( '.accordion' ) . each ( function ( e ) {
// on stocke l'accordéon dans une variable locale
var accordion = $ ( this );
// on récupère la valeur data-speed si elle existe
var toggleSpeed = accordion . attr ( 'data-speed' ) || 100 ;
2020-08-08 17:06:06 +02:00
// fonction pour afficher un élément
2019-11-28 14:55:02 +01:00
function open ( item , speed ) {
// on récupère tous les éléments, on enlève l'élément actif de ce résultat, et on les cache
accordion . find ( '.accordion-item' ) . not ( item ) . removeClass ( 'active' )
. find ( '.accordion-content' ) . slideUp ( speed );
// on affiche l'élément actif
item . addClass ( 'active' )
. find ( '.accordion-content' ) . slideDown ( speed );
}
2019-12-09 20:31:19 +01:00
function close ( item , speed ) {
accordion . find ( '.accordion-item' ) . removeClass ( 'active' )
. find ( '.accordion-content' ) . slideUp ( speed );
}
2019-11-28 14:55:02 +01:00
2020-08-08 17:06:06 +02:00
// on initialise l'accordéon, sans animation
2019-11-28 14:55:02 +01:00
open ( accordion . find ( '.active:first' ), 0 );
// au clic sur un titre...
accordion . on ( 'click' , '.accordion-title' , function ( ev ) {
2020-08-08 17:06:06 +02:00
ev . preventDefault ();
2019-12-09 17:13:55 +01:00
// Masquer l'élément déjà actif
if ( $ ( this ) . closest ( '.accordion-item' ) . hasClass ( 'active' )) {
2019-12-09 20:31:19 +01:00
close ( $ ( this ) . closest ( '.accordion-item' ), toggleSpeed );
2019-12-09 17:13:55 +01:00
} else {
2020-08-08 17:06:06 +02:00
// ...on lance l'affichage de l'élément, avec animation
open ( $ ( this ) . closest ( '.accordion-item' ), toggleSpeed );
2019-12-09 17:13:55 +01:00
}
2019-11-28 14:55:02 +01:00
});
});
2020-03-06 21:18:34 +01:00
/**
2020-08-08 17:06:06 +02:00
* Icône du Menu Burger
2020-03-06 21:18:34 +01:00
*/
2020-08-08 17:06:06 +02:00
$ ( " #toggle " ) . click ( function () {
2020-03-06 21:18:34 +01:00
var changeIcon = $ ( '#toggle' ) . children ( " span " );
if ( $ ( changeIcon ) . hasClass ( 'zwiico-menu' ) ) {
$ ( changeIcon ) . removeClass ( 'zwiico-menu' ) . addClass ( 'zwiico-cancel' );
}
2020-08-08 17:06:06 +02:00
else {
2020-03-06 21:18:34 +01:00
$ ( changeIcon ) . addClass ( 'zwiico-menu' );
};
});
2020-12-06 17:45:37 +01:00
2021-03-11 11:37:46 +01:00
/**
* Active le système d ' aide interne
*
*/
2021-05-20 21:52:09 +02:00
2021-05-09 10:41:19 +02:00
$ ( " .buttonHelp " ) . on ({
2021-05-08 11:18:54 +02:00
click : function () {
2021-05-05 15:36:05 +02:00
$ ( " .helpDisplayContent " ) . slideToggle ();
2021-05-09 10:41:19 +02:00
if ( $ ( " .buttonHelp " ) . css ( 'opacity' ) > '0.75' ){
$ ( " .buttonHelp " ) . css ( 'opacity' , '0.5' );
2021-05-08 11:18:54 +02:00
}
else {
2021-05-09 10:41:19 +02:00
$ ( " .buttonHelp " ) . css ( 'opacity' , '1' );
2021-05-08 11:18:54 +02:00
}
}
});
2020-12-06 17:45:37 +01:00
2021-01-09 11:46:32 +01:00
/**
2021-05-20 21:52:09 +02:00
* Remove ID Facebook from URL
2021-01-08 15:13:16 +01:00
*/
if ( /^ \ ? fbclid =/. test ( location . search ))
location . replace ( location . href . replace ( / \ ? fbclid .+/ , " " ));
2020-08-08 17:06:06 +02:00
});