main.js 5.8 KB

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