|
| 1 | +// Initialize moments |
| 2 | +function initialize_moments() { |
| 3 | + var times=$('span.time') |
| 4 | + $.each(times, function(i, item) { |
| 5 | + item.start_ts = moment.unix(this.getAttribute("data-start-time")).utc(); |
| 6 | + item.end_ts = moment.unix(this.getAttribute("data-end-time")).utc(); |
| 7 | + if (this.hasAttribute("weekday")) { |
| 8 | + item.format=2; |
| 9 | + } else { |
| 10 | + item.format=1; |
| 11 | + } |
| 12 | + if (this.hasAttribute("format")) { |
| 13 | + item.format = +this.getAttribute("format"); |
| 14 | + } |
| 15 | + }); |
| 16 | + var times=$('[data-slot-start-ts]') |
| 17 | + $.each(times, function(i, item) { |
| 18 | + item.slot_start_ts = moment.unix(this.getAttribute("data-slot-start-ts")).utc(); |
| 19 | + item.slot_end_ts = moment.unix(this.getAttribute("data-slot-end-ts")).utc(); |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +// Initialize timezone system |
| 24 | +function timezone_init(current) { |
| 25 | + var tz_names = moment.tz.names(); |
| 26 | + var select = $('#timezone_select'); |
| 27 | + |
| 28 | + $.each(tz_names, function(i, item) { |
| 29 | + if (current == item) { |
| 30 | + select.append($('<option/>', { |
| 31 | + selected: "selected", html: item, value: item })); |
| 32 | + } else { |
| 33 | + select.append($('<option/>', { |
| 34 | + html: item, value: item })); |
| 35 | + } |
| 36 | + }); |
| 37 | + initialize_moments(); |
| 38 | + select.change(function () { |
| 39 | + update_times(this.value); |
| 40 | + }); |
| 41 | + update_times(current); |
| 42 | + add_tooltips(); |
| 43 | +} |
| 44 | + |
| 45 | +// Select which timezone is used, 0 = meeting, 1 = browser local, 2 = UTC |
| 46 | +function use_timezone (val) { |
| 47 | + switch (val) { |
| 48 | + case 0: |
| 49 | + tz = meeting_timezone; |
| 50 | + break; |
| 51 | + case 1: |
| 52 | + tz = local_timezone; |
| 53 | + break; |
| 54 | + default: |
| 55 | + tz = 'UTC'; |
| 56 | + break; |
| 57 | + } |
| 58 | + $('#timezone_select').val(tz); |
| 59 | + update_times(tz); |
| 60 | +} |
| 61 | + |
| 62 | +// Format time for item for timezone. Depending on the fmt |
| 63 | +// use different formats. |
| 64 | +// Formats: 0 = long format "Saturday, October 24th 2020, 13:52 +00:00 UTC" |
| 65 | +// 1 = Short format "13:52", "13:52 (-1)", or "13:52 (+1)" |
| 66 | +// 2 = Short format with weekday, "Friday, 13:52 (-1)" |
| 67 | +// 3 = Date only "2020-10-24" |
| 68 | +// 4 = Date and time "2020-10-24 13:52" |
| 69 | +// 5 = Time only "13:52". |
| 70 | + |
| 71 | +function format_time(t, tz, fmt) { |
| 72 | + var out; |
| 73 | + var mtz = meeting_timezone; |
| 74 | + if (mtz == "") { |
| 75 | + mtz = "UTC"; |
| 76 | + } |
| 77 | + |
| 78 | + switch (fmt) { |
| 79 | + case 0: |
| 80 | + out = t.tz(tz).format('dddd, ') + '<span class="hidden-xs">' + |
| 81 | + t.tz(tz).format('MMMM Do YYYY, ') + '</span>' + |
| 82 | + t.tz(tz).format('HH:mm') + '<span class="hidden-xs">' + |
| 83 | + t.tz(tz).format(' Z z') + '</span>'; |
| 84 | + break; |
| 85 | + case 1: |
| 86 | + // Note, this code does not work if the meeting crosses the |
| 87 | + // year boundary. |
| 88 | + out = t.tz(tz).format("HH:mm"); |
| 89 | + if (+t.tz(tz).dayOfYear() < +t.tz(mtz).dayOfYear()) { |
| 90 | + out = out + " (-1)"; |
| 91 | + } else if (+t.tz(tz).dayOfYear() > +t.tz(mtz).dayOfYear()) { |
| 92 | + out = out + " (+1)"; |
| 93 | + } |
| 94 | + break; |
| 95 | + case 2: |
| 96 | + out = t.tz(mtz).format("dddd, ").toUpperCase() + |
| 97 | + t.tz(tz).format("HH:mm"); |
| 98 | + if (+t.tz(tz).dayOfYear() < +t.tz(mtz).dayOfYear()) { |
| 99 | + out = out + " (-1)"; |
| 100 | + } else if (+t.tz(tz).dayOfYear() > +t.tz(mtz).dayOfYear()) { |
| 101 | + out = out + " (+1)"; |
| 102 | + } |
| 103 | + break; |
| 104 | + case 3: |
| 105 | + out = t.utc().format("YYYY-MM-DD"); |
| 106 | + break; |
| 107 | + case 4: |
| 108 | + out = t.tz(tz).format("YYYY-MM-DD HH:mm"); |
| 109 | + break; |
| 110 | + case 5: |
| 111 | + out = t.tz(tz).format("HH:mm"); |
| 112 | + break; |
| 113 | + } |
| 114 | + return out; |
| 115 | +} |
| 116 | + |
| 117 | + |
| 118 | +// Format tooltip notice |
| 119 | +function format_tooltip_notice(start, end) { |
| 120 | + var notice = ""; |
| 121 | + |
| 122 | + if (end.isBefore()) { |
| 123 | + notice = "Event ended " + end.fromNow(); |
| 124 | + } else if (start.isAfter()) { |
| 125 | + notice = "Event will start " + start.fromNow(); |
| 126 | + } else { |
| 127 | + notice = "Event started " + start.fromNow() + " and will end " + |
| 128 | + end.fromNow(); |
| 129 | + } |
| 130 | + return '<span class="tooltipnotice">' + notice + '</span>'; |
| 131 | +} |
| 132 | + |
| 133 | +// Format tooltip table |
| 134 | +function format_tooltip_table(start, end) { |
| 135 | + var out = '<table><tr><th>Timezone</th><th>Start</th><th>End</th></tr>'; |
| 136 | + if (meeting_timezone != "") { |
| 137 | + out += '<tr><td class="timehead">Meeting timezone:</td><td>' + |
| 138 | + format_time(start, meeting_timezone, 0) + '</td><td>' + |
| 139 | + format_time(end, meeting_timezone, 0) + '</td></tr>'; |
| 140 | + } |
| 141 | + out += '<tr><td class="timehead">Local timezone:</td><td>' + |
| 142 | + format_time(start, local_timezone, 0) + '</td><td>' + |
| 143 | + format_time(end, local_timezone, 0) + '</td></tr>'; |
| 144 | + if (current_timezone != 'UTC') { |
| 145 | + out += '<tr><td class="timehead">Selected Timezone:</td><td>' + |
| 146 | + format_time(start, current_timezone, 0) + '</td><td>' + |
| 147 | + format_time(end, current_timezone, 0) + '</td></tr>'; |
| 148 | + } |
| 149 | + out += '<tr><td class="timehead">UTC:</td><td>' + |
| 150 | + format_time(start, 'UTC', 0) + '</td><td>' + |
| 151 | + format_time(end, 'UTC', 0) + '</td></tr>'; |
| 152 | + out += '</table>' + format_tooltip_notice(start, end); |
| 153 | + return out; |
| 154 | +} |
| 155 | + |
| 156 | +// Format tooltip for item |
| 157 | +function format_tooltip(start, end) { |
| 158 | + return '<span class="timetooltiptext">' + |
| 159 | + format_tooltip_table(start, end) + |
| 160 | + '</span>'; |
| 161 | +} |
| 162 | + |
| 163 | +// Add tooltips |
| 164 | +function add_tooltips() { |
| 165 | + $('span.time').each(function () { |
| 166 | + var tooltip = $(format_tooltip(this.start_ts, this.end_ts)); |
| 167 | + tooltip[0].start_ts = this.start_ts; |
| 168 | + tooltip[0].end_ts = this.end_ts; |
| 169 | + tooltip[0].ustart_ts = moment(this.start_ts).add(-2, 'hours'); |
| 170 | + tooltip[0].uend_ts = moment(this.end_ts).add(2, 'hours'); |
| 171 | + $(this).parent().append(tooltip); |
| 172 | + }); |
| 173 | +} |
| 174 | + |
| 175 | +// Update times on the agenda based on the selected timezone |
| 176 | +function update_times(newtz) { |
| 177 | + current_timezone = newtz; |
| 178 | + $('#title-timezone').html(newtz); |
| 179 | + $('span.time').each(function () { |
| 180 | + if (this.format == 4) { |
| 181 | + var tz = this.start_ts.tz(newtz).format(" z"); |
| 182 | + if (this.start_ts.tz(newtz).dayOfYear() == |
| 183 | + this.end_ts.tz(newtz).dayOfYear()) { |
| 184 | + $(this).html(format_time(this.start_ts, newtz, this.format) + |
| 185 | + '-' + format_time(this.end_ts, newtz, 5) + tz); |
| 186 | + } else { |
| 187 | + $(this).html(format_time(this.start_ts, newtz, this.format) + |
| 188 | + '-' + |
| 189 | + format_time(this.end_ts, newtz, this.format) + tz); |
| 190 | + } |
| 191 | + } else { |
| 192 | + $(this).html(format_time(this.start_ts, newtz, this.format) + '-' + |
| 193 | + format_time(this.end_ts, newtz, this.format)); |
| 194 | + } |
| 195 | + }); |
| 196 | + update_tooltips_all(); |
| 197 | + update_clock(); |
| 198 | + // update_calendar(agenda_filter.get_filter()) |
| 199 | +} |
| 200 | + |
| 201 | +// Highlight ongoing based on the current time |
| 202 | +function highlight_ongoing() { |
| 203 | + $("div#now").remove("#now"); |
| 204 | + $('.ongoing').removeClass("ongoing"); |
| 205 | + var agenda_rows=$('[data-slot-start-ts]') |
| 206 | + agenda_rows = agenda_rows.filter(function() { |
| 207 | + return moment().isBetween(this.slot_start_ts, this.slot_end_ts); |
| 208 | + }); |
| 209 | + agenda_rows.addClass("ongoing"); |
| 210 | + agenda_rows.first().children("th, td"). |
| 211 | + prepend($('<div id="now" class="anchor-target"></div>')); |
| 212 | +} |
| 213 | + |
| 214 | +// Update tooltips |
| 215 | +function update_tooltips() { |
| 216 | + var tooltips=$('.timetooltiptext'); |
| 217 | + tooltips.filter(function() { |
| 218 | + return moment().isBetween(this.ustart_ts, this.uend_ts); |
| 219 | + }).each(function () { |
| 220 | + $(this).html(format_tooltip_table(this.start_ts, this.end_ts)); |
| 221 | + }); |
| 222 | +} |
| 223 | + |
| 224 | +// Update all tooltips |
| 225 | +function update_tooltips_all() { |
| 226 | + var tooltips=$('.timetooltiptext'); |
| 227 | + tooltips.each(function () { |
| 228 | + $(this).html(format_tooltip_table(this.start_ts, this.end_ts)); |
| 229 | + }); |
| 230 | +} |
| 231 | + |
| 232 | +// Update clock |
| 233 | +function update_clock() { |
| 234 | + $('#current-time').html(format_time(moment(), current_timezone, 0)); |
| 235 | +} |
| 236 | + |
| 237 | +$.urlParam = function(name) { |
| 238 | + var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); |
| 239 | + if (results == null) { |
| 240 | + return null; |
| 241 | + } else { |
| 242 | + return results[1] || 0; |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +function init_timers() { |
| 247 | + var fast_timer = 60000 / (speedup > 600 ? 600 : speedup); |
| 248 | + update_clock(); |
| 249 | + highlight_ongoing(); |
| 250 | + setInterval(function() { update_clock(); }, fast_timer); |
| 251 | + setInterval(function() { highlight_ongoing(); }, fast_timer); |
| 252 | + setInterval(function() { update_tooltips(); }, fast_timer); |
| 253 | + setInterval(function() { update_tooltips_all(); }, 3600000 / speedup); |
| 254 | +} |
| 255 | + |
0 commit comments