PageSourceSearch

https://weatherfile.com/js/wf/settings.js

js weatherfile.com collected 2026-10-02 11:22:13 UTC 14,600 bytes, 537 lines download raw bytes

1function saveLanguage() {
2  var lang = $("#settings_language").val() || "en";
3  var previous =
4    window.WF && WF.i18nStorage
5      ? WF.i18nStorage.read()
6      : gC("wf_language") || "en";
7  var blocked =
8    window.WFConsent &&
9    typeof WFConsent.shouldBlockFunctionalWrite === "function" &&
10    WFConsent.shouldBlockFunctionalWrite();
11
12  if (blocked) {
13    $("#settings_language").val(previous);
14    notifyIfPreferenceBlocked();
15    return;
16  }
17
18  if (window.WF && WF.i18n && WF.i18n.setLocale) {
19    var applied = WF.i18n.setLocale(lang);
20    if (applied !== lang) {
21      $("#settings_language").val(previous);
22      notifyIfPreferenceBlocked();
23    }
24    return;
25  }
26
27  if (!sC("wf_language", lang, 90)) {
28    $("#settings_language").val(previous);
29    notifyIfPreferenceBlocked();
30  }
31}
32
33function saveTimeZone() {
34  var previous = gC("wf_timezone");
35  if (!sC("wf_timezone", $("#settings_time_zone").val(), 90)) {
36    $("#settings_time_zone").val(previous || "GMT");
37    notifyIfPreferenceBlocked();
38    return;
39  }
40  console.log("Saved Timeone:" + $("#settings_time_zone").val());
41}
42
43function saveCheckboxPreference(inputName, storageKey) {
44  var value = $('input[name="' + inputName + '"]:checked').val() === "on" ? "on" : "off";
45  var stored = gC(storageKey);
46  var previous = stored === "on" || stored === "off" ? stored : "on";
47  if (!sC(storageKey, value, 90)) {
48    $('input[name="' + inputName + '"]').prop("checked", previous === "on");
49    if (window.WFConsent && typeof WFConsent.notifyPreferenceBlocked === "function") {
50      WFConsent.notifyPreferenceBlocked();
51    }
52    refreshLocationDisplayIfOpen();
53  } else {
54    refreshLocationDisplayIfOpen();
55  }
56}
57
58function notifyIfPreferenceBlocked() {
59  if (window.WFConsent && typeof WFConsent.notifyPreferenceBlocked === "function") {
60    WFConsent.notifyPreferenceBlocked();
61  }
62}
63
64function refreshLocationDisplayIfOpen() {
65  if (
66    typeof window.currentPanel === "undefined" ||
67    window.currentPanel !== "location_info_container"
68  ) {
69    return;
70  }
71  if (typeof drawCharts === "function") {
72    drawCharts();
73  }
74  if (typeof showPreviewGaugeMeters === "function") {
75    showPreviewGaugeMeters();
76  }
77}
78
79function saveDisplayPublicSetting() {
80  var value = $('input[name="displaypublic"]:checked').val() === "on" ? "false" : "true";
81  var previous = gC("wf_suppress_public") === "true" ? "true" : "false";
82  if (!sC("wf_suppress_public", value, 90)) {
83    $('input[name="displaypublic"]').prop("checked", previous === "false");
84    notifyIfPreferenceBlocked();
85  }
86}
87
88function saveWindSpeedDisplaySetting() {
89  saveCheckboxPreference("windspeed", "wf_windspeedchart");
90}
91
92function saveWindDirectionDisplaySetting() {
93  saveCheckboxPreference("winddirection", "wf_winddirectionchart");
94}
95
96function saveHumidityDisplaySetting() {
97  saveCheckboxPreference("humidity", "wf_humiditychart");
98}
99
100function saveRainfallDisplaySetting() {
101  saveCheckboxPreference("rainfall", "wf_rainfallchart");
102}
103
104function savePressureDisplaySetting() {
105  saveCheckboxPreference("pressure", "wf_pressurechart");
106}
107
108function syncWindUnitsGlobal() {
109  var units = gC("wf_wunits") || "mps";
110  wunits = units;
111  if ($("#disp_units").length) {
112    if (units === "mps") {
113      $("#disp_units").html("m/s");
114    } else {
115      $("#disp_units").html(units);
116    }
117  }
118}
119
120function saveWindUnits() {
121  var next = $("#settings_wunits").val();
122  var previous = gC("wf_wunits") || "mps";
123  if (!sC("wf_wunits", next, 90)) {
124    syncWindUnitsGlobal();
125    $("#settings_wunits").val(gC("wf_wunits") || "mps");
126    notifyIfPreferenceBlocked();
127    refreshLocationDisplayIfOpen();
128    return;
129  }
130  wunits = next;
131  $("#settings_wunitsmap").val(next).change();
132  refreshLocationDisplayIfOpen();
133}
134function saveTempUnits() {
135  var previous = gC("wf_tempunits") || "celsius";
136  if (!sC("wf_tempunits", $("#settings_tempunits").val(), 90)) {
137    $("#settings_tempunits").val(previous);
138    notifyIfPreferenceBlocked();
139    return;
140  }
141  $("#settings_tempunits").val(gC("wf_tempunits")).change();
142}
143
144function saveWindUnitsmap() {
145  var next = $("#settings_wunitsmap").val();
146  var previous = gC("wf_wunits") || "mps";
147  if (!sC("wf_wunits", next, 90)) {
148    syncWindUnitsGlobal();
149    $("#settings_wunitsmap").val(gC("wf_wunits") || "mps");
150    notifyIfPreferenceBlocked();
151    return;
152  }
153  wunits = next;
154  getLatestData();
155}
156
157function saveDewpointDisplaySetting() {
158  saveCheckboxPreference("dewpoint", "wf_dewpointchart");
159}
160
161function saveWindchillDisplaySetting() {
162  saveCheckboxPreference("windchill", "wf_windchillchart");
163}
164
165function saveBgtDisplaySetting() {
166  saveCheckboxPreference("bgt", "wf_bgtchart");
167}
168
169function saveTemperatureDisplaySetting() {
170  saveCheckboxPreference("temperature", "wf_temperaturechart");
171}
172
173function saveSolarDisplaySetting() {
174  saveCheckboxPreference("solar", "wf_solarchart");
175}
176
177function saveDisplayDataTableSetting() {
178  saveCheckboxPreference("datatable", "wf_datatable");
179}
180
181function saveCustomScale() {
182  var pressuresettings = { minpressure: $('input[name="minpressure"]').val(), maxpressure: $('input[name="maxpressure"]').val() };
183  var previous = gC("wf_custom_scale");
184  if (!sC("wf_custom_scale", JSON.stringify(pressuresettings), 90) && previous) {
185    try {
186      var restored = JSON.parse(previous);
187      $('input[name="minpressure"]').val(restored.minpressure || "950");
188      $('input[name="maxpressure"]').val(restored.maxpressure || "1040");
189    } catch (e) {}
190    notifyIfPreferenceBlocked();
191  }
192}
193
194function doSaveSettings() {
195
196  saveWindUnits();
197
198  // Save the timezone setting
199  saveTimeZone();
200  saveWindSpeedDisplaySetting();
201  saveWindDirectionDisplaySetting();
202  savePressureDisplaySetting();
203  saveTemperatureDisplaySetting();
204  saveDewpointDisplaySetting();
205  saveWindchillDisplaySetting();
206  saveBgtDisplaySetting();
207  saveHumidityDisplaySetting();
208  saveRainfallDisplaySetting();
209  saveSolarDisplaySetting();
210  saveDisplayPublicSetting();
211  saveDisplayDataTableSetting();
212
213  // Reload the locations list just in case
214  load_locations_list();
215}
216
217function closeSettings() {
218
219  //doSaveSettings();
220  console.log("close settings called " + wf_user_token)
221  if (lastPanel === "location_info_container") {
222    if (currentLocation != "notset") {
223      showLocation(currentLocation);
224
225    } else {
226      showDiv("google_map_container");
227    }
228  } else {
229    showDiv("google_map_container");
230  }
231}
232
233function showSettings() {
234
235  // This function reads the settings cookies and sets up the settings form accordingly
236
237  $("#settings_language").val(
238    window.WF && WF.i18nStorage ? WF.i18nStorage.read() : (gC("wf_language") || "en")
239  );
240  $("#settings_time_zone").val(gC("wf_timezone") || "LCL");
241  $("#settings_wunits").val(gC("wf_wunits") || "mps");
242  $("#settings_wunitsmap").val(gC("wf_wunits") || "mps");
243
244  if (gC('wf_windspeedchart') === "off") {
245    $('input[name="windspeed"]').prop('checked', false);
246  } else {
247    $('input[name="windspeed"]').prop('checked', true);
248  }
249
250  if (gC('wf_datatable') === "off") {
251    $('input[name="datatable"]').prop('checked', false);
252  } else {
253    $('input[name="datatable"]').prop('checked', true);
254  }
255
256  if (gC('wf_winddirectionchart') === "off") {
257    $('input[name="winddirection"]').prop('checked', false);
258  } else {
259    $('input[name="winddirection"]').prop('checked', true);
260  }
261
262  if (gC('wf_temperaturechart') === "off") {
263    $('input[name="temperature"]').prop('checked', false);
264  } else {
265    $('input[name="temperature"]').prop('checked', true);
266  }
267
268  if (gC('wf_dewpointchart') === "off") {
269    $('input[name="dewpoint"]').prop('checked', false);
270  } else {
271    $('input[name="dewpoint"]').prop('checked', true);
272  }
273
274  if (gC('wf_windchillchart') === "off") {
275    $('input[name="windchill"]').prop('checked', false);
276  } else {
277    $('input[name="windchill"]').prop('checked', true);
278  }
279
280  if (gC('wf_bgtchart') === "off") {
281    $('input[name="bgt"]').prop('checked', false);
282  } else {
283    $('input[name="bgt"]').prop('checked', true);
284  }
285
286  if (gC('wf_pressurechart') === "off") {
287    $('input[name="pressure"]').prop('checked', false);
288  } else {
289    $('input[name="pressure"]').prop('checked', true);
290  }
291
292  if (gC('wf_humiditychart') === "off") {
293    $('input[name="humidity"]').prop('checked', false);
294  } else {
295    $('input[name="humidity"]').prop('checked', true);
296  }
297
298  if (gC('wf_rainfallchart') === "off") {
299    $('input[name="rainfall"]').prop('checked', false);
300  } else {
301    $('input[name="rainfall"]').prop('checked', true);
302  }
303
304  if (gC('wf_solarchart') === "off") {
305    $('input[name="solar"]').prop('checked', false);
306  } else {
307    $('input[name="solar"]').prop('checked', true);
308  }
309
310  if (gC('wf_suppress_public') === "false") {
311    $('input[name="displaypublic"]').prop('checked', true);
312  } else {
313    $('input[name="displaypublic"]').prop('checked', false);
314  }
315
316  if (gC('wf_tempunits') == "fhr") {
317    $("#settings_tempunits").val("fhr");
318  } else {
319    $("#settings_tempunits").val("celsius");
320  }
321
322  if (gC('wf_custom_scale') !== "") {
323    var pressuresettings = JSON.parse(gC('wf_custom_scale'));
324    if (pressuresettings.minpressure === undefined) pressuresettings.minpressure = "950";
325    if (pressuresettings.maxpressure === undefined) pressuresettings.maxpressure = "1040";
326    $('input[name="minpressure"]').val(pressuresettings.minpressure);
327    $('input[name="maxpressure"]').val(pressuresettings.maxpressure);
328  } else {
329    $('input[name="minpressure"]').val("950");
330    $('input[name="maxpressure"]').val("1040");
331  }
332
333  if (wf_user_name === "" | wf_user_name === "PUBLIC") {
334    console.log("Not Logged in");
335    $(".loggedin").hide();
336    //        $("#password_and_profile_change_title").hide();
337    //      $("#password_and_profile_change").hide();
338    //    $("#displayPublicContainer").hide();
339    //  $("#displayPublicContainerTitle").hide();
340
341  } else {
342    $(".loggedin").show();
343    //        $("#password_and_profile_change_title").show();
344    //      $("#password_and_profile_change").show();
345    //     $("#displayPublicContainer").show();
346    //  $("#displayPublicContainerTitle").show();
347  }
348
349  // Hide Admin only fields if the user is not an admin or superadmin
350  if (wf_user_level.toLowerCase() === "admin" | wf_user_level.toLowerCase() === "superadmin") {
351    $(".admin_only").show();
352  } else {
353    $(".admin_only").hide();
354  }
355
356  if (wf_user_level.toLowerCase() === "superadmin") {
357    $("#btn_fw").show();
358  } else {
359    $("#btn_fw").hide();
360  }
361
362  if (wf_user_level.toLowerCase() === "superadmin") {
363    $("#btn_partners").show();
364  } else {
365    $("#btn_partners").hide();
366  }
367
368  if (wf_user_level.toLowerCase() === "superadmin") {
369    $("#btn_devices").show();
370  } else {
371    $("#btn_devices").hide();
372  }
373
374  showDiv("settings_container");
375  if (window.WFConsent && typeof WFConsent.updateSettingsFunctionalNotice === "function") {
376    WFConsent.updateSettingsFunctionalNotice();
377  }
378}
379
380function setUpSettings() {
381  if (
382    window.WFConsent &&
383    typeof WFConsent.shouldBlockFunctionalWrite === "function" &&
384    WFConsent.shouldBlockFunctionalWrite()
385  ) {
386    syncWindUnitsGlobal();
387    return;
388  }
389  //Suppress public
390  var suppress = gC("wf_suppress_public");
391  if (suppress == "") {
392    sC("wf_suppress_public", "false", 90);
393    suppress = "false";
394  }
395
396  if (gC("wf_language") == "") {
397    if (window.WF && WF.i18nStorage) WF.i18nStorage.ensure();
398    else sC("wf_language", "en", 90);
399  }
400
401  if (suppress === "true") {
402    $("#suppresson").css('font-weight', 'bold');
403    $("#suppressoff").css('font-weight', 'normal');
404  } else {
405    $("#suppressoff").css('font-weight', 'bold');
406    $("#suppresson").css('font-weight', 'normal');
407  }
408  timezone = gC("wf_timezone");
409  // console.log("Timezone:" + timezone);
410
411  if (timezone !== "GMT") {
412    timezone = "LCL";
413    sC("wf_timezone", "LCL", 90);
414  }
415  // console.log("Timezone:" + timezone);
416
417  //Theme
418  theme = gC("wf_theme");
419
420  if (theme !== "greydials") {
421    theme = "classicblue";
422    sC("wf_theme", "classicblue", 90);
423  }
424
425  console.log("theme - " + theme);
426  //console.log("gC #271 - " + gC("wf_theme"));
427
428  //Wind Units
429
430  wunits = gC("wf_wunits");
431
432  if (wunits == "" || wunits == "null") {
433    wunits = "mps";
434    sC("wf_wunits", "mps", 90);
435  }
436
437  if (wunits == "mps") {
438    $("#disp_units").html("m/s");
439  } else {
440    $("#disp_units").html(wunits);
441  }
442
443  // CHECK OTHER Cookie Values
444  //sC("wf_timezone", $("#settings_timezone").val(), 90);
445
446  if (gC("wf_windspeedchart") == "") {
447    sC("wf_windspeedchart", "on", 90);
448  } else {
449    sC("wf_windspeedchart", gC("wf_windspeedchart"), 90);
450  }
451
452  if (gC("wf_winddirectionchart") == "") {
453    sC("wf_winddirectionchart", "on", 90);
454  } else {
455    sC("wf_winddirectionchart", gC("wf_winddirectionchart"), 90);
456  }
457
458  if (gC("wf_pressurechart") == "") {
459    sC("wf_pressurechart", "on", 90);
460  } else {
461    sC("wf_pressurechart", gC("wf_pressurechart"), 90);
462  }
463
464  if (gC("wf_temperaturechart") == "") {
465    sC("wf_temperaturechart", "on", 90);
466  } else {
467    sC("wf_temperaturechart", gC("wf_temperaturechart"), 90);
468  }
469
470  if (gC("wf_dewpointchart") == "") {
471    sC("wf_dewpointchart", "on", 90);
472  } else {
473    sC("wf_dewpointchart", gC("wf_dewpointchart"), 90);
474  }
475
476  if (gC("wf_windchillchart") == "") {
477    sC("wf_windchillchart", "on", 90);
478  } else {
479    sC("wf_windchillchart", gC("wf_windchillchart"), 90);
480  }
481
482  if (gC("wf_bgtchart") == "") {
483    sC("wf_bgtchart", "on", 90);
484  } else {
485    sC("wf_bgtchart", gC("wf_bgtchart"), 90);
486  }
487
488  if (gC("wf_humiditychart") == "") {
489    sC("wf_humiditychart", "on", 90);
490  } else {
491    sC("wf_humiditychart", gC("wf_humiditychart"), 90);
492  }
493
494  if (gC("wf_rainfallchart") == "") {
495    sC("wf_rainfallchart", "on", 90);
496  } else {
497    sC("wf_rainfallchart", gC("wf_rainfallchart"), 90);
498  }
499
500  if (gC("wf_solarchart") == "") {
501    sC("wf_solarchart", "on", 90);
502  } else {
503    sC("wf_solarchart", gC("wf_solarchart"), 90);
504  }
505
506  if (gC("wf_datatable") == "") {
507    sC("wf_datatable", "on", 90);
508  } else {
509    sC("wf_datatable", gC("wf_datatable"), 90);
510  }
511
512  //MPS, MPH, KPH, KTS
513  $(".sWunits").css('font-weight', 'normal')
514  $("#s" + wunits).css('font-weight', 'bold')
515}
516
517function hidePublic() {
518  sC("wf_suppress_public", "true", 60);
519  setUpSettings();
520  load_locations_list();
521  deleteMarkers(true);
522}
523
524function showPublic() {
525  sC("wf_suppress_public", "false", 60);
526  setUpSettings();
527  load_locations_list();
528  deleteMarkers(true);
529}
530
531function setUnits(unitstoset) {
532  if (!sC("wf_wunits", unitstoset, 30)) {
533    notifyIfPreferenceBlocked();
534    return;
535  }
536  setUpSettings();
537}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.