time-zones.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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-09-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. loading: function (bool) {
  44. if (bool) {
  45. loadingEl.style.display = "inline"; // show
  46. } else {
  47. loadingEl.style.display = "none"; // hide
  48. }
  49. },
  50. eventClick: function (info) {
  51. info.jsEvent.preventDefault(); // don't let the browser navigate
  52. if (info.event.url) {
  53. window.open(info.event.url);
  54. }
  55. },
  56. eventTimeFormat: { hour: "numeric", minute: "2-digit" }, //timeZoneName: "short"
  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. font-size: 150%;
  110. }
  111. .right {
  112. float: right;
  113. }
  114. .clear {
  115. clear: both;
  116. }
  117. #script-warning,
  118. #loading {
  119. display: none;
  120. }
  121. #script-warning {
  122. font-weight: bold;
  123. color: red;
  124. }
  125. #calendar {
  126. max-width: 1100px;
  127. margin: 40px auto;
  128. padding: 0 10px;
  129. }
  130. .tzo {
  131. color: #000;
  132. }
  133. #time-zone-selector{
  134. font-size: 100%;
  135. }
  136. .fc-direction-ltr .fc-daygrid-event.fc-event-end, .fc-direction-rtl .fc-daygrid-event.fc-event-start {
  137. flex-flow: wrap;
  138. }
  139. .fc-event-title{
  140. margin-left: 16px;
  141. }
  142. </style>
  143. </head>
  144. <body>
  145. <div id="top">
  146. <div class="left">
  147. Timezone:
  148. <select id="time-zone-selector">
  149. <option value="local" selected>local</option>
  150. <option value="UTC">UTC</option>
  151. </select>
  152. </div>
  153. <div class="right">
  154. <span id="loading">loading...</span>
  155. <span id="script-warning"><code>php/get-events.php</code> must be running.</span>
  156. </div>
  157. <div class="clear"></div>
  158. </div>
  159. <div id="calendar"></div>
  160. </body>
  161. </html>