script.js 23 KB

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