script.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. $(document).ready( () => {
  2. lazyLoading()
  3. displayPictograms()
  4. getDeviceSize()
  5. hideMobileNavOnResize()
  6. hoverDesktopNavItems()
  7. if (currentPage.text().trim() == 'Accueil') {
  8. hideFooter()
  9. toggleIndexContent()
  10. } else if (currentPage.text().trim() == 'Projets' && $('main').children(":first").attr('id') != 'reader') {
  11. hideFooter()
  12. loadProjetIndex()
  13. } else if ($('main').children(":first").attr('id') == 'reader') {
  14. hideFooter()
  15. displayReader()
  16. } else if ($('main').children(":first").attr('id') == 'text-content') {
  17. addToggleBiography()
  18. }
  19. initBarba()
  20. })
  21. // GLOBAL VARIABLES
  22. let isMobileNavOpen = false,
  23. isDesktopDevice = false,
  24. currentPage,
  25. filterObj = {
  26. publiqueCardsDisplayed : true,
  27. socialeCardsDisplayed : true,
  28. culturelleCardsDisplayed : true
  29. },
  30. projectTitleIsScrolling = false,
  31. titleScrollTimer
  32. // MAIN FUNCTIONS
  33. function initBarba() {
  34. barba.init({
  35. //prefetchIgnore: true,
  36. transitions: [{
  37. name: 'opacity-transition',
  38. leave(data) {
  39. return gsap.to(data.current.container, {
  40. opacity: 0
  41. })
  42. },
  43. enter(data) {
  44. return gsap.from(data.next.container, {
  45. opacity: 0
  46. })
  47. }
  48. }]
  49. })
  50. barba.hooks.beforeLeave((data) => {
  51. if (isMobileNavOpen) { toggleMobileNav() }
  52. if ($(data.current.container).attr('id') == 'projets-index') { resetFilters() }
  53. if ($(data.current.container).attr('id') == 'text-content' ) { hideFooter() }
  54. setBgColor(color_bg)
  55. })
  56. barba.hooks.afterLeave((data) => {
  57. if ($(data.current.container).attr('id') == 'reader' && $(data.next.container).attr('id') != 'reader') {
  58. leaveReader()
  59. $('#nav-container h1').empty().append(currentPage.text())
  60. }
  61. })
  62. barba.hooks.beforeEnter((data) => {
  63. lazyLoading()
  64. displayPictograms()
  65. $('html, body').scrollTop(0)
  66. if ($(data.next.container).attr('id') == 'index-content') {
  67. toggleIndexContent()
  68. } else if ($(data.next.container).attr('id') == 'projets-index') {
  69. loadProjetIndex()
  70. filterWhenEntering()
  71. } else if ($(data.next.container).attr('id') == 'text-content')
  72. {
  73. if (isDesktopDevice) displayFooter()
  74. addToggleBiography()
  75. }
  76. })
  77. barba.hooks.after((data) => {
  78. refreshUiOnResize()
  79. let pageTitleComparator, navIndex
  80. switch ($('main').children(":first").attr('id')) {
  81. case 'index-content':
  82. pageTitleComparator = 'Accueil'
  83. navIndex = 0
  84. break
  85. case 'text-content':
  86. // dirty hack to get what content it is
  87. if ($('main').children(":first").children(":first").text().substring(3).replace(/ .*/,'') == "équipe") {
  88. pageTitleComparator = 'Le collectif'
  89. navIndex = 1;
  90. } else {
  91. pageTitleComparator = 'Logiciels Libres'
  92. navIndex = 3;
  93. }
  94. break
  95. case 'projets-index':
  96. case 'reader':
  97. pageTitleComparator = 'Projets'
  98. navIndex = 2
  99. break
  100. }
  101. if (pageTitleComparator != currentPage.text().trim()) {
  102. changeMenuSelected($('header nav ul li').eq(navIndex))
  103. }
  104. if ($(data.next.container).attr('id') == 'reader') {
  105. displayReader()
  106. }
  107. })
  108. }
  109. function lazyLoading() {
  110. $('.lazy').Lazy({
  111. scrollDirection: 'vertical',
  112. effect: 'fadeIn',
  113. effectTime: 400,
  114. threshold: 100,
  115. afterLoad: function(element) {
  116. $(element).removeClass('loader')
  117. if ($(element).parent().is('figure')) {
  118. $(element).parent().addClass('loaded')
  119. } else {
  120. $(element).parentsUntil('figure').parent().addClass('loaded')
  121. }
  122. }
  123. })
  124. }
  125. // UI FUNCTIONS
  126. // general content
  127. function displayPictograms() {
  128. // To be able to change the pictograms color through scss variables
  129. addLinkPictogram()
  130. $('.picto').each((i, el) => {
  131. let source = $(el).data('src')
  132. $(el).css({
  133. '-webkit-mask': 'url(' + source + ') 0% 0% / contain no-repeat',
  134. 'mask': 'url(' + source + ') 0% 0% / contain no-repeat',
  135. })
  136. })
  137. }
  138. function addLinkPictogram() {
  139. $('main a[target="_blank"]').each( (i, e) => {
  140. $(e).append('<div class="picto picto-url" data-src="/user/themes/figureslibres-v2/images/pictos/arrow-diagonal.svg" aria-hidden="true"></div>')
  141. })
  142. // hardcoded url because cant use twig in js
  143. }
  144. function getDeviceSize() {
  145. function setDeviceSize() {
  146. if (window.matchMedia('(min-width: 996px)').matches) {
  147. isDesktopDevice = true
  148. } else {
  149. isDesktopDevice = false
  150. }
  151. }
  152. setDeviceSize()
  153. let timer
  154. $(window).on('resize', () => {
  155. clearTimeout(timer)
  156. timer = setTimeout(setDeviceSize(), 100)
  157. refreshUiOnResize()
  158. })
  159. }
  160. function refreshUiOnResize() {
  161. hideFooterOnResize()
  162. hideMobileNavOnResize()
  163. checkTitleAutoScroll()
  164. function menuViewJustChanged(callback) {
  165. let prevDeviceIsDesktop = isDesktopDevice;
  166. setTimeout(() => callback(!(isDesktopDevice === prevDeviceIsDesktop)), 50);
  167. }
  168. menuViewJustChanged(result => {
  169. if (result) {
  170. currentColor = $('body').css('background-color')
  171. if (isDesktopDevice) {
  172. console.log("is desktop");
  173. $('nav').css('background-color', currentColor)
  174. $('#nav-container').css('background-color', color_bg)
  175. } else {
  176. console.log("is NOT desktop");
  177. $('nav').css('background-color', color_main)
  178. $('#nav-container').css('background-color', currentColor)
  179. }
  180. }
  181. })
  182. }
  183. function triggerLazyLoading() {
  184. setTimeout(() => {
  185. $(document).scrollTop($(document).scrollTop() + 1)
  186. setTimeout(() => {
  187. $(document).scrollTop($(document).scrollTop() - 1)
  188. }, 100)
  189. }, 300)
  190. }
  191. function titleScrollTop() {
  192. if ($('html, body').scrollTop() > 0) {
  193. $('html, body').animate({scrollTop: 0}, 1200)
  194. if (currentPage.text().trim() == 'Accueil') {
  195. toggleIndexContent(true)
  196. }
  197. }
  198. }
  199. // set navigation
  200. function toggleMobileNav() {
  201. if (!isMobileNavOpen) {
  202. $('nav').addClass('mobile-nav-open')
  203. $('footer').fadeIn()
  204. isMobileNavOpen = true
  205. } else {
  206. $('nav').removeClass('mobile-nav-open')
  207. isMobileNavOpen = false
  208. if (window.matchMedia('(min-width: 576px)').matches && (currentPage.text().trim() == 'Figures Libres' || currentPage.text().trim() == 'Logiciels Libres')) {
  209. return
  210. } else {
  211. $('footer').fadeOut()
  212. }
  213. }
  214. }
  215. function hideMobileNavOnResize() {
  216. if (!isDesktopDevice) {
  217. if (isMobileNavOpen) {
  218. toggleMobileNav()
  219. }
  220. $('nav').css('display', 'none')
  221. setTimeout( () => {
  222. $('nav').css('display', 'flex')
  223. }, 200)
  224. }
  225. }
  226. function hoverDesktopNavItems() {
  227. currentPage = $('.selected')
  228. $('nav li').hover(() => {
  229. if (isDesktopDevice) {
  230. currentPage.removeClass('selected')
  231. }
  232. }, () => {
  233. if (isDesktopDevice) {
  234. currentPage.addClass('selected')
  235. }
  236. })
  237. }
  238. function changeMenuSelected(page) {
  239. $('.selected').removeClass('selected')
  240. currentPage = $(page)
  241. currentPage.addClass('selected')
  242. changeMobileTitle()
  243. }
  244. function changeMobileTitle() {
  245. $('#nav-container h1').empty().append(currentPage.text())
  246. }
  247. const color_publique = "#ffaeab";
  248. const color_sociale = "#71ff94";
  249. const color_culturelle = "#feff74";
  250. const color_commanditaire = "#fabbde";
  251. const color_figureslibres = "#82f8ee";
  252. const color_projets = "#4bffc9";
  253. const color_bg = "#f5f5f5";
  254. const color_main = "#0e1229";
  255. let isExtraitOpen = false,
  256. isCommanditairesOpen = false,
  257. quelExtrait
  258. function setBgColor(color) {
  259. $('body').css('background-color', color);
  260. if (isDesktopDevice) {
  261. $('nav').css('background-color', color)
  262. } else {
  263. $('#nav-container').css('background-color', color)
  264. }
  265. if (color === color_bg) {
  266. $('header').removeClass('plain_bg');
  267. } else {
  268. $('header').addClass('plain_bg');
  269. }
  270. }
  271. // index interaction
  272. function toggleIndexContent(closeEverything) {
  273. let isTextOpen = false
  274. if (closeEverything) {
  275. closeEverything()
  276. }
  277. $('#figureslibres, #publique, #sociale, #culturelle, #commanditaires, #projets')
  278. .on('mouseleave', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_bg) : null)
  279. $('#figureslibres')
  280. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_figureslibres) : null)
  281. $('#publique')
  282. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_publique) : null)
  283. $('#sociale')
  284. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_sociale) : null)
  285. $('#culturelle')
  286. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_culturelle) : null)
  287. $('#commanditaires')
  288. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_commanditaire) : null)
  289. $('#projets')
  290. .on('mouseenter', () => !isExtraitOpen && !isCommanditairesOpen ? setBgColor(color_projets) : null)
  291. $('#second-p-index, #commanditaires-grid, #extrait-publique, #extrait-social, #extrait-culturelle')
  292. .children().fadeOut()
  293. $('#arrowIndex').click( () => {
  294. if (!isTextOpen && !isExtraitOpen) {
  295. displayContent($('#second-p-index'), isDesktopDevice ? '70vh' : '90vh')
  296. turnArrow('down')
  297. isTextOpen = true
  298. } else {
  299. if (isExtraitOpen) {
  300. hideContent($('#extrait-' + quelExtrait))
  301. $('#' + quelExtrait).css({
  302. 'text-underline-offset': '0.1em',
  303. 'text-decoration-thickness': '1px',
  304. })
  305. isExtraitOpen = false
  306. turnArrow('top')
  307. }
  308. if (isTextOpen) {
  309. hideContent($('#second-p-index'))
  310. turnArrow('top')
  311. isTextOpen = false
  312. }
  313. if (isCommanditairesOpen) {
  314. hideContent($('#commanditaires-grid'))
  315. $('#commanditaires').css({
  316. 'text-underline-offset': '0.1em',
  317. 'text-decoration-thickness': '1px',})
  318. isCommanditairesOpen = false
  319. }
  320. }
  321. })
  322. $('#index-content .animateText').click( function(event) {
  323. target = $(event.target).attr('id')
  324. if (target == 'publique' || target == 'sociale' || target == 'culturelle') {
  325. toggleExtrait(target)
  326. return false
  327. } else if (target == 'commanditaires') {
  328. toggleCommanditaires()
  329. return false
  330. } else {
  331. switch (target) {
  332. case 'figureslibres':
  333. changeMenuSelected($('nav li a[href$=collectif]').parent())
  334. break
  335. /* case 'logicielslibres':
  336. changeMenuSelected($('nav li a[href$=logiciels-libres]').parent())
  337. break
  338. */ case 'projets':
  339. changeMenuSelected($('nav li a[href$=projets]').parent())
  340. break
  341. }
  342. setBgColor(color_bg)
  343. }
  344. })
  345. $('#extrait-projets .projets-link-filter').click(() => {
  346. changeMenuSelected($('nav li a[href$=projets]').parent())
  347. setBgColor(color_bg)
  348. })
  349. function toggleExtrait(category) {
  350. if(!isExtraitOpen) {
  351. if (isTextOpen) {
  352. hideContent($('#second-p-index'))
  353. isTextOpen = false
  354. }
  355. if (isCommanditairesOpen) {
  356. hideContent($('#commanditaires-grid'))
  357. $('#commanditaires').css({
  358. 'text-underline-offset': '0.1em',
  359. 'text-decoration-thickness': '1px',
  360. })
  361. isCommanditairesOpen = false
  362. }
  363. displayContent($('#extrait-' + category), '100vh')
  364. turnArrow('down')
  365. $('#' + category).css({
  366. 'text-underline-offset': '0.3em',
  367. 'text-decoration-thickness': '2px',
  368. })
  369. isExtraitOpen = true
  370. quelExtrait = category
  371. } else {
  372. if (quelExtrait != category) {
  373. hideContent($('#extrait-' + quelExtrait))
  374. $('#' + category).css({
  375. 'text-underline-offset': '0.3em',
  376. 'text-decoration-thickness': '2px',
  377. })
  378. $('#' + quelExtrait).css({
  379. 'text-underline-offset': '0.1em',
  380. 'text-decoration-thickness': '1px',
  381. })
  382. setTimeout(() => {
  383. displayContent($('#extrait-' + category), '80vh')
  384. quelExtrait = category
  385. }, 1000)
  386. } else {
  387. hideContent($('#extrait-' + category))
  388. turnArrow('top')
  389. $('#' + category).css({
  390. 'text-underline-offset': '0.1em',
  391. 'text-decoration-thickness': '1px',
  392. })
  393. setBgColor(color_bg)
  394. isExtraitOpen = false
  395. }
  396. }
  397. }
  398. function toggleCommanditaires() {
  399. if (!isCommanditairesOpen) {
  400. displayContent($('#commanditaires-grid'), '150vh')
  401. $('#commanditaires').css({
  402. 'text-underline-offset': '0.3em',
  403. 'text-decoration-thickness': '2px',
  404. })
  405. setBgColor(color_commanditaire)
  406. isCommanditairesOpen = true
  407. } else {
  408. hideContent($('#commanditaires-grid'))
  409. $('#commanditaires').css({
  410. 'text-underline-offset': '0.1em',
  411. 'text-decoration-thickness': '1px',
  412. })
  413. setBgColor(color_bg)
  414. isCommanditairesOpen = false
  415. }
  416. }
  417. function closeEverything() {
  418. if (isTextOpen) {
  419. hideContent($('#second-p-index'))
  420. isTextOpen = false
  421. }
  422. if (isExtraitOpen) {
  423. hideContent($('#extrait-' + quelExtrait))
  424. $('#' + quelExtrait).css({
  425. 'text-underline-offset': '0.1em',
  426. 'text-decoration-thickness': '1px',
  427. })
  428. isExtraitOpen = false
  429. }
  430. if (isCommanditairesOpen) {
  431. hideContent($('#commanditaires-grid'))
  432. $('#commanditaires').css({
  433. 'text-underline-offset': '0.1em',
  434. 'text-decoration-thickness': '1px',
  435. })
  436. isCommanditairesOpen = false
  437. }
  438. turnArrow('top')
  439. setBgColor(color_bg);
  440. }
  441. }
  442. function turnArrow(direction) {
  443. if (direction == 'down') {
  444. $('#arrow-container').css({
  445. 'transform': 'rotate(180deg)',
  446. 'margin-bottom': '10vh'
  447. })
  448. $('#arrow-container .picto').removeAttr('id')
  449. } else if (direction == 'top') {
  450. $('#arrow-container').css({
  451. 'transform': 'rotate(0deg)',
  452. 'margin-bottom': '0vh'
  453. })
  454. $('#arrow-container .picto').attr('id', 'arrowIndex')
  455. setBgColor(color_bg);
  456. }
  457. }
  458. function displayContent(content, maxHeight) {
  459. switch (content[0].id) {
  460. case 'extrait-publique':
  461. setBgColor(color_publique)
  462. break
  463. case 'extrait-sociale':
  464. setBgColor(color_sociale)
  465. break
  466. case 'extrait-culturelle':
  467. setBgColor(color_culturelle)
  468. break
  469. default:
  470. break
  471. }
  472. content.children().fadeIn()
  473. setTimeout( () => {
  474. content.css({
  475. 'max-height': maxHeight,
  476. 'opacity': '1'
  477. })
  478. if (isDesktopDevice) {
  479. content.css('margin-top', '3vh')
  480. }
  481. }, 200)
  482. setTimeout( () => {
  483. $('html, body').animate({
  484. scrollTop: $(content).position().top
  485. }, 1200, 'swing')
  486. }, 400)
  487. }
  488. function hideContent(content) {
  489. content.css({
  490. 'max-height': '0vh',
  491. 'opacity': '0',
  492. 'margin-top': '0vh'
  493. })
  494. setTimeout(() => {
  495. content.children().fadeOut()
  496. }, 1200)
  497. }
  498. // display project grid
  499. function toggleCategory(category) {
  500. let chevron = $(category).find('.chevron-category')
  501. if (chevron.hasClass('close')) {
  502. $(chevron.removeClass('close'))
  503. $(category).next().slideToggle('slow')
  504. $('.card-displayed figure').each(function() {
  505. if ($(this).css('transform') != 'none') {
  506. $(this).css('transform', 'none')
  507. }
  508. })
  509. } else {
  510. $(chevron.addClass('close'))
  511. $(category).next().slideToggle('slow')
  512. triggerLazyLoading()
  513. }
  514. }
  515. function filterCards(utilite) {
  516. let filterIsOn
  517. function checkFilter() {
  518. switch (utilite) {
  519. case 'publique':
  520. filterIsOn = filterObj.publiqueCardsDisplayed ? true : false
  521. if (filterObj.publiqueCardsDisplayed) {
  522. filterObj.publiqueCardsDisplayed = false
  523. } else {
  524. filterObj.publiqueCardsDisplayed = true
  525. }
  526. break
  527. case 'sociale':
  528. filterIsOn = filterObj.socialeCardsDisplayed ? true : false
  529. if (filterObj.socialeCardsDisplayed) {
  530. filterObj.socialeCardsDisplayed = false
  531. } else {
  532. filterObj.socialeCardsDisplayed = true
  533. }
  534. break
  535. case 'culturelle':
  536. filterIsOn = filterObj.culturelleCardsDisplayed ? true : false
  537. if (filterObj.culturelleCardsDisplayed) {
  538. filterObj.culturelleCardsDisplayed = false
  539. } else {
  540. filterObj.culturelleCardsDisplayed = true
  541. }
  542. break
  543. }
  544. }
  545. if (Object.values(filterObj).every(Boolean) || Object.values(filterObj).every(e => e == false)) { // si tous les filtres sont actifs (état de base)
  546. $('.projets-grid div').each(function () { // hide all cards
  547. if($(this).hasClass(utilite + '-card')) { // except those from the filtered category
  548. $(this).removeClass('card-hidden').addClass('card-displayed')
  549. }
  550. else {
  551. $(this).removeClass('card-displayed').addClass('card-hidden')
  552. }
  553. })
  554. $('#' + utilite + '-filter').css({
  555. 'opacity': 1,
  556. 'filter': 'grayscale(0)'
  557. })
  558. Object.keys(filterObj).forEach(v => filterObj[v] = false)
  559. checkFilter()
  560. }
  561. else if (Object.values(filterObj).filter(Boolean).length == 1) {
  562. // check if the filter is on or off
  563. checkFilter()
  564. if (filterIsOn) {
  565. $('#' + utilite + '-filter').css({
  566. 'opacity': 0.4,
  567. 'filter': 'grayscale(1)'
  568. })
  569. $('.projets-grid div').each(function () { // display all cards
  570. $(this).removeClass('card-hidden').addClass('card-displayed')
  571. })
  572. } else {
  573. $('#' + utilite + '-filter').css({
  574. 'opacity': 1,
  575. 'filter': 'grayscale(0)'
  576. })
  577. $('.' + utilite + '-card').each(function () { // only display cards from selected category
  578. $(this).removeClass('card-hidden').addClass('card-displayed')
  579. })
  580. }
  581. }
  582. else if (Object.values(filterObj).filter(Boolean).length == 2) {
  583. checkFilter()
  584. if (filterIsOn) {
  585. $('#' + utilite + '-filter').css({
  586. 'opacity': 0.4,
  587. 'filter': 'grayscale(1)'
  588. })
  589. $('.' + utilite + '-card').each(function () { // only display cards from selected category
  590. $(this).removeClass('card-displayed').addClass('card-hidden')
  591. })
  592. } else {
  593. $('.filter-button').each(function() {
  594. $(this).css({
  595. 'opacity': 0.4,
  596. 'filter': 'grayscale(1)'
  597. })
  598. })
  599. $('.projets-grid div').each(function () { // hide all cards
  600. $(this).removeClass('card-hidden').addClass('card-displayed')
  601. })
  602. }
  603. }
  604. triggerLazyLoading()
  605. checkIfCategoryEmpty() // to hide empty category
  606. function checkIfCategoryEmpty() {
  607. $('.projets-grid').each(function() {
  608. let hiddenCount = 0
  609. $(this).children().each(function() {
  610. if ($(this).hasClass('card-hidden')) { hiddenCount++ }
  611. })
  612. if (hiddenCount == $(this).children().length) { $(this).prev().fadeOut() }
  613. else { $(this).prev().fadeIn() }
  614. })
  615. }
  616. }
  617. function loadProjetIndex() {
  618. animateProjectGrid()
  619. isProjetsIndexLoaded = true
  620. }
  621. function animateProjectGrid() {
  622. const grid = document.querySelector(".projets-grid")
  623. animateCSSGrid.wrapGrid(grid, {duration : 600})
  624. }
  625. function resetFilters() {
  626. Object.keys(filterObj).forEach(v => filterObj[v] = false)
  627. }
  628. function filterWhenEntering() {
  629. let searchParam = new URLSearchParams(window.location.search)
  630. if (searchParam.has('filter')) {
  631. switch (searchParam.get('filter')) {
  632. case 'publique':
  633. filterCards('publique')
  634. break
  635. case 'sociale':
  636. filterCards('sociale')
  637. break
  638. case 'culturelle':
  639. filterCards('culturelle')
  640. break
  641. }
  642. }
  643. }
  644. // display reader
  645. function displayReader() {
  646. $('header').fadeOut()
  647. projectTitleIsScrolling = false
  648. checkTitleAutoScroll()
  649. const swiper = new Swiper('.swiper', {
  650. // Optional parameters
  651. loop: true,
  652. // Navigation arrows
  653. navigation: {
  654. nextEl: '.swiper-button-next',
  655. prevEl: '.swiper-button-prev',
  656. },
  657. });
  658. $('#cover-image img, .project-image').click( function(event) {
  659. const totalImg = $('img')
  660. let indexImg = 0
  661. for (let img of totalImg) {
  662. if (event.target === img) { break }
  663. indexImg++
  664. }
  665. swiper.slideToLoop(indexImg - 1)
  666. $('body').css('overflow-y', 'hidden');
  667. swiper.el.style.display = "block";
  668. setTimeout(() => {
  669. swiper.el.style.opacity = "1";
  670. }, 10);
  671. })
  672. $('#close-carousel').click( () => {
  673. $('body').css('overflow-y', 'auto');
  674. swiper.el.style.opacity = "0";
  675. setTimeout(() => {
  676. swiper.el.style.display = "none";
  677. }, 300);
  678. })
  679. let isProjectHeaderDisplayed = false
  680. $(window).scroll( () => {
  681. if ($(window).scrollTop() > $('#main-project-title').offset().top && !isProjectHeaderDisplayed) {
  682. $('#header-project').css('top', '0vh')
  683. if(isDesktopDevice) {
  684. $('#close-project').addClass('scrolled-cross')
  685. }
  686. isProjectHeaderDisplayed = true
  687. } else if ($(window).scrollTop() < $('#main-project-title').offset().top && isProjectHeaderDisplayed) {
  688. $('#header-project').css('top', '-4vh')
  689. if (isDesktopDevice) {
  690. $('#close-project').removeClass('scrolled-cross')
  691. }
  692. isProjectHeaderDisplayed = false
  693. }
  694. })
  695. }
  696. function leaveReader() {
  697. $(window).off('scroll')
  698. $('header').fadeIn()
  699. if (!$('nav li a[href$=projets]').parent().hasClass('selected')) {
  700. changeNavSelected('projets')
  701. }
  702. disableTitleAutoScroll()
  703. }
  704. function titleAutoScroll() {
  705. if (!projectTitleIsScrolling) {
  706. $('#header-project').append('<div id="gradient-long-title"></div>')
  707. projectTitleIsScrolling = true
  708. }
  709. $('#header-project h2 span').addClass('scrollText')
  710. $('#header-project h2 span').css({
  711. 'transition': 'transform 7s linear',
  712. 'transform': 'translate(-' + parseInt($('#header-project h2 span').width() / 2 + 8) + 'px, 0)'
  713. })
  714. titleScrollTimer = setTimeout( () => {
  715. $('#header-project h2 span').css({'transition': 'none', 'transform': 'translate(0, 0)'})
  716. titleAutoScroll()
  717. }, 7000)
  718. }
  719. function disableTitleAutoScroll() {
  720. $('#gradient-long-title').remove()
  721. $('#header-project h2 span').removeClass('scrollText').css({'transition': 'none', 'transform': 'translate(0, 0)'})
  722. projectTitleIsScrolling = false
  723. }
  724. function checkTitleAutoScroll() {
  725. if (titleScrollTimer != null) { clearTimeout(titleScrollTimer) }
  726. if ($('#header-project h2 span').width() > $('#header-project h2').width() && !projectTitleIsScrolling) {
  727. titleAutoScroll()
  728. } else if ($('#header-project h2 span').width() / 2 < $('#header-project h2').width() && projectTitleIsScrolling) {
  729. $('#header-project h2 span').removeClass('scrollText')
  730. disableTitleAutoScroll()
  731. }
  732. }
  733. // show and hide footer
  734. function displayFooter() {
  735. $('footer').fadeIn()
  736. }
  737. function hideFooter() {
  738. $('footer').fadeOut()
  739. }
  740. function hideFooterOnResize() {
  741. if ($('footer').css('display', 'flex') &&
  742. (window.matchMedia('(max-width: 576px)').matches ||
  743. $('.selected').text().trim() == 'Accueil' ||
  744. $('.selected').text().trim() == 'Projets')) {
  745. $('footer').css('display', 'none')
  746. }
  747. }
  748. // dropdown collectif
  749. function addToggleBiography() {
  750. $('h4 + p > em, h4').on('click', toggleBiographie);
  751. $('h4 + p > em').append('<img src="/user/themes/figureslibres-v2/images/pictos/chevron-down.svg" aria-hidden="true">');
  752. }
  753. function toggleBiographie(el) {
  754. let targetContent;
  755. let targetArrow;
  756. if (el.target.tagName === "H4") {
  757. targetContent = el.target.nextElementSibling.nextElementSibling;
  758. targetArrow = el.target.nextElementSibling.firstElementChild.firstElementChild;
  759. } else {
  760. targetContent = el.target.firstElementChild;
  761. targetArrow = el.target.parentElement.nextElementSibling;
  762. }
  763. for (let openElement of document.querySelectorAll('h4 + p > em > img, h4 + p + p')) {
  764. if (openElement !== targetContent && openElement !== targetArrow) {
  765. openElement.classList.remove('open');
  766. }
  767. }
  768. targetContent.classList.toggle('open');
  769. targetArrow.classList.toggle('open');
  770. }