main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. $(document).ready(function(){
  2. // ******* Navbars & dropdowns *******
  3. var hideDropdownsFor = function(elt, delay=0) {
  4. if (delay === 0) {
  5. elt.children('ul.dropdown-menu').removeClass('dropdown-displayed');
  6. elt.removeClass('dropdown-displayed');
  7. elt.children('ul.dropdown-menu').hide();
  8. } else {
  9. elt.delay(delay).queue(function(next) {
  10. elt.children('ul.dropdown-menu').removeClass('dropdown-displayed');
  11. elt.removeClass('dropdown-displayed');
  12. next();
  13. });
  14. elt.children('ul.dropdown-menu').delay(delay).hide(1);
  15. }
  16. }
  17. var stopDelayedHidingFor = function(elt) {
  18. elt.stop(true);
  19. elt.children('ul.dropdown-menu').stop(true);
  20. }
  21. $('.dropdown').on('mouseenter', function(e) {
  22. stopDelayedHidingFor($(this));
  23. $('.dropdown.dropdown-displayed').not($(this).parents()).each(function() {
  24. hideDropdownsFor($(this));
  25. });
  26. dropdown = $(this).find('ul.dropdown-menu:first');
  27. if (dropdown.length !== 0) {
  28. $(this).addClass('dropdown-displayed');
  29. dropdown.addClass('dropdown-displayed');
  30. dropdown.show();
  31. if ($(this).parents('.dropdown').length !== 0) {
  32. // second level dropdown
  33. dropdown.removeClass('dropdown-left').removeClass('dropdown-right');
  34. if (($(this).offset().left + $(this).width() + dropdown.width()) > $(window).width()) {
  35. dropdown.addClass('dropdown-left');
  36. } else {
  37. dropdown.addClass('dropdown-right');
  38. }
  39. }
  40. }
  41. }).on('mouseleave', function(e) {
  42. if ($(this).hasClass('delayed-collapsing')) {
  43. hideDropdownsFor($(this), 800);
  44. } else {
  45. hideDropdownsFor($(this));
  46. }
  47. });
  48. // **** Login Pop-Up and Auth
  49. $('#login-btn').on('click', function(e) {
  50. e.preventDefault();
  51. $('#login-popup .popup-form').toggleClass("show");
  52. });
  53. if ($('#login-popup').find('.alert').length) {
  54. $('#login-popup .popup-form').toggleClass("show");
  55. console.log('')
  56. }
  57. // **** Forms ****
  58. $('.datepicker').datepicker({
  59. minDate: new Date(),
  60. maxDate: "+2y",
  61. dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ],
  62. dayNamesMin: [ "Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa" ],
  63. dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ],
  64. monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ],
  65. monthNamesShort: [ "Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Juil", "Aou", "Sep", "Oct", "Nov", "Dec" ],
  66. dateFormat: "dd/mm/yy"
  67. });
  68. // **** Carousel *****
  69. // uses the slick lib, see https://kenwheeler.github.io/slick/
  70. $('.carousel').slick({
  71. arrows: false,
  72. dots: false,
  73. autoplay: true,
  74. autoplaySpeed: 3600,
  75. draggable: false,
  76. speed: 700,
  77. adaptiveHeight: false
  78. });
  79. // **** Leaflet: maps *****
  80. function showEventMap(mapDiv) {
  81. // Collect the data from th map children <i>
  82. var events = [];
  83. mapDiv.children('.event-geodata').each(function () {
  84. let event_ = {
  85. id: $(this).data('id'),
  86. long: $(this).data('long'),
  87. lat: $(this).data('lat'),
  88. label: $(this).data('label')
  89. };
  90. events.push(event_);
  91. });
  92. if (events.length === 0) {
  93. return;
  94. }
  95. // Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
  96. var mapOptions = {scrollWheelZoom: false};
  97. var initialZoom = 13;
  98. var eventMap = L.map('event-map', mapOptions);
  99. eventMap.setView([events[0].lat, events[0].long], initialZoom);
  100. console.log([events[0].lat, events[0].long]);
  101. // Add the tile layer
  102. L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
  103. maxZoom: 18,
  104. id: 'mapbox/streets-v11',
  105. tileSize: 512,
  106. zoomOffset: -1,
  107. 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>',
  108. accessToken: 'pk.eyJ1Ijoib2xpdmllci1tYXNzb3QiLCJhIjoiY2s5OGl1M2cxMWNpajNscnV4Zm5maWY3eSJ9.YDESFgB-JuAhplTzXI6hGQ',
  109. }).addTo(eventMap);
  110. // Collect the event geodata to create the markers
  111. var markers = []
  112. events.forEach(function (event_) {
  113. var marker = L.marker([event_.lat, event_.long]).addTo(eventMap);
  114. marker.bindPopup(event_.label);
  115. markers.push(marker);
  116. });
  117. // Set the view
  118. var markersGroup = new L.featureGroup(markers);
  119. eventMap.fitBounds(markersGroup.getBounds());
  120. eventMap.zoomSnap = 1;
  121. eventMap.zoomOut();
  122. }
  123. if ($('.ot-all-events #event-map').length) {
  124. showEventMap($('#event-map').first());
  125. }
  126. if ($('.ot-show-event #event-map').length) {
  127. showEventMap($('#event-map').first());
  128. }
  129. });