custom.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. (function ($) {
  2. new WOW().init();
  3. var today = new Date();
  4. var year = today.getUTCFullYear();
  5. var month = today.getMonth() + 1;
  6. if (month < 10) {
  7. var month = "0" + month;
  8. }
  9. var day = today.getDate();
  10. if (day < 10) {
  11. var day = "0" + month;
  12. }
  13. var stupidlyUglyDateTimeFormatOfSemanticMerdiaWiki = year + "-2D" + month + "-2D" + day;
  14. var previous_events_url = "/index.php?title=Special:Ask/-5B-5BCategory:Event-5D-5D-20-5B-5BEvent-20status::Ready-5D-5D-20-5B-5BDate::-3C" + stupidlyUglyDateTimeFormatOfSemanticMerdiaWiki + "T00:00:00-5D-5D/-3FDate/-3FPlace/format%3Djson/limit%3D2/sort%3DDate/order%3Ddescending/default%3DNo-20past-20event./offset%3D0";
  15. var next_events_url = "/index.php?title=Special:Ask/-5B-5BCategory:Event-5D-5D-20-5B-5BEvent-20status::Ready-5D-5D-20-5B-5BDate::-3E" + stupidlyUglyDateTimeFormatOfSemanticMerdiaWiki + "T00:00:00-5D-5D/-3FDate/-3FPlace/format%3Djson/limit%3D10/sort%3DDate/order%3Dascending/default%3DNo-20upcoming-20event./offset%3D0";
  16. jQuery(window).load(function() {
  17. jQuery("#preloader").delay(100).fadeOut("slow");
  18. jQuery("#load").delay(100).fadeOut("slow");
  19. var osm_html = '<iframe width="100%" height="300px" frameBorder="0" src="https://umap.openstreetmap.fr/fr/map/carte-sans-nom_26223?scaleControl=true&miniMap=false&scrollWheelZoom=false&zoomControl=true&allowEdit=false&moreControl=false&datalayersControl=false&onLoadPanel=undefined"></iframe><p><a href="https://umap.openstreetmap.fr/fr/map/carte-sans-nom_26223" style="color: yellow"><b>Full screen</b></a></p>';
  20. $("#osm").html(osm_html);
  21. });
  22. //jQuery to collapse the navbar on scroll
  23. $(window).scroll(function() {
  24. if ($(".navbar").offset().top > 50) {
  25. $(".navbar-fixed-top").addClass("top-nav-collapse");
  26. } else {
  27. $(".navbar-fixed-top").removeClass("top-nav-collapse");
  28. }
  29. });
  30. //jQuery to inline SVG so it's stylable which makes me so happy
  31. /*
  32. * http://stackoverflow.com/questions/11978995/how-to-change-color-of-svg-image-using-css-jquery-svg-image-replacement
  33. * Replace all SVG images with inline SVG
  34. */
  35. jQuery('img.svg').each(function(){
  36. var $img = jQuery(this);
  37. var imgID = $img.attr('id');
  38. var imgClass = $img.attr('class');
  39. var imgURL = $img.attr('src');
  40. jQuery.get(imgURL, function(data) {
  41. // Get the SVG tag, ignore the rest
  42. var $svg = jQuery(data).find('svg');
  43. // Add replaced image's ID to the new SVG
  44. if(typeof imgID !== 'undefined') {
  45. $svg = $svg.attr('id', imgID);
  46. }
  47. // Add replaced image's classes to the new SVG
  48. if(typeof imgClass !== 'undefined') {
  49. $svg = $svg.attr('class', imgClass+' replaced-svg');
  50. }
  51. // Remove any invalid XML tags as per http://validator.w3.org
  52. $svg = $svg.removeAttr('xmlns:a');
  53. // Replace image with new SVG
  54. $img.replaceWith($svg);
  55. }, 'xml');
  56. });
  57. function addMeetings(url, kind) {
  58. var element = $("#" + kind + "-meetings");
  59. $.getJSON(url).success(function(data){
  60. if ($.isEmptyObject(data.results)) {
  61. // will only happen for next meeting *normally* (haha.)
  62. element.html('<p class="meeting"><i>There is no next meeting planned yet</i></p>')
  63. } else {
  64. // this is horrible, I do this because data is not in a list but is sorted on the object
  65. // semantic merdiawiki really have a shitty export
  66. for (i in data.results) {
  67. var url = data.results[i].fullurl;
  68. var location = data.results[i].printouts.Place[0]
  69. var date = new Date(data.results[i].printouts.Date[0] * 1000);
  70. // javascript is super lame
  71. var month = date.getMonth() + 1;
  72. if (month < 10) {
  73. var month = "0" + month;
  74. }
  75. var date = date.getDate() + "/" + month + "/" + date.getUTCFullYear();
  76. element.append('<p class="meeting">' + date + ' - <a href="' + window.location.protocol + url + '"><b>' + i.slice(6, i.length) + '</b></a> ' + location + '</p>')
  77. }
  78. }
  79. }).error(function(data) {
  80. console.log("Can't get " + kind + " meetings: ");
  81. console.log(data);
  82. element.html('<p class="meeting"><i>There is no next meeting planned yet</i></p>')
  83. })
  84. }
  85. //jQuery for page scrolling feature - requires jQuery Easing plugin
  86. $(function() {
  87. addMeetings(previous_events_url, "previous");
  88. addMeetings(next_events_url, "next");
  89. $('.navbar-nav li a').bind('click', function(event) {
  90. var $anchor = $(this);
  91. $('html, body').stop().animate({
  92. scrollTop: $($anchor.attr('href')).offset().top
  93. }, 1500, 'easeInOutExpo');
  94. event.preventDefault();
  95. });
  96. $('.page-scroll a').bind('click', function(event) {
  97. var $anchor = $(this);
  98. $('html, body').stop().animate({
  99. scrollTop: $($anchor.attr('href')).offset().top
  100. }, 1500, 'easeInOutExpo');
  101. event.preventDefault();
  102. });
  103. });
  104. })(jQuery);