main.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. console.log($(this).scrollTop());
  62. console.log(menuTop);
  63. if ($(this).scrollTop() >= menuTop) {
  64. $('#menu').addClass('sticky');
  65. }
  66. else if (($(this).scrollTop() < (menuTop - menuHeight))) {
  67. $('#menu').removeClass('sticky');
  68. }
  69. });
  70. });
  71. // **** Login Pop-Up and Auth
  72. $('#login-btn').on('click', function(e) {
  73. e.preventDefault();
  74. $('#login-popup .popup-form').toggleClass("show");
  75. });
  76. if ($('#login-popup').find('.alert').length) {
  77. $('#login-popup .popup-form').toggleClass("show");
  78. console.log('')
  79. }
  80. // **** Forms ****
  81. $('.datepicker').datepicker({
  82. minDate: new Date(),
  83. maxDate: "+2y",
  84. dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ],
  85. dayNamesMin: [ "Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa" ],
  86. dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ],
  87. monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ],
  88. monthNamesShort: [ "Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Juil", "Aou", "Sep", "Oct", "Nov", "Dec" ],
  89. dateFormat: "dd/mm/yy"
  90. });
  91. // **** Carousels *****
  92. // uses the slick lib, see https://kenwheeler.github.io/slick/
  93. $('header .carousel').slick({
  94. arrows: false,
  95. dots: false,
  96. autoplay: true,
  97. autoplaySpeed: 3600,
  98. draggable: false,
  99. speed: 700,
  100. adaptiveHeight: false
  101. });
  102. $('.content .carousel').slick({
  103. arrows: true,
  104. dots: true,
  105. autoplay: true,
  106. autoplaySpeed: 2400,
  107. draggable: false,
  108. speed: 700
  109. });
  110. // **** Leaflet: maps *****
  111. function showEventMap(mapDiv) {
  112. // Collect the data from th map children <i>
  113. var events = [];
  114. mapDiv.children('.event-geodata').each(function () {
  115. let event_ = {
  116. id: $(this).data('id'),
  117. long: $(this).data('long'),
  118. lat: $(this).data('lat'),
  119. label: $(this).data('label')
  120. };
  121. events.push(event_);
  122. });
  123. if (events.length === 0) {
  124. return;
  125. }
  126. // Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
  127. var mapOptions = {scrollWheelZoom: false};
  128. var initialZoom = 13;
  129. var eventMap = L.map('event-map', mapOptions);
  130. eventMap.setView([events[0].lat, events[0].long], initialZoom);
  131. console.log([events[0].lat, events[0].long]);
  132. // Add the tile layer
  133. L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
  134. maxZoom: 18,
  135. id: 'mapbox/streets-v11',
  136. tileSize: 512,
  137. zoomOffset: -1,
  138. 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>',
  139. accessToken: 'pk.eyJ1Ijoib2xpdmllci1tYXNzb3QiLCJhIjoiY2s5OGl1M2cxMWNpajNscnV4Zm5maWY3eSJ9.YDESFgB-JuAhplTzXI6hGQ',
  140. }).addTo(eventMap);
  141. // Collect the event geodata to create the markers
  142. var markers = []
  143. events.forEach(function (event_) {
  144. var marker = L.marker([event_.lat, event_.long]).addTo(eventMap);
  145. marker.bindPopup(event_.label);
  146. markers.push(marker);
  147. });
  148. // Set the view
  149. var markersGroup = new L.featureGroup(markers);
  150. eventMap.fitBounds(markersGroup.getBounds());
  151. eventMap.zoomSnap = 1;
  152. eventMap.zoomOut();
  153. }
  154. if ($('.ot-all-events #event-map').length) {
  155. showEventMap($('#event-map').first());
  156. }
  157. if ($('.ot-show-event #event-map').length) {
  158. showEventMap($('#event-map').first());
  159. }
  160. });