time-zones.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. function getCookie(name) {
  9. var start = document.cookie.indexOf(name + "=");
  10. var len = start + name.length + 1;
  11. if (!start && name != document.cookie.substring(0, name.length)) {
  12. return null;
  13. }
  14. if (start == -1) return null;
  15. var end = document.cookie.indexOf(";", len);
  16. if (end == -1) end = document.cookie.length;
  17. return decodeURI(document.cookie.substring(len, end));
  18. }
  19. document.addEventListener("DOMContentLoaded", function () {
  20. var initialTimeZone = "local";
  21. var timeZoneSelectorEl = document.getElementById("time-zone-selector");
  22. var loadingEl = document.getElementById("loading");
  23. var calendarEl = document.getElementById("calendar");
  24. var calendar = new FullCalendar.Calendar(calendarEl, {
  25. timeZone: initialTimeZone,
  26. locale: getCookie("language"),
  27. headerToolbar: {
  28. left: "prev,next today",
  29. center: "title",
  30. right: "dayGridMonth,timeGridWeek,timeGridDay,listWeek",
  31. },
  32. //initialDate: "2020-12-12",
  33. navLinks: true, // can click day/week names to navigate views
  34. editable: true,
  35. selectable: true,
  36. dayMaxEvents: true, // allow "more" link when too many events
  37. events: {
  38. url: "php/get-events.php",
  39. failure: function () {
  40. document.getElementById("script-warning").style.display = "inline"; // show
  41. },
  42. },
  43. eventClick: function (info) {
  44. info.jsEvent.preventDefault(); // don't let the browser navigate
  45. if (info.event.url) {
  46. window.open(info.event.url);
  47. }
  48. },
  49. loading: function (bool) {
  50. if (bool) {
  51. loadingEl.style.display = "inline"; // show
  52. } else {
  53. loadingEl.style.display = "none"; // hide
  54. }
  55. },
  56. eventTimeFormat: { hour: "numeric", minute: "2-digit" },
  57. dateClick: function (arg) {
  58. console.log("dateClick", calendar.formatIso(arg.date));
  59. },
  60. select: function (arg) {
  61. console.log("select", calendar.formatIso(arg.start), calendar.formatIso(arg.end));
  62. },
  63. });
  64. calendar.render();
  65. // load the list of available timezones, build the <select> options
  66. // it's HIGHLY recommended to use a different library for network requests, not this internal util func
  67. FullCalendar.requestJson(
  68. "GET",
  69. "php/get-time-zones.php",
  70. {},
  71. function (timeZones) {
  72. timeZones.forEach(function (timeZone) {
  73. var optionEl;
  74. if (timeZone !== "UTC") {
  75. // UTC is already in the list
  76. optionEl = document.createElement("option");
  77. optionEl.value = timeZone;
  78. optionEl.innerText = timeZone;
  79. timeZoneSelectorEl.appendChild(optionEl);
  80. }
  81. });
  82. },
  83. function () {
  84. // TODO: handle error
  85. }
  86. );
  87. // when the timezone selector changes, dynamically change the calendar option
  88. timeZoneSelectorEl.addEventListener("change", function () {
  89. calendar.setOption("timeZone", this.value);
  90. });
  91. });
  92. </script>
  93. <style>
  94. body {
  95. margin: 0;
  96. padding: 0;
  97. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  98. font-size: 14px;
  99. }
  100. #top {
  101. background: #eee;
  102. border-bottom: 1px solid #ddd;
  103. padding: 0 10px;
  104. line-height: 40px;
  105. font-size: 12px;
  106. }
  107. .left {
  108. float: left;
  109. }
  110. .right {
  111. float: right;
  112. }
  113. .clear {
  114. clear: both;
  115. }
  116. #script-warning,
  117. #loading {
  118. display: none;
  119. }
  120. #script-warning {
  121. font-weight: bold;
  122. color: red;
  123. }
  124. #calendar {
  125. max-width: 1100px;
  126. margin: 40px auto;
  127. padding: 0 10px;
  128. }
  129. .tzo {
  130. color: #000;
  131. }
  132. </style>
  133. </head>
  134. <body>
  135. <div id="top">
  136. <div class="left">
  137. Timezone:
  138. <select id="time-zone-selector">
  139. <option value="local" selected>local</option>
  140. <option value="UTC">UTC</option>
  141. </select>
  142. </div>
  143. <div class="right">
  144. <span id="loading">loading...</span>
  145. <span id="script-warning"><code>php/get-events.php</code> must be running.</span>
  146. </div>
  147. <div class="clear"></div>
  148. </div>
  149. <div id="calendar"></div>
  150. </body>
  151. </html>