time-zones.html 3.5 KB

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