123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- $(document).ready( () => {
- lazyLoading()
- displayPictograms()
- getDeviceSize()
- hideMobileNavOnResize()
- hoverDesktopNavItems()
- if (currentPage.text().trim() == 'Accueil') {
- hideFooter()
- toggleIndexContent()
- } else if (currentPage.text().trim() == 'Projets' && $('main').children(":first").attr('id') != 'reader') {
- hideFooter()
- loadProjetIndex()
- } else if ($('main').children(":first").attr('id') == 'reader') {
- hideFooter()
- displayReader()
- }
- initBarba()
- })
- // GLOBAL VARIABLES
- let isMobileNavOpen = false,
- isDesktopDevice = false,
- currentPage,
- filterObj = {
- publiqueCardsDisplayed : true,
- socialeCardsDisplayed : true,
- culturelleCardsDisplayed : true
- },
- projectTitleIsScrolling = false,
- titleScrollTimer
- // MAIN FUNCTIONS
- function initBarba() {
- barba.init({
- prefetchIgnore: true,
- transitions: [{
- name: 'opacity-transition',
- leave(data) {
- return gsap.to(data.current.container, {
- opacity: 0
- })
- },
- enter(data) {
- return gsap.from(data.next.container, {
- opacity: 0
- })
- }
- }]
- })
- barba.hooks.beforeLeave((data) => {
- if (isMobileNavOpen) { toggleMobileNav() }
- if ($(data.current.container).attr('id') == 'projets-index') { resetFilters() }
- if ($(data.current.container).attr('id') == 'text-content' ) { hideFooter() }
- })
- barba.hooks.afterLeave((data) => {
- if ($(data.current.container).attr('id') == 'reader') {
- if ($(data.next.container).attr('id') != 'reader') {
- leaveReader()
- $('#nav-container h1').empty().append(currentPage.text())
- }
- }
- })
- barba.hooks.beforeEnter((data) => {
- lazyLoading()
- displayPictograms()
- $('html, body').scrollTop(0)
- if ($(data.next.container).attr('id') == 'index-content') {
- toggleIndexContent()
- } else if ($(data.next.container).attr('id') == 'projets-index') {
- loadProjetIndex()
- filterWhenEntering()
- } else if ($(data.next.container).attr('id') == 'text-content')
- { if (isDesktopDevice) { displayFooter() } }
- })
- barba.hooks.after((data) => {
- let pageTitleComparator, navIndex
- switch ($('main').children(":first").attr('id')) {
- case 'index-content':
- pageTitleComparator = 'Accueil'
- navIndex = 0
- break
- case 'text-content':
- // dirty hack to get what content it is
- if ($('main').children(":first").children(":first").text().substring(3).replace(/ .*/,'') == "équipe") {
- pageTitleComparator = 'Le collectif'
- navIndex = 1;
- } else {
- pageTitleComparator = 'Logiciels Libres'
- navIndex = 3;
- }
- break
- case 'projets-index':
- case 'reader':
- pageTitleComparator = 'Projets'
- navIndex = 2
- break
- }
- if (pageTitleComparator != currentPage.text().trim()) {
- changeMenuSelected($('header nav ul li').eq(navIndex))
- }
- if ($(data.next.container).attr('id') == 'reader') {
- displayReader()
- }
- })
- }
- function lazyLoading() {
- $('.lazy').Lazy({
- scrollDirection: 'vertical',
- effect: 'fadeIn',
- effectTime: 400,
- threshold: 100,
- afterLoad: function(element) {
- $(element).removeClass('loader')
- if ($(element).parent().is('figure')) {
- $(element).parent().addClass('loaded')
- } else {
- $(element).parentsUntil('figure').parent().addClass('loaded')
- }
- }
- })
- }
- // UI FUNCTIONS
- // general content
- function displayPictograms() {
- // To be able to change the pictograms color through scss variables
- addLinkPictogram()
- $('.picto').each((i, el) => {
- let source = $(el).data('src')
- $(el).css({
- '-webkit-mask': 'url(' + source + ') 0% 0% / contain no-repeat',
- 'mask': 'url(' + source + ') 0% 0% / contain no-repeat',
- })
- })
- }
- function addLinkPictogram() {
- $('main a[target="_blank"]').each( (i, e) => {
- $(e).append('<div class="picto picto-url" data-src="/user/themes/figureslibres-v2/images/pictos/arrow-diagonal.svg" aria-hidden="true"></div>')
- })
- // hardcoded url because cant use twig in js
- }
- function getDeviceSize() {
- function setDeviceSize() {
- if (window.matchMedia('(min-width: 996px)').matches) {
- isDesktopDevice = true
- } else {
- isDesktopDevice = false
- }
- }
- setDeviceSize()
- let timer
- $(window).on('resize', () => {
- clearTimeout(timer)
- timer = setTimeout(setDeviceSize(), 100)
- refreshUiOnResize()
- })
- }
- function refreshUiOnResize() {
- hideFooterOnResize()
- hideMobileNavOnResize()
- checkTitleAutoScroll()
- }
- function triggerLazyLoading() {
- setTimeout(() => {
- $(document).scrollTop($(document).scrollTop() + 1)
- setTimeout(() => {
- $(document).scrollTop($(document).scrollTop() - 1)
- }, 100)
- }, 300)
- }
- function titleScrollTop() {
- if ($('html, body').scrollTop() > 0) {
- $('html, body').animate({scrollTop: 0}, 1200)
- if (currentPage.text().trim() == 'Accueil') {
- toggleIndexContent(true)
- }
- }
- }
- // set navigation
- function toggleMobileNav() {
- if (!isMobileNavOpen) {
- $('nav').addClass('mobile-nav-open')
- $('footer').fadeIn()
- isMobileNavOpen = true
- } else {
- $('nav').removeClass('mobile-nav-open')
- isMobileNavOpen = false
- if (window.matchMedia('(min-width: 576px)').matches && (currentPage.text().trim() == 'Figures Libres' || currentPage.text().trim() == 'Logiciels Libres')) {
- return
- } else {
- $('footer').fadeOut()
- }
- }
- }
- function hideMobileNavOnResize() {
- if (!isDesktopDevice) {
- if (isMobileNavOpen) {
- toggleMobileNav()
- }
- $('nav').css('display', 'none')
- setTimeout( () => {
- $('nav').css('display', 'flex')
- }, 200)
- }
- }
- function hoverDesktopNavItems() {
- currentPage = $('.selected')
- $('nav li').hover(() => {
- if (isDesktopDevice) {
- currentPage.removeClass('selected')
- }
- }, () => {
- if (isDesktopDevice) {
- currentPage.addClass('selected')
- }
- })
- }
- function changeMenuSelected(page) {
- $('.selected').removeClass('selected')
- currentPage = $(page)
- currentPage.addClass('selected')
- changeMobileTitle()
- }
- function changeMobileTitle() {
- $('#nav-container h1').empty().append(currentPage.text())
- }
- // index interaction
- function toggleIndexContent(closeEverything) {
- let isTextOpen = false,
- isCommanditairesOpen = false,
- isExtraitOpen = false,
- quelExtrait
- if (closeEverything) {
- closeEverything()
- }
- $('#second-p-index, #commanditaires-grid, #extrait-publique, #extrait-social, #extrait-culturelle').children().fadeOut()
- $('#arrowIndex').click( () => {
- if (!isTextOpen && !isExtraitOpen) {
- if (isDesktopDevice) {
- displayContent($('#second-p-index'), '70vh')
- } else {
- displayContent($('#second-p-index'), '90vh')
- }
- turnArrow('down')
- isTextOpen = true
- } else {
- if (isExtraitOpen) {
- hideContent($('#extrait-' + quelExtrait))
- $('#' + quelExtrait).css('text-decoration', 'none')
- isExtraitOpen = false
- turnArrow('top')
- }
- if (isTextOpen) {
- hideContent($('#second-p-index'))
- turnArrow('top')
- isTextOpen = false
- }
- if (isCommanditairesOpen) {
- hideContent($('#commanditaires-grid'))
- $('#commanditaires').css('text-decoration', 'none')
- isCommanditairesOpen = false
- }
- }
- })
- $('#index-content .animateText').click( function(event) {
- target = $(event.target).attr('id')
- if (target == 'publique' || target == 'sociale' || target == 'culturelle') {
- toggleExtrait(target)
- return false
- } else if (target == 'commanditaires') {
- toggleCommanditaires()
- return false
- } else {
- switch (target) {
- case 'figureslibres':
- changeMenuSelected($('nav li a[href$=collectif]').parent())
- break
- case 'logicielslibres':
- changeMenuSelected($('nav li a[href$=logiciels-libres]').parent())
- break
- case 'projets':
- changeMenuSelected($('nav li a[href$=projets]').parent())
- break
- }
- }
- })
- $('#extrait-projets .projets-link-filter').click(() => {
- changeMenuSelected($('nav li a[href$=projets]').parent())
- })
- function toggleExtrait(category) {
- if(!isExtraitOpen) {
- if (isTextOpen) {
- hideContent($('#second-p-index'))
- isTextOpen = false
- }
- if (isCommanditairesOpen) {
- hideContent($('#commanditaires-grid'))
- $('#commanditaires').css('text-decoration', 'none')
- isCommanditairesOpen = false
- }
- displayContent($('#extrait-' + category), '80vh')
- turnArrow('down')
- $('#' + category).css({'text-decoration': 'underline', 'text-decoration-thickness': '2px', 'text-underline-offset': '8px'})
- isExtraitOpen = true
- quelExtrait = category
- } else if (isExtraitOpen && quelExtrait != category) {
- hideContent($('#extrait-' + quelExtrait))
- $('#' + category).css({'text-decoration': 'underline', 'text-decoration-thickness': '2px', 'text-underline-offset': '8px'})
- $('#' + quelExtrait).css('text-decoration', 'none')
- setTimeout(() => {
- displayContent($('#extrait-' + category), '80vh')
- quelExtrait = category
- }, 1000)
- } else if (isExtraitOpen && quelExtrait == category) {
- hideContent($('#extrait-' + category))
- turnArrow('top')
- $('#' + category).css('text-decoration', 'none')
- isExtraitOpen = false
- }
- }
- function toggleCommanditaires() {
- if (!isCommanditairesOpen) {
- displayContent($('#commanditaires-grid'), '150vh')
- $('#commanditaires').css({'text-decoration': 'underline', 'text-decoration-thickness': '2px', 'text-underline-offset': '8px'})
- isCommanditairesOpen = true
- } else {
- hideContent($('#commanditaires-grid'))
- $('#commanditaires').css('text-decoration', 'none')
- isCommanditairesOpen = false
- }
- }
- function closeEverything() {
- if (isTextOpen) {
- hideContent($('#second-p-index'))
- isTextOpen = false
- }
- if (isExtraitOpen) {
- hideContent($('#extrait-' + quelExtrait))
- $('#' + quelExtrait).css('text-decoration', 'none')
- isExtraitOpen = false
- }
- if (isCommanditairesOpen) {
- hideContent($('#commanditaires-grid'))
- $('#commanditaires').css('text-decoration', 'none')
- isCommanditairesOpen = false
- }
- turnArrow('top')
- }
- }
- function turnArrow(direction) {
- if (direction == 'down') {
- $('#arrow-container').css({
- 'transform': 'rotate(180deg)',
- 'margin-bottom': '10vh'
- })
- $('#arrow-container .picto').removeAttr('id')
- } else if (direction == 'top') {
- $('#arrow-container').css({
- 'transform': 'rotate(0deg)',
- 'margin-bottom': '0vh'
- })
- $('#arrow-container .picto').attr('id', 'arrowIndex')
- }
- }
- function displayContent(content, maxHeight) {
- content.children().fadeIn()
- setTimeout( () => {
- content.css({
- 'max-height': maxHeight,
- 'opacity': '1'
- })
- if (isDesktopDevice) {
- content.css('margin-top', '3vh')
- }
- }, 200)
- setTimeout( () => {
- $('html, body').animate({
- scrollTop: $(content).position().top
- }, 1200, 'swing')
- }, 400)
- }
- function hideContent(content) {
- content.css({
- 'max-height': '0vh',
- 'opacity': '0',
- 'margin-top': '0vh'
- })
- setTimeout(() => {
- content.children().fadeOut()
- }, 1200)
- }
- // display project grid
- function toggleCategory(category) {
- let chevron = $(category).find('.chevron-category')
- if (chevron.hasClass('close')) {
- $(chevron.removeClass('close'))
- $(category).next().slideToggle('slow')
- $('.card-displayed figure').each(function() {
- if ($(this).css('transform') != 'none') {
- $(this).css('transform', 'none')
- }
- })
- } else {
- $(chevron.addClass('close'))
- $(category).next().slideToggle('slow')
- triggerLazyLoading()
- }
- }
- function filterCards(utilite) {
- let filterIsOn
- function checkFilter() {
- switch (utilite) {
- case 'publique':
- filterIsOn = filterObj.publiqueCardsDisplayed ? true : false
- if (filterObj.publiqueCardsDisplayed) {
- filterObj.publiqueCardsDisplayed = false
- } else {
- filterObj.publiqueCardsDisplayed = true
- }
- break
- case 'sociale':
- filterIsOn = filterObj.socialeCardsDisplayed ? true : false
- if (filterObj.socialeCardsDisplayed) {
- filterObj.socialeCardsDisplayed = false
- } else {
- filterObj.socialeCardsDisplayed = true
- }
- break
- case 'culturelle':
- filterIsOn = filterObj.culturelleCardsDisplayed ? true : false
- if (filterObj.culturelleCardsDisplayed) {
- filterObj.culturelleCardsDisplayed = false
- } else {
- filterObj.culturelleCardsDisplayed = true
- }
- break
- }
- }
- if (Object.values(filterObj).every(Boolean) || Object.values(filterObj).every(e => e == false)) { // si tous les filtres sont actifs (état de base)
- $('.projets-grid div').each(function () { // hide all cards
- if($(this).hasClass(utilite + '-card')) { // except those from the filtered category
- $(this).removeClass('card-hidden').addClass('card-displayed')
- }
- else {
- $(this).removeClass('card-displayed').addClass('card-hidden')
- }
- })
- $('#' + utilite + '-filter').css('opacity', 1)
- Object.keys(filterObj).forEach(v => filterObj[v] = false)
- checkFilter()
- }
- else if (Object.values(filterObj).filter(Boolean).length == 1) {
- // check if the filter is on or off
- checkFilter()
- if (filterIsOn) {
- $('#' + utilite + '-filter').css('opacity', 0.4)
- $('.projets-grid div').each(function () { // display all cards
- $(this).removeClass('card-hidden').addClass('card-displayed')
- })
- } else {
- $('#' + utilite + '-filter').css('opacity', 1)
- $('.' + utilite + '-card').each(function () { // only display cards from selected category
- $(this).removeClass('card-hidden').addClass('card-displayed')
- })
- }
- }
- else if (Object.values(filterObj).filter(Boolean).length == 2) {
- checkFilter()
- if (filterIsOn) {
- $('#' + utilite + '-filter').css('opacity', 0.4)
- $('.' + utilite + '-card').each(function () { // only display cards from selected category
- $(this).removeClass('card-displayed').addClass('card-hidden')
- })
- } else {
- $('.filter-button').each(function() {
- $(this).css('opacity', 0.4)
- })
- $('.projets-grid div').each(function () { // hide all cards
- $(this).removeClass('card-hidden').addClass('card-displayed')
- })
- }
- }
- triggerLazyLoading()
- checkIfCategoryEmpty() // to hide empty category
- function checkIfCategoryEmpty() {
- $('.projets-grid').each(function() {
- let hiddenCount = 0
- $(this).children().each(function() {
- if ($(this).hasClass('card-hidden')) { hiddenCount++ }
- })
- if (hiddenCount == $(this).children().length) { $(this).prev().fadeOut() }
- else { $(this).prev().fadeIn() }
- })
- }
- }
- function loadProjetIndex() {
- animateProjectGrid()
- isProjetsIndexLoaded = true
- }
- function animateProjectGrid() {
- const grid = document.querySelector(".projets-grid")
- animateCSSGrid.wrapGrid(grid, {duration : 600})
- }
- function resetFilters() {
- Object.keys(filterObj).forEach(v => filterObj[v] = false)
- }
- function filterWhenEntering() {
- let searchParam = new URLSearchParams(window.location.search)
- if (searchParam.has('filter')) {
- switch (searchParam.get('filter')) {
- case 'publique':
- filterCards('publique')
- break
- case 'sociale':
- filterCards('sociale')
- break
- case 'culturelle':
- filterCards('culturelle')
- break
- }
- }
- }
- // display reader
- function displayReader() {
- const swiper = new Swiper('.swiper', {
- // Optional parameters
- loop: true,
- // Navigation arrows
- navigation: {
- nextEl: '.swiper-button-next',
- prevEl: '.swiper-button-prev',
- },
-
- });
- $('#cover-image img, .project-image').click( function(event) {
- const totalImg = $('img')
- let indexImg = 0
- for (let img of totalImg) {
- if (event.target === img) { break }
- indexImg++
- }
- swiper.slideToLoop(indexImg - 1)
- $('body').css('overflow-y', 'hidden');
- swiper.el.style.display = "block";
- setTimeout(() => {
- swiper.el.style.opacity = "1";
- }, 10);
- })
- $('#close-carousel').click( () => {
- $('body').css('overflow-y', 'auto');
- swiper.el.style.opacity = "0";
- setTimeout(() => {
- swiper.el.style.display = "none";
- }, 300);
- })
- $('header').fadeOut()
- projectTitleIsScrolling = false
- checkTitleAutoScroll()
- let isProjectHeaderDisplayed = false
- $(window).scroll( () => {
- if ($(window).scrollTop() > $('#main-project-title').offset().top && !isProjectHeaderDisplayed) {
- $('#header-project').css('top', '0vh')
- if(isDesktopDevice) {
- $('#close-project').addClass('scrolled-cross')
- }
- isProjectHeaderDisplayed = true
- } else if ($(window).scrollTop() < $('#main-project-title').offset().top && isProjectHeaderDisplayed) {
- $('#header-project').css('top', '-9vh')
- if (isDesktopDevice) {
- $('#close-project').removeClass('scrolled-cross')
- }
- isProjectHeaderDisplayed = false
- }
- })
- }
- function leaveReader() {
- $(window).off('scroll')
- $('header').fadeIn()
- if (!$('nav li a[href$=projets]').parent().hasClass('selected')) {
- changeNavSelected('projets')
- }
- disableTitleAutoScroll()
- }
- function titleAutoScroll() {
- if (!projectTitleIsScrolling) {
- $('#header-project').append('<div id="gradient-long-title"></div>')
- projectTitleIsScrolling = true
- }
- $('#header-project h2 span').addClass('scrollText')
- $('#header-project h2 span').css({
- 'transition': 'transform 7s linear',
- 'transform': 'translate(-' + parseInt($('#header-project h2 span').width() / 2 + 8) + 'px, 0)'
- })
- titleScrollTimer = setTimeout( () => {
- $('#header-project h2 span').css({'transition': 'none', 'transform': 'translate(0, 0)'})
- titleAutoScroll()
- }, 7000)
- }
- function disableTitleAutoScroll() {
- $('#gradient-long-title').remove()
- $('#header-project h2 span').removeClass('scrollText').css({'transition': 'none', 'transform': 'translate(0, 0)'})
- projectTitleIsScrolling = false
- }
- function checkTitleAutoScroll() {
- if (titleScrollTimer != null) { clearTimeout(titleScrollTimer) }
- if ($('#header-project h2 span').width() > $('#header-project h2').width() && !projectTitleIsScrolling) {
- titleAutoScroll()
- } else if ($('#header-project h2 span').width() / 2 < $('#header-project h2').width() && projectTitleIsScrolling) {
- $('#header-project h2 span').removeClass('scrollText')
- disableTitleAutoScroll()
- }
- }
- // show and hide footer
- function displayFooter() {
- $('footer').fadeIn()
- }
- function hideFooter() {
- $('footer').fadeOut()
- }
- function hideFooterOnResize() {
- if ($('footer').css('display', 'flex') &&
- (window.matchMedia('(max-width: 576px)').matches ||
- $('.selected').text().trim() == 'Accueil' ||
- $('.selected').text().trim() == 'Projets')) {
- $('footer').css('display', 'none')
- }
- }
|