Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en">
  4.  
  5. <head>
  6.  
  7. <meta charset="UTF-8">
  8.  
  9. <title>Bus Schedule</title>
  10.  
  11. <style>
  12.  
  13. #schedule { text-align: center; width: 400px; }
  14.  
  15. input { width: 120px; }
  16.  
  17. #info { background-color:aquamarine; border:1px solid black; margin:0.25em; }
  18.  
  19. .info { font-size: 1.5em; padding: 0.25em; }
  20.  
  21. </style>
  22.  
  23. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  24.  
  25. </head>
  26.  
  27. <body>
  28.  
  29. <div id="schedule">
  30.  
  31. <div id="info"><span class="info">Not Connected</span></div>
  32.  
  33. <div id="controls">
  34.  
  35. <input id="depart" value="Depart" type="button" onclick="result.depart()">
  36.  
  37. <input id="arrive" value="Arrive" type="button" onclick="result.arrive()" disabled="true">
  38.  
  39. </div>
  40.  
  41. </div>
  42.  
  43. <script>
  44.  
  45. function solve() {
  46. let apiUrl = 'https://judgetests.firebaseio.com/schedule/';
  47. let currentStop = 'depot';
  48. let nextStop = 'depot';
  49.  
  50. function depart() {
  51. toggleButtons('#arrive', '#depart');
  52. $.ajax({
  53. method: 'GET',
  54. url: apiUrl + currentStop + '.json',
  55. success: function (data) {
  56. nextStop = data.next;
  57. $('#info').find('span').text(`Next stop ${data.name}`);
  58. }
  59. });
  60. }
  61.  
  62. function arrive() {
  63. toggleButtons('#depart', '#arrive');
  64. $.ajax({
  65. method: 'GET',
  66. url: apiUrl + currentStop + '.json',
  67. success: function (data) {
  68. $('#info').find('span').text(`Arriving at ${data.name}`);
  69. currentStop = nextStop;
  70. }
  71. });
  72. }
  73.  
  74. function toggleButtons(buttonA, buttonB) {
  75. $(buttonA).removeAttr('disabled');
  76. $(buttonB).attr('disabled', 'disabled');
  77. }
  78.  
  79. return {
  80. depart,
  81. arrive
  82. };
  83. }
  84.  
  85. </script>
  86.  
  87. </body>
  88.  
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement