2023-11-30 17:33:32 +01:00
/ * *
* @ file
* erabletheme behaviors .
* /
2024-11-06 02:46:29 +01:00
( function ( $ , Drupal ) {
2023-11-30 17:33:32 +01:00
'use strict' ;
Drupal . behaviors . erabletheme = {
attach : function ( context , settings ) {
2023-12-15 20:04:59 +01:00
//
// Carrousel
//
2024-11-07 23:49:56 +01:00
const isTaxonomyPage = document . querySelector ( '.taxonomy_page' ) ? true : false ;
if ( $ ( '.slick-container' ) && ! isTaxonomyPage ) {
2024-11-05 23:30:16 +01:00
let slickEl = $ ( '.slick-container' ) . find ( 'div' ) . eq ( 3 ) ;
2023-12-06 17:06:45 +01:00
$ ( slickEl ) . slick ( {
2024-10-31 20:08:58 +01:00
centerMode : true ,
slidesToShow : 3 ,
2023-12-06 17:06:45 +01:00
dots : true ,
2024-10-31 20:08:58 +01:00
appendDots : $ ( '#carousel_dots' ) ,
responsive : [
{
breakpoint : 760 ,
settings : {
slidesToShow : 1
}
} ,
] ,
2023-12-06 17:06:45 +01:00
} ) ;
2024-11-06 02:46:29 +01:00
}
2024-11-07 23:49:56 +01:00
if ( $ ( '.diapo' ) && ! isTaxonomyPage ) {
2024-11-06 02:46:29 +01:00
let slickEl = $ ( '.diapo > div > div' ) ; $ ( slickEl ) . slick ( {
dots : true ,
appendDots : $ ( '#carousel_dots' ) ,
} ) ;
}
2023-12-06 17:06:45 +01:00
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 ;
2023-12-17 16:49:23 +01:00
let inTransition = false ;
2023-12-14 06:01:09 +01:00
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 ;
}
}
2024-10-31 01:32:57 +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-17 16:49:23 +01:00
if ( ! inTransition ) {
inTransition = true ;
hamburgerIcon . classList . toggle ( 'open' ) ;
if ( menu . classList . contains ( 'active' ) ) {
setTimeout ( ( ) => {
menu . style . display = "none" ;
} , 700 ) ;
toggleMenuItems ( 'hide' ) ;
} else {
2024-10-31 01:32:57 +01:00
menu . style . display = "flex" ;
toggleMenuItems ( 'show' ) ;
2023-12-17 16:49:23 +01:00
}
2023-12-14 06:01:09 +01:00
setTimeout ( ( ) => {
2023-12-17 16:49:23 +01:00
menu . classList . toggle ( "active" ) ;
} , 1 ) ;
setTimeout ( ( ) => {
inTransition = false ;
2023-12-14 06:01:09 +01:00
} , 700 ) ;
}
2023-12-17 16:49:23 +01:00
2023-12-06 05:01:23 +01:00
} ) ;
2024-10-31 01:32:57 +01:00
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-17 16:49:23 +01:00
if ( ! isMenuClicked && ! isHamburgerClicked && ! inTransition ) {
inTransition = true ;
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" ;
2023-12-17 16:49:23 +01:00
inTransition = false ;
2023-12-15 20:04:59 +01:00
} , 700 ) ;
2023-12-06 05:01:23 +01:00
}
} ) ;
2023-12-15 20:04:59 +01:00
2024-11-27 19:34:18 +01:00
//
// Programme page text fade in when it enters viewport
//
const url = window . location . pathname ;
if ( url . endsWith ( "le-programme-erable" ) || url . endsWith ( "le-programme-erable/" ) ) {
const textElements = document . querySelectorAll ( '.fullpage_content p, .fullpage_content h3' ) ;
for ( let element of textElements ) element . classList . add ( 'faded' ) ;
const fadeInOnScroll = ( entries , observer ) => {
entries . forEach ( entry => {
if ( entry . isIntersecting ) {
entry . target . classList . add ( 'fade-in' ) ; // Add your fade-in class
observer . unobserve ( entry . target ) ; // Stop observing once it's visible
}
} ) ;
} ;
// Create an Intersection Observer
const observer = new IntersectionObserver ( fadeInOnScroll , {
threshold : 0.1 // Adjust as needed (0.1 means 10% of the element is visible)
} ) ;
// Attach the observer to each element
textElements . forEach ( element => {
observer . observe ( element ) ;
} ) ;
}
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' ) ;
2024-03-29 21:29:59 +01:00
} else if ( document . querySelector ( '.offre-content' ) ) {
2024-04-26 20:08:09 +02:00
fluoButtons = document . querySelectorAll ( '.liens_fixed > div, .file_fixed > div > div' ) ;
2024-11-06 02:46:29 +01:00
} else if ( document . querySelector ( '.projets' ) ) {
2024-11-08 06:12:36 +01:00
fluoButtons = document . querySelectorAll ( '.file_fixed > div > div, .liens > div > div > div' ) ;
2023-12-15 20:04:59 +01:00
} else {
2024-11-06 02:46:29 +01:00
fluoButtons = document . querySelectorAll ( '.liens_fixed > div > div:not(.visually-hidden), .file_fixed > div > div, .liens > div > div' ) ;
2023-12-15 20:04:59 +01:00
}
2024-10-31 01:32:57 +01:00
2024-11-08 06:12:36 +01:00
let footer = document . querySelector ( 'footer' ) ;
2024-11-06 16:59:14 +01:00
2024-11-08 06:12:36 +01:00
function positionFluoLinks ( scrollTop ) {
2023-12-15 20:04:59 +01:00
for ( let i = fluoButtons . length ; i > 0 ; i -- ) {
2024-11-06 16:59:14 +01:00
if ( window . innerWidth > 1080 ) {
2024-11-08 06:12:36 +01:00
const layoutContainerEl = document . querySelector ( '.layout-container' ) ;
let pageScrollableHeight = layoutContainerEl . offsetHeight ;
2024-11-06 16:59:14 +01:00
let prevButtonBottom = fluoButtons [ i ] ? parseInt ( fluoButtons [ i ] . style . bottom ) : 0 ;
let prevButtonHeight = fluoButtons [ i ] ? fluoButtons [ i ] . offsetHeight : 0 ;
fluoButtons [ i - 1 ] . style . position = 'fixed' ;
fluoButtons [ i - 1 ] . style . left = document . querySelector ( '.projets' ) ? '76vw' : '75vw' ;
2024-11-08 06:12:36 +01:00
/ * c o n s o l e . l o g ( `
pageScrollableHeight : $ { pageScrollableHeight } ,
footer . offsetHeight : $ { footer . offsetHeight } ,
window . innerHeight : $ { window . innerHeight } ,
scrollTop : $ { scrollTop }
` ); */
if ( pageScrollableHeight - footer . offsetHeight < window . innerHeight + scrollTop && i === fluoButtons . length ) {
let margin = document . querySelector ( '.projets' ) ? 15 : 30 ;
fluoButtons [ i - 1 ] . style . bottom = ` ${ window . innerHeight - footer . offsetTop + scrollTop + margin } px ` ;
2024-11-06 16:59:14 +01:00
} else {
2024-11-08 06:12:36 +01:00
let margin = document . querySelector ( '.projets' ) ? 0 : 15 ;
fluoButtons [ i - 1 ] . style . bottom = i === fluoButtons . length ? '30px' : ` ${ prevButtonBottom + prevButtonHeight + margin } px ` ;
2024-11-06 16:59:14 +01:00
}
2023-12-15 20:04:59 +01:00
} else {
2024-11-06 16:59:14 +01:00
fluoButtons [ i - 1 ] . style . position = 'relative' ;
fluoButtons [ i - 1 ] . style . left = '0' ;
fluoButtons [ i - 1 ] . style . bottom = '0' ;
2023-12-15 20:04:59 +01:00
}
}
}
if ( document . querySelector ( '.fullpage' ) ) {
2024-01-06 10:00:50 +01:00
let liens = document . querySelectorAll ( '.liens_fixed a, .file_fixed a, .content_partenaires a' ) ;
2024-01-06 09:39:13 +01:00
for ( let lien of liens ) {
lien . setAttribute ( 'target' , '_blank' ) ;
}
2024-11-08 06:12:36 +01:00
2023-12-15 20:04:59 +01:00
positionFluoLinks ( ) ;
2024-11-08 06:12:36 +01:00
document . body . addEventListener ( 'scroll' , ( e ) => {
positionFluoLinks ( e . target . scrollTop ) ;
2023-12-15 20:04:59 +01:00
} ) ;
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-12-20 06:48:35 +01:00
//
2024-01-22 15:25:26 +01:00
// Retirer paragraphes vides fullpage
// et ajouter de la marge pour les images en portrait
2023-12-20 06:48:35 +01:00
//
2023-12-21 12:48:12 +01:00
let currentPage ;
if ( document . querySelector ( '.fullpage:not(.actus)' ) ) currentPage = 'fullpage' ;
else if ( document . querySelector ( '.carousel_container' ) ) currentPage = 'home' ;
2024-01-22 15:25:26 +01:00
if ( currentPage === 'fullpage' ) {
let paragraphs = document . querySelectorAll ( 'p' ) ;
for ( let paragraph of paragraphs ) {
if ( ! /[a-zA-Z]/ . test ( paragraph . innerText ) ) {
paragraph . remove ( ) ;
}
}
let imgs = document . querySelectorAll ( '.fullpage img' ) ;
2024-11-07 04:37:14 +01:00
let isActus = document . querySelector ( '.retour_actus' ) ;
if ( isActus ) {
2024-04-09 10:54:31 +02:00
for ( let img of imgs ) {
if ( img . height > img . width ) {
img . parentElement . style . padding = '0 12vw' ;
}
2024-01-22 15:25:26 +01:00
}
}
}
2024-04-19 15:26:56 +02:00
//
// all meetup card is a link
//
let meetup = document . querySelector ( '.meetup_list' ) ;
if ( meetup ) {
let meetupCards = document . querySelectorAll ( '.meetup_list > .views-row' ) ;
for ( let card of meetupCards ) {
let meetupLink = card . querySelector ( '.offre-title' ) ;
meetupLink = meetupLink . getAttribute ( 'href' ) ;
let ficheLink = document . createElement ( 'a' ) ;
ficheLink . setAttribute ( 'href' , meetupLink ) ;
let cardArticle = card . querySelector ( 'article' ) ;
ficheLink . append ( cardArticle ) ;
card . append ( ficheLink ) ;
}
}
2024-01-22 15:25:26 +01:00
//
2024-10-31 01:32:57 +01:00
// Sous Menu display on hover
2024-01-22 15:25:26 +01:00
//
2024-10-31 01:32:57 +01:00
const programLink = document . querySelector ( "#block-erabletheme-navigationprincipale ul li:first-of-type" ) ;
const programSubmenu = document . querySelector ( "#block-erabletheme-leprogramme" ) ;
let isSubmenuOpen = false ;
2023-12-20 06:48:35 +01:00
2024-10-31 01:32:57 +01:00
function showSubmenu ( ) {
programLink . classList . add ( "submenu-open" ) ;
2024-10-31 20:08:58 +01:00
let rect = programLink . getBoundingClientRect ( ) ;
2024-10-31 01:32:57 +01:00
programSubmenu . style . top = ` ${ rect . bottom } px ` ;
programSubmenu . style . left = ` ${ rect . left } px ` ;
programSubmenu . style . display = "block" ;
2023-12-20 06:48:35 +01:00
2024-10-31 01:32:57 +01:00
programSubmenu . style . display = "block" ;
setTimeout ( ( ) => {
programSubmenu . style . maxHeight = "50vh" ;
} , 10 )
2023-12-20 06:48:35 +01:00
2024-10-31 01:32:57 +01:00
isSubmenuOpen = true ;
2023-12-20 06:48:35 +01:00
}
2024-10-31 01:32:57 +01:00
function hideSubmenu ( ) {
programLink . classList . remove ( "submenu-open" ) ;
programSubmenu . style . maxHeight = "0px" ;
isSubmenuOpen = false ;
setTimeout ( ( ) => {
if ( ! isSubmenuOpen ) {
programSubmenu . style . display = "none" ;
2023-12-20 06:48:35 +01:00
}
2024-10-31 01:32:57 +01:00
} , 600 ) ;
2023-12-20 06:48:35 +01:00
}
2024-10-31 01:32:57 +01:00
programLink . addEventListener ( "mouseenter" , showSubmenu ) ;
programLink . addEventListener ( "mouseleave" , hideSubmenu ) ;
programSubmenu . addEventListener ( "mouseenter" , showSubmenu ) ;
programSubmenu . addEventListener ( "mouseleave" , hideSubmenu ) ;
2023-12-20 06:48:35 +01:00
2024-11-05 01:44:18 +01:00
//
// Aside menu toggle
//
2024-11-06 16:59:14 +01:00
const sideMenuTitle =
document . querySelector ( '#block-erabletheme-leprogramme-2 h2' ) ||
document . querySelector ( '#block-erabletheme-views-block-projets-block-1 h2' ) ;
2024-11-05 01:44:18 +01:00
if ( sideMenuTitle ) {
sideMenuTitle . addEventListener ( 'click' , ( ) => {
2024-11-06 16:59:14 +01:00
const sideMenu = document . querySelector ( '#block-erabletheme-leprogramme-2 > ul' ) ||
document . querySelector ( '#block-erabletheme-views-block-projets-block-1 .projets_list' ) ;
2024-11-05 01:44:18 +01:00
const titleArrow = sideMenuTitle . querySelector ( 'div' ) ;
if ( ! sideMenu . classList . contains ( 'closed' ) ) {
sideMenu . classList . add ( 'closed' ) ;
titleArrow . classList . add ( 'closed' ) ;
} else {
sideMenu . classList . remove ( 'closed' ) ;
titleArrow . classList . remove ( 'closed' ) ;
}
} ) ;
}
2024-11-06 16:59:14 +01:00
//
// set active project in aside project menu
//
const asideProjectMenu = document . querySelector ( '#block-erabletheme-views-block-projets-block-1 .projets_list' ) ;
if ( asideProjectMenu ) {
for ( let item of asideProjectMenu . children ) {
const itemTitle = item . innerText ;
const contentPage = document . querySelector ( '.projet_full' ) ;
const contentPageTitle = contentPage . querySelector ( 'h2' ) . innerText ;
if ( itemTitle . toLowerCase ( ) === contentPageTitle . toLowerCase ( ) ) {
item . querySelector ( 'a' ) . classList . add ( 'is-active' ) ;
}
}
}
2024-11-07 20:34:00 +01:00
//
// set non breaking spaces
//
document . querySelectorAll ( 'p, li, h1, h2, h3, h4, h5, h6' ) . forEach ( ( content ) => {
content . innerHTML = content . innerHTML . replaceAll ( ' ;' , ' ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( ' :' , ' ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( ' ?' , ' ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( ' !' , ' ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( '« ' , '« ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( ' »' , ' »' ) ;
content . innerHTML = content . innerHTML . replaceAll ( '(« ' , '(« ' ) ;
content . innerHTML = content . innerHTML . replaceAll ( ' »)' , ' »)' ) ;
} ) ;
2024-11-05 01:44:18 +01:00
//
// index projets random shape
//
if ( document . querySelector ( '.projets_list' ) ) {
const projets = document . querySelectorAll ( '.projets_list > .views-row' ) ;
2024-11-07 04:37:14 +01:00
const shapesAmount = 6 ;
2024-11-05 01:44:18 +01:00
for ( let i = 0 ; i < projets . length ; i ++ ) {
const randomShape = Math . floor ( Math . random ( ) * shapesAmount ) + 1 ;
2024-11-07 04:37:14 +01:00
if ( projets [ i ] . querySelector ( 'img' ) ) {
const img = projets [ i ] . querySelector ( 'a' ) ;
img . style . maskImage = ` url('/themes/erabletheme/assets/shapes/shape_ ${ randomShape } .svg') ` ;
}
}
}
//
// set bg middle placement
//
2024-11-08 06:12:36 +01:00
let pageHeight = document . querySelector ( '.layout-container' ) . offsetHeight ;
toggleBgMiddle ( pageHeight )
2024-11-07 04:37:14 +01:00
window . addEventListener ( 'resize' , ( ) => {
2024-11-08 06:12:36 +01:00
pageHeight = document . querySelector ( '.layout-container' ) . offsetHeight ;
toggleBgMiddle ( pageHeight ) ;
} )
2024-11-07 23:49:56 +01:00
2024-11-08 06:12:36 +01:00
function toggleBgMiddle ( pageHeight ) {
const bgMiddle = document . querySelector ( '#bg-middle' ) ;
const bgOnze = document . querySelector ( '#bg-11' ) ;
2024-11-07 04:37:14 +01:00
if ( pageHeight < 2000 ) {
bgMiddle . style . display = 'none' ;
2024-11-08 06:12:36 +01:00
bgOnze . style . display = 'none' ;
} else {
bgMiddle . style . display = 'block' ;
bgOnze . style . display = 'block' ;
2024-11-05 01:44:18 +01:00
}
}
2023-11-30 17:33:32 +01:00
}
2024-10-31 01:32:57 +01:00
}
2023-11-30 17:33:32 +01:00
2024-11-06 02:46:29 +01:00
Drupal . behaviors . customLeafletInteraction = {
attach : function ( context , settings ) {
$ ( context ) . on ( 'leafletMapInit' , function ( e , settings , map , mapid , markers ) {
2024-11-07 04:37:14 +01:00
//
// on projects pages, replace leaflet icons with erable leafs
//
const leafletIcons = document . querySelectorAll ( '.leaflet-marker-pane img' ) ;
for ( let icon of leafletIcons ) {
icon . setAttribute ( 'src' , '/themes/erabletheme/assets/leaf.svg' ) ;
}
//
// set hover on leaflet marker and zones
//
const leafletPlaces = document . querySelectorAll ( '.leaflet-marker-pane img, .leaflet-overlay-pane path' ) ;
const libelles = document . querySelectorAll ( '.libelles-carte > div > div > div' ) ;
for ( let i = 0 ; i < leafletPlaces . length ; i ++ ) {
const carte = document . querySelector ( '.carte' ) ;
leafletPlaces [ i ] . addEventListener ( 'mouseenter' , ( ) => {
let div = document . createElement ( 'div' ) ;
div . setAttribute ( 'id' , 'leaflet-popup' ) ;
div . style . zIndex = '100' ;
const x = leafletPlaces [ i ] . getBoundingClientRect ( ) . left + leafletPlaces [ i ] . getBoundingClientRect ( ) . width / 2 ;
const y = leafletPlaces [ i ] . getBoundingClientRect ( ) . top ;
setTimeout ( ( ) => {
div . style . opacity = 1 ;
const divHeight = div . getBoundingClientRect ( ) . height ;
const divWidth = div . getBoundingClientRect ( ) . width ;
setTimeout ( ( ) => {
div . style . left = ` ${ x - divWidth / 2 } px ` ;
div . style . top = ` ${ y - divHeight } px ` ;
} , 10 ) ;
} , 10 ) ;
div . innerText = libelles [ i ] . innerText ;
carte . appendChild ( div ) ;
} ) ;
leafletPlaces [ i ] . addEventListener ( 'mouseleave' , ( ) => {
let divs = document . querySelectorAll ( '#leaflet-popup' ) ;
for ( let div of divs ) {
div . style . opacity = 0 ;
setTimeout ( ( ) => {
div . remove ( ) ;
} , 300 ) ;
}
} ) ;
}
2024-11-06 02:46:29 +01:00
} ) ;
}
}
} ( jQuery , Drupal ) ) ;