script.js 22 KB

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