Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. $(document).ready(function() {
  2. var spinner = $('.spinner');
  3. spinner.show();
  4. var objAjax = {
  5. type: "POST",
  6. dataType: "JSON",
  7. async: true,
  8. url: extendedWeatherInfoPath,
  9. data:
  10. {
  11. spotId: {{$spot['id']}},
  12. lat: {{$spot['lat']}},
  13. lng: {{$spot['lng']}}
  14. },
  15. success: function(data)
  16. {
  17. var wrapper = $('.miniWeatherWidget');
  18. if(data.error === false) {
  19.  
  20. //////////////////////////////////////////////////////wind graph + wave graph
  21. var htmlWind = '<p class="fsWidget">The speed of the wind</p>';
  22. var htmlWave = '<p class="fsWidget">The height of the wave</p>';
  23. var htmlSlider = '';
  24.  
  25. $.each(data.forecast.info.data.weather, function(i, item){
  26.  
  27. htmlSlider += '<div class="weathertbl">'
  28. +'<p class="hdrLabels tblHeader">'+ moment(item.date).format('dddd') +', '+ moment(item.date).format('MMM') + moment(item.date).format('D') +'</p>'
  29. +'<div class="tblContainer">';
  30.  
  31. htmlWind += '<div class="wrappercols">';
  32. htmlWind += '<div class="header-col1-5">'+ moment(item.date).format('dd') + ', '+ moment(item.date).format('D') +'</div>';
  33. htmlWind += '<div class="col1-5">';
  34.  
  35. htmlWave += '<div class="wrappercols">';
  36. htmlWave += '<div class="header-col1-5">'+ moment(item.date).format('dd') + ', '+ moment(item.date).format('D') +'</div>';
  37. htmlWave += '<div class="col1-5">';
  38.  
  39. $.each(item.hourly, function(j, itemh){
  40.  
  41. htmlWind += '<div class="elemItem">'
  42. +'<div class="elmMed intensity_default intensity_'+ Math.ceil(parseFloat(itemh.windspeedKmph) / 7) +'" style="height:'+ itemh.windspeedKmph +'px"></div>' //7 represents 70(kmph - max speed) / 10 (total color intervals)
  43. +'<div class="elmMax intensity_default intensity_'+ Math.ceil(parseFloat(itemh.WindGustKmph) / 7) +'" style="top:'+ (70 - itemh.WindGustKmph) +'px"></div>'
  44. +'</div>';
  45.  
  46. htmlWave += '<div class="elemItem">'
  47. +'<div class="elmMed intensity_default intensity_'+ Math.ceil(parseFloat(itemh.swellHeight_m) / 0.5) +'" style="height:'+ (70 * (itemh.swellHeight_m) / 5) +'px"></div>' //0.5 represents 5(m - max height / 10 (total color intervals))
  48. +'<div class="elmMax intensity_default intensity_'+ Math.ceil(parseFloat(itemh.sigHeight_m) / 0.5) +'" style="top:'+ (70 - (70 * (itemh.sigHeight_m) / 5)) +'px"></div>'
  49. +'</div>';
  50.  
  51. htmlSlider += '<div class="tblColumn">' +
  52. +'<div class="tblCell">'+ returnReadableHour(itemh.time) +'</div>'
  53. +' </div>';
  54. });
  55.  
  56. htmlWind += '</div></div>';
  57. htmlWave += '</div></div>';
  58.  
  59. htmlSlider += '</div></div>';
  60. });
  61. $('.topGraph').html(htmlWind);
  62. $('.topGraph2').html(htmlWave);
  63. $('.containerTables').html(htmlSlider);
  64.  
  65. //load the slider for the generated content
  66. loadSlider('.slider');
  67.  
  68. } else {
  69. wrapper.html(data.error);
  70. }
  71. },
  72. error: function(XMLHttpRequest, textStatus, errorThrown)
  73. {
  74. //console.log(errorThrown);
  75. }
  76. };
  77.  
  78. $.ajax(objAjax);
  79.  
  80. function returnReadableHour(time) {
  81. var objHours = {
  82. 0: '0h',
  83. 300: '03h',
  84. 600: '06h',
  85. 900: '09h',
  86. 1200: '12h',
  87. 1500: '15h',
  88. 1800: '18h',
  89. 2100: '21h'
  90. };
  91.  
  92. return objHours[time];
  93. }
  94.  
  95. function loadSlider(which) {
  96. $(which).slick({
  97. dots: false,
  98. infinite: false,
  99. speed: 300,
  100. slidesToShow: 2,
  101. slidesToScroll: 2,
  102. responsive: [
  103. {
  104. breakpoint: 992,
  105. settings: {
  106. slidesToShow: 2,
  107. slidesToScroll: 1
  108. }
  109. },
  110. {
  111. breakpoint: 768,
  112. settings: {
  113. slidesToShow: 1,
  114. slidesToScroll: 1
  115. }
  116. }
  117. // You can unslick at a given breakpoint now by adding:
  118. // settings: "unslick"
  119. // instead of a settings object
  120. ]
  121. });
  122. }
  123. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement