You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

10 years ago
  1. $(function () {
  2. $('[data-toggle="tooltip"]').tooltip();
  3. var code = $("#check-code").text();
  4. var url = $("#pitch-url").text();
  5. var lastPing = null;
  6. var lastPingHuman = null;
  7. $("#run-it").click(function() {
  8. $.get(url);
  9. });
  10. function checkLastPing() {
  11. $.getJSON("/status/" + code + "/", function(data) {
  12. if (data.last_ping != lastPing) {
  13. lastPing = data.last_ping;
  14. $("#timer").data("timer", data.secs_to_alert);
  15. }
  16. var lph = data.last_ping_human;
  17. if (lph && lph.indexOf("seconds ago") > 0)
  18. data.last_ping_human = "seconds ago";
  19. if (data.last_ping_human != lastPingHuman) {
  20. lastPingHuman = data.last_ping_human;
  21. $("#last-ping").text(lastPingHuman);
  22. }
  23. });
  24. }
  25. function updateTimer() {
  26. var timer = parseInt($("#timer").data("timer"));
  27. if (timer == 0)
  28. return;
  29. var s = timer % 60;
  30. var m = parseInt(timer / 60) % 60;
  31. var h = parseInt(timer / 3600);
  32. $("#timer").text(h + "h " + m + "m " + s + "s");
  33. $("#timer").data("timer", timer - 1);
  34. }
  35. setInterval(checkLastPing, 3000);
  36. setInterval(updateTimer, 1000);
  37. });