diff --git a/ietf/static/js/timezone.js b/ietf/static/js/timezone.js index 21f6cad774..1d7207fe00 100644 --- a/ietf/static/js/timezone.js +++ b/ietf/static/js/timezone.js @@ -1,5 +1,5 @@ - // Copyright The IETF Trust 2021, All Rights Reserved - +// Copyright The IETF Trust 2021, All Rights Reserved +/* global moment */ /* Timezone selection handling. Relies on the moment.js library. @@ -8,21 +8,16 @@ names. Time zone can be changed via the select input or by calling the use() method with the name of a time zone (or 'local' to guess the user's local timezone). */ -window.ietf_timezone; // public interface - (function () { 'use strict'; // Callback for timezone change - called after current_timezone is updated - var timezone_change_callback; - var current_timezone; + let timezone_change_callback; + let current_timezone; + let tz_radios; + let tz_selects; // Select timezone to use. Arg is name of a timezone or 'local' to guess local tz. function use_timezone(newtz) { - // Guess local timezone if necessary - if (newtz.toLowerCase() === 'local') { - newtz = moment.tz.guess(); - } - if (current_timezone !== newtz) { current_timezone = newtz; // Update values of tz-select inputs but do not trigger change event @@ -31,9 +26,18 @@ window.ietf_timezone; // public interface if (timezone_change_callback) { timezone_change_callback(newtz); } + tz_radios.filter(`[value="${newtz}"]`).prop('checked', true); + tz_radios.filter(`[value!="${newtz}"]`).prop('checked', false); + tz_selects.val(newtz); + tz_selects.trigger('change.select2'); // notify only select2 of change to avoid change event storm } } + function handle_change_event(evt) { + const newtz = evt.target.value; + use_timezone(newtz); // use the requested timezone + } + /* Initialize timezone system * * This will set the timezone to the value of 'current'. Set up the tz_change callback @@ -41,30 +45,33 @@ window.ietf_timezone; // public interface */ function timezone_init(current) { var tz_names = moment.tz.names(); - var select = $('select.tz-select'); - - select.empty(); + if (current === 'local') { + current = moment.tz.guess(); + } + tz_selects = $('select.tz-select'); + tz_selects.empty(); $.each(tz_names, function (i, item) { - select.append($('