main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // **** Carousel *****
  92. // uses the slick lib, see https://kenwheeler.github.io/slick/
  93. $('.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. // **** Leaflet: maps *****
  103. function showEventMap(mapDiv) {
  104. // Collect the data from th map children <i>
  105. var events = [];
  106. mapDiv.children('.event-geodata').each(function () {
  107. let event_ = {
  108. id: $(this).data('id'),
  109. long: $(this).data('long'),
  110. lat: $(this).data('lat'),
  111. label: $(this).data('label')
  112. };
  113. events.push(event_);
  114. });
  115. if (events.length === 0) {
  116. return;
  117. }
  118. // Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
  119. var mapOptions = {scrollWheelZoom: false};
  120. var initialZoom = 13;
  121. var eventMap = L.map('event-map', mapOptions);
  122. eventMap.setView([events[0].lat, events[0].long], initialZoom);
  123. console.log([events[0].lat, events[0].long]);
  124. // Add the tile layer
  125. L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
  126. maxZoom: 18,
  127. id: 'mapbox/streets-v11',
  128. tileSize: 512,
  129. zoomOffset: -1,
  130. 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>',
  131. accessToken: 'pk.eyJ1Ijoib2xpdmllci1tYXNzb3QiLCJhIjoiY2s5OGl1M2cxMWNpajNscnV4Zm5maWY3eSJ9.YDESFgB-JuAhplTzXI6hGQ',
  132. }).addTo(eventMap);
  133. // Collect the event geodata to create the markers
  134. var markers = []
  135. events.forEach(function (event_) {
  136. var marker = L.marker([event_.lat, event_.long]).addTo(eventMap);
  137. marker.bindPopup(event_.label);
  138. markers.push(marker);
  139. });
  140. // Set the view
  141. var markersGroup = new L.featureGroup(markers);
  142. eventMap.fitBounds(markersGroup.getBounds());
  143. eventMap.zoomSnap = 1;
  144. eventMap.zoomOut();
  145. }
  146. if ($('.ot-all-events #event-map').length) {
  147. showEventMap($('#event-map').first());
  148. }
  149. if ($('.ot-show-event #event-map').length) {
  150. showEventMap($('#event-map').first());
  151. }
  152. });