script.js 23 KB

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