/** * @file * Global utilities. * */ (function($, Drupal) { 'use strict'; var mql = window.matchMedia("(min-width: 768px)"); var is_mobile = !(mql.matches); var surhead = 40; if($('body').hasClass('ru')) { surhead = 0; } Drupal.behaviors.faureciarh = { attach: function(context, settings) { $(".node--type-page .accord").first().find('.card-header a').attr("aria-expanded", "true"); $(".node--type-page .accord").first().find('.card-header a').removeClass("collapsed"); $(".node--type-page .accord").first().find('.collapse').addClass("show"); $(".node--type-page-who .accord").first().find('.card-header a').attr("aria-expanded", "true"); $(".node--type-page-who .accord").first().find('.card-header a').removeClass("collapsed"); $(".node--type-page-who .accord").first().find('.collapse').addClass("show"); if($('.node--type-page .card-img-overlay').find('.field--name-field-text-long-unik1').length) { //standard page }else { $(".node--type-page .card-img-overlay").addClass("left-card"); } if(context.id == 'block-menuleft' || $('#block-menuleft').length) { $('#sidebar_first').show(); $('body').addClass('colleft'); } else { $('.main-content').addClass('nocolleft'); } if(is_mobile) { $('#block-menuleft').find('.bloc-lat-title').on('click', function(){ console.log(context.id); if($(this).siblings('.content').length && !$(this).hasClass('open')) { $(this).siblings('.content').slideDown(); $(this).addClass('open'); } else if($(this).siblings('.content').length && $(this).hasClass('open')) { $(this).siblings('.content').slideUp(); $(this).removeClass('open'); } }); } } }; if($('.switch_reseaux').length) { if($('.field--name-dynamic-block-fieldnode-bloc-twitter').length == 0) { $('.show_tw').hide(); $('.show_tw').removeClass('active'); if($('.field--name-dynamic-block-fieldnode-bloc-facebook').length) { $('.show_fb').addClass('active'); $('.field--name-dynamic-block-fieldnode-bloc-facebook').css('display', 'flex'); } else if($('.field--name-dynamic-block-fieldnode-bloc-youtube').length) { $('.show_yt').addClass('active'); $('.field--name-dynamic-block-fieldnode-bloc-youtube').css('display', 'flex'); } } if($('.field--name-dynamic-block-fieldnode-bloc-facebook').length == 0) { $('.show_fb').hide(); } if($('.field--name-dynamic-block-fieldnode-bloc-youtube').length == 0) { $('.show_yt').hide(); } $('.show_tw').on('click', function(){ $('.show_link').removeClass('active'); $(this).addClass('active'); $('.field--name-dynamic-block-fieldnode-bloc-youtube').hide(); $('.field--name-dynamic-block-fieldnode-bloc-facebook').hide(); $('.field--name-dynamic-block-fieldnode-bloc-twitter').css('display', 'flex'); }); $('.show_fb').on('click', function(){ $('.show_link').removeClass('active'); $(this).addClass('active'); $('.field--name-dynamic-block-fieldnode-bloc-youtube').hide(); $('.field--name-dynamic-block-fieldnode-bloc-twitter').hide(); $('.field--name-dynamic-block-fieldnode-bloc-facebook').css('display', 'flex'); }); $('.show_yt').on('click', function(){ $('.show_link').removeClass('active'); $(this).addClass('active'); $('.field--name-dynamic-block-fieldnode-bloc-twitter').hide(); $('.field--name-dynamic-block-fieldnode-bloc-facebook').hide(); $('.field--name-dynamic-block-fieldnode-bloc-youtube').css('display', 'flex'); }); } $(".carousel-control-next-icon").click(function(e){ var totalItems = $(this).parent().parent().parent().find('.carousel-item').length; var currentIndex = $(this).parent().parent().parent().find('div.active').index() + 2; if(currentIndex > totalItems) currentIndex = 1; var compteur = currentIndex; if(currentIndex < 10) compteur = "0" + currentIndex; $(this).parent().parent().find(".carousel-c1").html(compteur); var percent = (currentIndex/totalItems)*100; $(this).parent().parent().find(".carousel-percent").animate({width: percent + "%",}, 500, function() {}); }); $(".carousel-control-prev-icon").click(function(e){ var totalItems = $(this).parent().parent().parent().find('.carousel-item').length; var currentIndex = $(this).parent().parent().parent().find('div.active').index(); if(currentIndex < 1) currentIndex = totalItems; var compteur = currentIndex; if(currentIndex < 10) compteur = "0" + currentIndex; $(this).parent().parent().find(".carousel-c1").html(compteur); var percent = (currentIndex/totalItems)*100; $(this).parent().parent().find(".carousel-percent").animate({width: percent + "%",}, 500, function() {}); }); if($('#carousel-newsroom').length) { var slides = $('#carousel-newsroom').find('.carousel-item').length; if(slides === 1) { $('#carousel-newsroom').find('.carousel-newsroom-footer').addClass('hidden'); } } if($('#carousel-spotlight').length) { var slides = $('#carousel-spotlight').find('.carousel-item').length; if(slides === 1) { $('#carousel-spotlight').find('.carousel-spotlight-footer').addClass('hidden'); } } if($('#carousel-videohome').length) { var slides = $('#carousel-videohome').find('.carousel-item').length; if(slides === 1) { $('#carousel-videohome').find('.carousel-indicators').addClass('hidden'); } } $(".navbar-toggler-right").click(function(e){ var eTop = $('#navbar-main').offset().top; var doc = eTop + $(window).scrollTop(); if($("#CollapsingNavbar").css("right") == "0px") { $("#CollapsingNavbar").css("top", "80px"); $("#CollapsingNavbar").animate({right: '-100%',}, 1000, function() {}); } else { $("#CollapsingNavbar").animate({right: 0,}, 1000, function() {}); } }); $(".btn-close-nav").click(function(e){ $("#CollapsingNavbar").animate({right: '-100%',}, 1000, function() {}); }); $(".btn-search").click(function(e){ $(".search-bar").slideDown(); $(".btn-search").addClass('open'); }); if(is_mobile) { $(".cta-partage").click(function(e){ $(this).parent().find(".cta-rs").css('display', 'flex'); }); $(".navbar-toggler").on('click', function(){ if($('header').hasClass('open')) { $('header').removeClass('open'); } else { $('header').addClass('open'); } }); if($('body').hasClass('node--type-homepage')) { $('.keys_inner').slick({ dots: true, infinite: true, speed: 300, arrows: false, slidesToShow: 1, adaptiveHeight: true }) } $('#views-exposed-form-newsroom-page-1').find('label').on('click', function(){ if($(this).siblings('.form-select').length && !$(this).hasClass('open')) { $(this).siblings('.form-select').slideDown(); $(this).addClass('open'); } else if($(this).siblings('.form-select').length && $(this).hasClass('open')) { $(this).siblings('.form-select').slideUp(); $(this).removeClass('open'); } }); } else { $(".cta-partage").click(function(e){ $(this).parent().find(".cta-rs").show(); }); } $(".close-search").click(function(e){ $(".search-bar").slideUp(); $(".btn-search").removeClass('open'); }); $(".site-footer .navigation h2").click(function(e){ $(this).parent().find(".navbar-nav").slideDown(); }); $("#return_top img").click(function(e){ $("html, body").animate({scrollTop: 0 }, 1000); }); $(".strate-more").click(function(e){ $([document.documentElement, document.body]).animate({ scrollTop: $(".keys").offset().top - parseInt($("body").css('padding-top').replace("px", "")) }, 500); }); $('.paragraph--type-paragraph-documents').each(function(){ $(this).find('.field--name-field-file-unik1').find('.file--mime-application-pdf').children('a').text($(this).find('.field--name-field-text-unik1').html()); $(this).find('.field--name-field-file-unik1').find('.file--image').children('a').text($(this).find('.field--name-field-text-unik1').html()); }); $('.clickscroll').on('click', function(){ if($('body').hasClass('headerfixed')) { $([document.documentElement, document.body]).animate({ scrollTop: $("#targetscroll").offset().top - parseInt($("body").css('padding-top').replace("px", "")) }, 500); } else { $([document.documentElement, document.body]).animate({ scrollTop: $("#targetscroll").offset().top - parseInt($("body").css('padding-top').replace("px", "")) - $('#navbar-main').height() - $('#block-faureciarh-breadcrumbs').height() }, 500); } }); if($('body').hasClass('page-view-newsroom')) { var filterpos = $('.view-filters').offset().top - $("#navbar-main").outerHeight(); if($('body').hasClass('toolbar-fixed')) { filterpos = filterpos - 79; } } $(window).scroll(function() { if(!is_mobile) { if($("#CollapsingNavbar").css("right") == "0px") { $("#CollapsingNavbar").animate({right: '-100%',}, 1000, function() {}); $(".search-bar").slideUp(); } if($(this).scrollTop() > surhead) { $("#navbar-main").addClass('fixed'); $('body').addClass('headerfixed'); if($('body').hasClass('node--type-page-who') || $('body').hasClass('node--type-what-we-stand') || $('body').hasClass('node--type-news') || $('body').hasClass('node--type-page')) { var bread = parseInt($("body").css('padding-top').replace("px", "")) - 60; var side = parseInt($("body").css('padding-top').replace("px", "")) + $('#block-faureciarh-breadcrumbs').outerHeight() - 60; $('#navbar-top').css('opacity', 0); $('body').addClass('pagefixed'); $('#block-faureciarh-breadcrumbs').css('top', bread); $('#sidebar_first').css('top', side); $('#block-faureciarh-breadcrumbs').addClass('sticky'); $('#sidebar_first').width($('#sidebar_first').width()); $('#sidebar_first').addClass('sticky'); $('#sidebar_first').css('left', $('body').offset().left); if($('body').hasClass('colleft') || $('body').hasClass('node--type-page-who') || $('body').hasClass('node--type-what-we-stand') || $('body').hasClass('node--type-news')) { $('#content').css('padding-left', $('#sidebar_first').outerWidth() + 15); $('#content').addClass('stick'); } } if($('body').hasClass('page-view-newsroom')) { if($(this).scrollTop() > filterpos && !$('.view-filters').hasClass('stick')) { $('.view-filters').css('top', parseInt($("body").css('padding-top').replace("px", ""))); $('.view-filters').addClass('stick'); $('body').addClass('filterstick'); } if($(this).scrollTop() <= filterpos && $('.view-filters').hasClass('stick')) { $('.view-filters').css('top', 'auto'); $('.view-filters').removeClass('stick'); $('body').removeClass('filterstick'); } } } if($(this).scrollTop() <= surhead) { $("#navbar-main").removeClass('fixed'); $('body').removeClass('headerfixed'); if($('body').hasClass('node--type-page-who') || $('body').hasClass('node--type-what-we-stand') || $('body').hasClass('node--type-news') || $('body').hasClass('node--type-page')) { $('#navbar-top').css('opacity', 1); $('body').removeClass('pagefixed'); $('#block-faureciarh-breadcrumbs').css('top', 'auto'); $('#sidebar_first').css('top', 'auto'); $('#block-faureciarh-breadcrumbs').removeClass('sticky'); $('#sidebar_first').removeClass('sticky'); $('#sidebar_first').css('left', 'auto'); if($('body').hasClass('colleft') || $('body').hasClass('node--type-page-who') || $('body').hasClass('node--type-what-we-stand') || $('body').hasClass('node--type-news')) { $('#content').css('padding-left', '15px'); $('#content').removeClass('stick'); } } } } }); })(jQuery, Drupal);