main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. $(document).ready(function(){
  2. // ******* Navbars & dropdowns *******
  3. // delay in ms before dropdown collapse after the cursor leave
  4. var collapsingDelay = 400;
  5. // hide the dropdown element and its children
  6. var hideDropdownsFor = function(elt, delay=0) {
  7. if (delay === 0) {
  8. elt.children('ul.dropdown-menu').removeClass('dropdown-displayed');
  9. elt.removeClass('dropdown-displayed');
  10. elt.children('ul.dropdown-menu').hide();
  11. } else {
  12. elt.delay(delay).queue(function(next) {
  13. elt.children('ul.dropdown-menu').removeClass('dropdown-displayed');
  14. elt.removeClass('dropdown-displayed');
  15. next();
  16. });
  17. elt.children('ul.dropdown-menu').delay(delay).hide(1);
  18. }
  19. }
  20. // stop any delayed commands on elt and its children
  21. var stopDelayedHidingFor = function(elt) {
  22. elt.stop(true);
  23. elt.children('ul.dropdown-menu').stop(true);
  24. }
  25. $('.dropdown').on('mouseenter', function(e) {
  26. // stop any delayed hiding on this since the cursor went back on it
  27. stopDelayedHidingFor($(this));
  28. // hide every other dropdown in the page
  29. $('.dropdown.dropdown-displayed').not($(this).parents()).each(function() {
  30. hideDropdownsFor($(this));
  31. });
  32. // display the dropdown
  33. dropdown = $(this).find('ul.dropdown-menu:first');
  34. if (dropdown.length !== 0) {
  35. $(this).addClass('dropdown-displayed');
  36. dropdown.addClass('dropdown-displayed');
  37. dropdown.show();
  38. // if this is a second level dropdown
  39. if ($(this).parents('.dropdown').length !== 0) {
  40. // move it on the right or left according to its current position
  41. dropdown.removeClass('dropdown-left').removeClass('dropdown-right');
  42. if (($(this).offset().left + $(this).width() + dropdown.width()) > $(window).width()) {
  43. dropdown.addClass('dropdown-left');
  44. } else {
  45. dropdown.addClass('dropdown-right');
  46. }
  47. }
  48. }
  49. }).on('mouseleave', function(e) {
  50. if ($(this).hasClass('delayed-collapsing')) {
  51. hideDropdownsFor($(this), collapsingDelay);
  52. } else {
  53. hideDropdownsFor($(this));
  54. }
  55. });
  56. // * Sticky menu
  57. var menuTop = $('#menu').offset().top;
  58. var menuHeight = $('#menu').height();
  59. $(function(){
  60. $(window).scroll(function() {
  61. if ($(this).scrollTop() >= menuTop) {
  62. $('#menu').addClass('sticky');
  63. }
  64. else if (($(this).scrollTop() < (menuTop - menuHeight))) {
  65. $('#menu').removeClass('sticky');
  66. }
  67. });
  68. });
  69. // **** Login Pop-Up and Auth
  70. $('#login-btn').on('click', function(e) {
  71. e.preventDefault();
  72. $('#login-popup .popup-form').toggleClass("show");
  73. });
  74. if ($('#login-popup').find('.alert').length) {
  75. $('#login-popup .popup-form').toggleClass("show");
  76. }
  77. // **** Forms ****
  78. $('.datepicker').datepicker({
  79. minDate: new Date(),
  80. maxDate: "+2y",
  81. dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ],
  82. dayNamesMin: [ "Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa" ],
  83. dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ],
  84. monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ],
  85. monthNamesShort: [ "Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Juil", "Aou", "Sep", "Oct", "Nov", "Dec" ],
  86. dateFormat: "dd/mm/yy"
  87. });
  88. // **** Carousels *****
  89. // uses the slick lib, see https://kenwheeler.github.io/slick/
  90. $('header .carousel').slick({
  91. arrows: false,
  92. dots: false,
  93. autoplay: true,
  94. autoplaySpeed: 3600,
  95. draggable: false,
  96. speed: 700,
  97. adaptiveHeight: false
  98. });
  99. $('.content .carousel').slick({
  100. arrows: true,
  101. dots: true,
  102. autoplay: true,
  103. autoplaySpeed: 2400,
  104. draggable: false,
  105. speed: 700
  106. });
  107. // **** Leaflet: maps *****
  108. function showEventMap(mapDiv) {
  109. // Collect the data from th map children <i>
  110. var events = [];
  111. mapDiv.children('.event-geodata').each(function () {
  112. let event_ = {
  113. id: $(this).data('id'),
  114. long: $(this).data('long'),
  115. lat: $(this).data('lat'),
  116. label: $(this).data('label')
  117. };
  118. events.push(event_);
  119. });
  120. if (events.length === 0) {
  121. return;
  122. }
  123. // Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
  124. var mapOptions = {scrollWheelZoom: false};
  125. var initialZoom = 13;
  126. var eventMap = L.map('event-map', mapOptions);
  127. eventMap.setView([events[0].lat, events[0].long], initialZoom);
  128. // Add the tile layer
  129. L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
  130. maxZoom: 18,
  131. id: 'mapbox/streets-v11',
  132. tileSize: 512,
  133. zoomOffset: -1,
  134. attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  135. accessToken: 'pk.eyJ1Ijoib2xpdmllci1tYXNzb3QiLCJhIjoiY2s5OGl1M2cxMWNpajNscnV4Zm5maWY3eSJ9.YDESFgB-JuAhplTzXI6hGQ',
  136. }).addTo(eventMap);
  137. // Collect the event geodata to create the markers
  138. var markers = []
  139. events.forEach(function (event_) {
  140. var marker = L.marker([event_.lat, event_.long]).addTo(eventMap);
  141. marker.bindPopup(event_.label);
  142. markers.push(marker);
  143. });
  144. // Set the view
  145. var markersGroup = new L.featureGroup(markers);
  146. eventMap.fitBounds(markersGroup.getBounds());
  147. eventMap.zoomSnap = 1;
  148. eventMap.zoomOut();
  149. }
  150. if ($('.ot-all-events #event-map').length) {
  151. showEventMap($('#event-map').first());
  152. }
  153. if ($('.ot-show-event #event-map').length) {
  154. showEventMap($('#event-map').first());
  155. }
  156. });