2023-11-30 17:33:32 +01:00
/ * *
* @ file
* erabletheme behaviors .
* /
( function ( Drupal ) {
'use strict' ;
Drupal . behaviors . erabletheme = {
attach : function ( context , settings ) {
2023-12-15 20:04:59 +01:00
//
// Carrousel
//
2023-12-06 17:06:45 +01:00
( function ( $ , window ) {
let slickEl = $ ( '.slick-container' ) . children ( ) . first ( ) . children ( ) . first ( ) . children ( ) . first ( ) . children ( ) . first ( ) ;
$ ( slickEl ) . slick ( {
dots : true ,
appendDots : $ ( '#carousel_dots' )
} ) ;
} ) ( jQuery , window ) ;
2023-12-14 06:01:09 +01:00
//
// Toggle du menu
//
2023-12-06 05:01:23 +01:00
const hamburgerBtn = document . getElementById ( "hamburger" ) ;
2023-12-14 06:01:09 +01:00
const hamburgerIcon = document . querySelector ( ".burger-icon" ) ;
2023-12-06 05:01:23 +01:00
const menu = hamburgerBtn . nextElementSibling ;
2023-12-14 06:01:09 +01:00
const menuItems = menu . children ;
const opacityDelay = 50 ;
function toggleMenuItems ( action ) {
let delay = opacityDelay ;
for ( let i = 0 ; i < menuItems . length ; i ++ ) {
setTimeout ( ( ) => {
if ( action === 'show' ) {
menuItems [ i ] . classList . add ( 'visible' ) ;
} else if ( action === 'hide' ) {
menuItems [ menuItems . length - i - 1 ] . classList . remove ( 'visible' ) ;
}
} , delay ) ;
delay += opacityDelay ;
}
}
2023-12-15 20:04:59 +01:00
2023-12-06 05:01:23 +01:00
// Toggle menu visibility on hamburger click
hamburgerBtn . addEventListener ( "click" , function ( event ) {
event . stopPropagation ( ) ;
2023-12-14 06:01:09 +01:00
hamburgerIcon . classList . toggle ( 'open' ) ;
if ( menu . classList . contains ( 'active' ) ) {
setTimeout ( ( ) => {
menu . style . display = "none" ;
} , 700 ) ;
toggleMenuItems ( 'hide' ) ;
} else {
2023-12-15 20:04:59 +01:00
menu . style . display = "flex" ;
2023-12-14 06:01:09 +01:00
toggleMenuItems ( 'show' ) ;
}
setTimeout ( ( ) => {
menu . classList . toggle ( "active" ) ;
} , 1 ) ;
2023-12-06 05:01:23 +01:00
} ) ;
// Close menu when clicking outside of the menu
document . addEventListener ( "click" , function ( event ) {
const isHamburgerClicked = event . target === hamburgerBtn ;
2023-12-14 06:01:09 +01:00
const isMenuClicked = event . target === menu || event . target . parentElement === menu ;
2023-12-06 05:01:23 +01:00
if ( ! isMenuClicked && ! isHamburgerClicked ) {
2023-12-14 06:01:09 +01:00
hamburgerIcon . classList . remove ( 'open' ) ;
2023-12-06 05:01:23 +01:00
menu . classList . remove ( "active" ) ;
2023-12-14 06:01:09 +01:00
toggleMenuItems ( 'hide' ) ;
2023-12-15 20:04:59 +01:00
setTimeout ( ( ) => {
menu . style . display = "none" ;
} , 700 ) ;
2023-12-06 05:01:23 +01:00
}
} ) ;
2023-12-15 20:04:59 +01:00
//
// Fixed links
//
let fluoButtons ;
if ( document . querySelector ( '.actu_full' ) ) {
fluoButtons = document . querySelectorAll ( '.liens_fixed > div > div:nth-of-type(2):not(.visually-hidden), .file_fixed > div > .visually-hidden + div > div' ) ;
} else {
fluoButtons = document . querySelectorAll ( '.liens_fixed > div > div:not(.visually-hidden), .file_fixed > div > div' ) ;
}
let footer = document . querySelector ( '#footer_top' ) ;
function positionFluoLinks ( ) {
for ( let i = fluoButtons . length ; i > 0 ; i -- ) {
let prevButtonBottom = fluoButtons [ i ] ? parseInt ( fluoButtons [ i ] . style . bottom ) : 0 ;
let prevButtonHeight = fluoButtons [ i ] ? fluoButtons [ i ] . offsetHeight : 0 ;
if ( footer . offsetTop < window . innerHeight + window . scrollY && i === fluoButtons . length ) {
fluoButtons [ i - 1 ] . style . bottom = ` ${ window . innerHeight - footer . offsetTop + window . scrollY + 30 } px ` ;
} else {
fluoButtons [ i - 1 ] . style . bottom = i === fluoButtons . length ? '30px' : ` ${ prevButtonBottom + prevButtonHeight + 15 } px ` ;
}
}
}
if ( document . querySelector ( '.fullpage' ) ) {
positionFluoLinks ( ) ;
document . addEventListener ( 'scroll' , ( ) => {
positionFluoLinks ( ) ;
} ) ;
window . addEventListener ( 'resize' , ( ) => {
positionFluoLinks ( ) ;
} ) ;
}
//
// Ajouter les logos réseaux sociaux dans le menu togglable
//
let socials = document . querySelector ( '.social-media-links--platforms' ) ;
let socialsClone = socials . cloneNode ( true ) ;
socialsClone . id = 'socials-in-menu-wrapper' ;
let menuContainer = document . querySelector ( '#hamburger + ul' ) ;
let socialsContainer = document . createElement ( 'li' ) ;
socialsContainer . append ( socialsClone ) ;
menuContainer . append ( socialsContainer ) ;
2023-11-30 17:33:32 +01:00
}
} ;
} ( Drupal ) ) ;