Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, Drupal) {
|
Chris@0
|
9 Drupal.behaviors.setTimezone = {
|
Chris@0
|
10 attach: function attach(context, settings) {
|
Chris@0
|
11 var $timezone = $(context).find('.timezone-detect').once('timezone');
|
Chris@0
|
12 if ($timezone.length) {
|
Chris@0
|
13 var dateString = Date();
|
Chris@0
|
14
|
Chris@0
|
15 var matches = dateString.match(/\(([A-Z]{3,5})\)/);
|
Chris@0
|
16 var abbreviation = matches ? matches[1] : 0;
|
Chris@0
|
17
|
Chris@0
|
18 var dateNow = new Date();
|
Chris@0
|
19 var offsetNow = dateNow.getTimezoneOffset() * -60;
|
Chris@0
|
20
|
Chris@0
|
21 var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0);
|
Chris@0
|
22 var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0);
|
Chris@0
|
23 var offsetJan = dateJan.getTimezoneOffset() * -60;
|
Chris@0
|
24 var offsetJul = dateJul.getTimezoneOffset() * -60;
|
Chris@0
|
25
|
Chris@0
|
26 var isDaylightSavingTime = void 0;
|
Chris@0
|
27
|
Chris@0
|
28 if (offsetJan === offsetJul) {
|
Chris@0
|
29 isDaylightSavingTime = '';
|
Chris@0
|
30 } else if (Math.max(offsetJan, offsetJul) === offsetNow) {
|
Chris@0
|
31 isDaylightSavingTime = 1;
|
Chris@0
|
32 } else {
|
Chris@0
|
33 isDaylightSavingTime = 0;
|
Chris@0
|
34 }
|
Chris@0
|
35
|
Chris@0
|
36 var path = 'system/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime;
|
Chris@0
|
37 $.ajax({
|
Chris@0
|
38 async: false,
|
Chris@0
|
39 url: Drupal.url(path),
|
Chris@0
|
40 data: { date: dateString },
|
Chris@0
|
41 dataType: 'json',
|
Chris@0
|
42 success: function success(data) {
|
Chris@0
|
43 if (data) {
|
Chris@0
|
44 $timezone.val(data);
|
Chris@0
|
45 }
|
Chris@0
|
46 }
|
Chris@0
|
47 });
|
Chris@0
|
48 }
|
Chris@0
|
49 }
|
Chris@0
|
50 };
|
Chris@0
|
51 })(jQuery, Drupal); |