time-zones.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <link href='../lib/main.css' rel='stylesheet' />
  6. <script src='../lib/main.js'></script>
  7. <script>
  8. document.addEventListener('DOMContentLoaded', function() {
  9. var initialTimeZone = 'local';
  10. var timeZoneSelectorEl = document.getElementById('time-zone-selector');
  11. var loadingEl = document.getElementById('loading');
  12. var calendarEl = document.getElementById('calendar');
  13. var calendar = new FullCalendar.Calendar(calendarEl, {
  14. timeZone: initialTimeZone,
  15. headerToolbar: {
  16. left: 'prev,next today',
  17. center: 'title',
  18. right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
  19. },
  20. initialDate: '2020-06-12',
  21. navLinks: true, // can click day/week names to navigate views
  22. editable: true,
  23. selectable: true,
  24. dayMaxEvents: true, // allow "more" link when too many events
  25. events: {
  26. url: 'php/get-events.php',
  27. failure: function() {
  28. document.getElementById('script-warning').style.display = 'inline'; // show
  29. }
  30. },
  31. loading: function(bool) {
  32. if (bool) {
  33. loadingEl.style.display = 'inline'; // show
  34. } else {
  35. loadingEl.style.display = 'none'; // hide
  36. }
  37. },
  38. eventTimeFormat: { hour: 'numeric', minute: '2-digit', timeZoneName: 'short' },
  39. dateClick: function(arg) {
  40. console.log('dateClick', calendar.formatIso(arg.date));
  41. },
  42. select: function(arg) {
  43. console.log('select', calendar.formatIso(arg.start), calendar.formatIso(arg.end));
  44. }
  45. });
  46. calendar.render();
  47. // load the list of available timezones, build the <select> options
  48. // it's HIGHLY recommended to use a different library for network requests, not this internal util func
  49. FullCalendar.requestJson('GET', 'php/get-time-zones.php', {}, function(timeZones) {
  50. timeZones.forEach(function(timeZone) {
  51. var optionEl;
  52. if (timeZone !== 'UTC') { // UTC is already in the list
  53. optionEl = document.createElement('option');
  54. optionEl.value = timeZone;
  55. optionEl.innerText = timeZone;
  56. timeZoneSelectorEl.appendChild(optionEl);
  57. }
  58. });
  59. }, function() {
  60. // TODO: handle error
  61. });
  62. // when the timezone selector changes, dynamically change the calendar option
  63. timeZoneSelectorEl.addEventListener('change', function() {
  64. calendar.setOption('timeZone', this.value);
  65. });
  66. });
  67. </script>
  68. <style>
  69. body {
  70. margin: 0;
  71. padding: 0;
  72. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  73. font-size: 14px;
  74. }
  75. #top {
  76. background: #eee;
  77. border-bottom: 1px solid #ddd;
  78. padding: 0 10px;
  79. line-height: 40px;
  80. font-size: 12px;
  81. }
  82. .left { float: left }
  83. .right { float: right }
  84. .clear { clear: both }
  85. #script-warning, #loading { display: none }
  86. #script-warning { font-weight: bold; color: red }
  87. #calendar {
  88. max-width: 1100px;
  89. margin: 40px auto;
  90. padding: 0 10px;
  91. }
  92. .tzo {
  93. color: #000;
  94. }
  95. </style>
  96. </head>
  97. <body>
  98. <div id='top'>
  99. <div class='left'>
  100. Timezone:
  101. <select id='time-zone-selector'>
  102. <option value='local' selected>local</option>
  103. <option value='UTC'>UTC</option>
  104. </select>
  105. </div>
  106. <div class='right'>
  107. <span id='loading'>loading...</span>
  108. <span id='script-warning'><code>php/get-events.php</code> must be running.</span>
  109. </div>
  110. <div class='clear'></div>
  111. </div>
  112. <div id='calendar'></div>
  113. </body>
  114. </html>