main.js 4.4 KB

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