aboutsummaryrefslogtreecommitdiffstats
path: root/hesla.js
blob: 7c64c89f125da26da7aea6356b318f49179d5a56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
if (!Date.prototype.toISODateString) {

  (function() {
    function pad(number) {
      var r = String(number);
      if ( r.length === 1 ) {
        r = '0' + r;
      }
      return r;
    }

    Date.prototype.toISODateString = function() {
      return this.getFullYear() +
    '-' + pad( this.getMonth() + 1 ) +
    '-' + pad( this.getDate() );
    };

  }());
}

const today_id = new Date().toISODateString();

// Switch langauge
function lang_reload() {
  var new_basename = "index.html";
  var new_url = "NOURL";
  if (localStorage.language && (localStorage.language === "de")) {
      new_basename = "index_de.html";
  }

  var old_basename = window.location.pathname.split("/").slice(-1);

  if ((old_basename !== new_basename) || (window.location.pathname.length === 0)) {
    new_url = window.location.href.replace(/(index[a-zA-Z-_]*\.html)?$/,
	new_basename);
  }

  if (window.location.href !== new_url) {
    window.location.assign(new_url);
  }
}

document.getElementById("czech_nav").addEventListener("click",
    function(evt) {
      localStorage.language = "cs";
      lang_reload();
    }, false);

document.getElementById("german_nav").addEventListener("click",
    function(evt) {
      localStorage.language = "de";
      lang_reload();
    }, false);

lang_reload();

var today_losungen = document.getElementById(today_id);
today_losungen.style.display = "block";