/*******************************************************************************
* Auteurs : developpez.com (Atomya Rise, djibril, Torgar...)
* But : JS des articles de developpez.com
* Date : 15/03/2021
******************************************************************************/
/**********************************************************************************************************************************/
/******************************************* VARIABLES GLOBALES *******************************************************************/
/**********************************************************************************************************************************/
var hauteurSommaire, classNavSom, classToggle, TogglePlier, ToggleDeplier, hauteurContenuArticle, articleBody, LargeurEcranMobile;
var cheminImageKit = "https://www.developpez.com/template/kit/";
/**********************************************************************************************************************************/
/******************************************* DOCUMENT READY ***********************************************************************/
/**********************************************************************************************************************************/
jQuery(function($) {
/******************************************* On initialise les variables **********************************************************/
classNavSom = jQuery(".nav-sommaire"); // Section du sommaire
classToggle = jQuery(".ToggleGecko"); // Entete sommaire
TogglePlier = jQuery(".ToggleImgPlier");
ToggleDeplier = jQuery(".ToggleImgDeplier");
articleBody = jQuery(".articleBody"); // Corps de l'article
hauteurSommaire = classNavSom.height();
hauteurContenuArticle = articleBody.height();
/* Ecran mobile */
LargeurEcranMobile = 1090;
var LargeurEcran = $( window ).width();
var LargeurEcranVideo = LargeurEcran - 50;
/******************************************* Gestion des largeurs des sections d'entête *************************************************/
var LargeurSectionAuteurs = jQuery(".SectionAuteurs").css("width");
var LargeurSectionInformationArticle = jQuery(".SectionInformationArticle").css("width");
var LargeurSectionBookmarks = jQuery(".SectionBookmarks").css("width");
if ( LargeurEcran > LargeurEcranMobile ) {
if ( ! LargeurSectionBookmarks && (LargeurSectionAuteurs && LargeurSectionInformationArticle ) ) {
jQuery(".InfoAuthArtBook").css("grid-template-columns", "250px auto");
}
else if ( ! LargeurSectionAuteurs && (LargeurSectionBookmarks && LargeurSectionInformationArticle ) ) {
jQuery(".InfoAuthArtBook").css("grid-template-columns", "auto max-content");
}
else if ( ! LargeurSectionAuteurs && ! LargeurSectionBookmarks ) {
jQuery(".InfoAuthArtBook").css("grid-template-columns", "auto");
}
}
/******************************************* On récupère la position du sommaire *************************************************/
var positionSommaire;
// S'il y a un sommaire, on récupère la position.
if (classNavSom.length != 0) {
var positionSommaire = classNavSom.offset();
positionSommaire = positionSommaire.top;
}else
jQuery("article > section").css("grid-template-columns", "auto");
/******************************************* Déplacement de la licence **********************************************************/
var licence = jQuery('.licence').clone();
jQuery('.licence').remove();
jQuery('.ArticleComplet > section > div.contenu').append(licence);
/******************************************* Calcul des dimensions + resize de la fenêtre ***************************************/
calcul_dimensions();
jQuery(window).resize(
function() {
calcul_dimensions();
casMobile();
}
);
/******************************************* Si pas IE6 On gère le scroll pour fixer ou non le sommaire *************************/
if (version_ie() != 6 && hauteurContenuArticle > hauteurSommaire) {
jQuery(window).scroll(function() {
// Si la class StopArrondi n'est pas présente, alors le menu est déroulé
if (!classToggle.hasClass("StopArrondi")) {
// Si le scroll est supérieur à la hauteur de l'entête alors on fixe le sommaire
if (jQuery(window).scrollTop() >= positionSommaire)
fixed_activer();
// Sinon, on retire la class de fixation
else
fixed_desactiver();
// Si le sommaire est fermé, on supprime la class de fixation
} else
fixed_desactiver();
});
}
/******************************************* Toggle pour ouvrir et fermer le sommaire ******************************************/
classToggle.on('click', function() {
if (!$(this).hasClass('StopArrondi')) {
calcul_dimensions();
jQuery("#nav_sommaire_ul_principal").slideUp("slow",function(){
TogglePlier.hide();
ToggleDeplier.show();
classToggle.addClass("StopArrondi");
$(this).parents('nav.nav-sommaire').css('margin-bottom', '20px');
fixed_desactiver();
calcul_dimensions();
});
} else {
$(this).removeClass("StopArrondi");
calcul_dimensions();
jQuery("#nav_sommaire_ul_principal").slideDown("slow",function(){
ToggleDeplier.hide();
TogglePlier.show();
$(this).parents('nav.nav-sommaire').css('margin-bottom', '10px');
fixed_activer();
calcul_dimensions();
});
}
});
/******************************************* Présence de pub sur les faqs *****************************************************/
presencePubFaq();
/******************************************* Onglets pour les livres **********************************************************/
jQuery(".classLivreContenu").addClass("displayNone");
jQuery(".livreOnglets .classJsInfo").addClass("livreOngletActif");
jQuery(".livreDetails .classJsInfo").removeClass("displayNone");
jQuery(".classLivreOnglet").on('click',
function() {
// On récupère la première class
var parentId = jQuery(this).parent().parent().attr("id");
var divClass = jQuery(this).attr("class");
var recupDivClass = divClass.split(" ");
var classe1 = recupDivClass[0];
jQuery("#" + parentId + " .classLivreOnglet").removeClass("livreOngletActif");
jQuery(this).addClass("livreOngletActif");
jQuery("#" + parentId + " .classLivreContenu").addClass("displayNone");
jQuery("#" + parentId + " .livreDetails ."+classe1).removeClass("displayNone");
}
);
/******************************************* Gestion des popup des auteurs *****************************************************/
popup_modal_auteur();
// Améliorer le sommaire des pages de cours de developpez.com
if ( document.URL.indexOf("page=") < 0 ) {
if ( jQuery(".PageCours").length >=4 && jQuery(".ThemeCours").length >= 30 ) {
jQuery(".PageCours").prepend('
');
jQuery(".ListeCategorieCours").hide();
} else {
jQuery(".PageCours").prepend('
');
}
jQuery(".PageCours > img").css('cursor','pointer');
jQuery(".PageCours > img").mouseover(function() {
jQuery(this).next("a").css('background', "#DDDDFF");
});
jQuery(".PageCours > img").mouseleave(function() {
jQuery(this).next("a").css('background', "#FFFFFF");
});
jQuery(".PageCours > img").click(function() {
if( jQuery(this).attr("src") == "https://www.developpez.com/template/kit/kitplus.png" ) {
jQuery(this).attr("src", "https://www.developpez.com/template/kit/kitmoins.png" );
jQuery(this).next('a').next("ul").slideDown();
} else {
jQuery(this).attr("src", "https://www.developpez.com/template/kit/kitplus.png" );
jQuery(this).next('a').next("ul").slideUp();
}
});
}
/*
if ( document.URL.indexOf("page=") > 0 ) {
console.log('ancre : ' + location.hash );
console.log('search : ' + location.search );
}
*/
});
/**********************************************************************************************************************************/
/******************************************* FONCTION POUR VERSION IE *************************************************************/
/**********************************************************************************************************************************/
function version_ie() {
if (navigator.appVersion.indexOf('MSIE 6') > 0)
return 6;
else if (navigator.appVersion.indexOf('MSIE 7') > 0)
return 7;
else if (navigator.appVersion.indexOf('MSIE 8') > 0)
return 8;
else
return 0;
}
/**********************************************************************************************************************************/
/******************************************* FONCTION POUR FIXER OU NON LE SOMMAIRE ***********************************************/
/**********************************************************************************************************************************/
function fixed_activer() {
if ($('article#contenuArticle').length != 0 && $( window ).height() > $('article#contenuArticle').height())
return;
if ( $( window ).width() > LargeurEcranMobile )
classNavSom.addClass("fixed2");
}
function fixed_desactiver() {
if ( $( window ).width() > LargeurEcranMobile )
classNavSom.removeClass("fixed2");
}
/**********************************************************************************************************************************/
/******************************************* FONCTION POUR CALCULER LES DIMENSIONS SELON L'ECRAN **********************************/
/**********************************************************************************************************************************/
function calcul_dimensions() {
if ( $( window ).width() < LargeurEcranMobile )
return;
if (classNavSom.length != 0 && !classToggle.hasClass("StopArrondi")) {
var gtc = "300px auto";
if (hauteurSommaire > hauteurContenuArticle)
fixed_desactiver();
else {
fixed_activer();
var classNavSomUlPrinc = jQuery("#nav_sommaire_ul_principal");
if ((jQuery(window).height() - jQuery("#gabarit_pied").height()) < hauteurSommaire)
classNavSomUlPrinc.css("overflow-y", "scroll")
else
classNavSomUlPrinc.css("overflow-y", "auto")
}
} else {
var gtc = "auto";
fixed_desactiver();
}
jQuery(".contenuPage:not(#gabarit_mobile_contenuPage) article.ArticleComplet > section").css("grid-template-columns", gtc);
}
/**********************************************************************************************************************************/
/******************************************* FONCTION POUR AFFICHER/CACHER UN CODE ************************************************/
/**********************************************************************************************************************************/
function CacherMontreCode(elementId, IdTitreCode){
var ObjetCode = jQuery("#"+elementId); // Id de ol du code
var ObjettitreCode = jQuery("#"+IdTitreCode); // Id du div contenant le titre d'un code
var $parent = ObjettitreCode.parent('div.code_et_titre');
var $BaliseAParent = $parent.find('span.dissimuler_code a');
//
');
// Margin du pop-up pour centrer le pop-up
// Ajustement avec le CSS de 80px
var MarginTopPopup = (HauteurPopup + 80 ) / 2;
var MarginLeftPopup = (LargeurPopup + 80 ) / 2;
// Affectation du margin
DivPopupAuteurs.css({
'margin-top' : -MarginTopPopup,
'margin-left' : -MarginLeftPopup
});
// Effet fade-in du fond opaque
jQuery('body').append('