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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/// <reference path='touchEvent.d.ts' />
import ap = require("./activePage");
if (!Date.prototype.hasOwnProperty("toISODateString")) {
Date.prototype.toISODateString = function() {
function pad(number) {
var r = String(number);
if (r.length === 1) {
r = '0' + r;
}
return r;
}
return this.getFullYear() +
'-' + pad(this.getMonth() + 1) +
'-' + pad(this.getDate());
};
}
export class Hesla extends ap.ActivePage {
constructor() {
super();
document.getElementById("czech_nav").addEventListener("click",
(evt: TouchEvent) => {
localStorage.setItem("language", "cs");
this.lang_reload();
}, false);
document.getElementById("german_nav").addEventListener("click",
(evt: TouchEvent) => {
localStorage.setItem("language", "de");
this.lang_reload();
}, false);
}
/**
* react to the discovered distance of swipe
*
* @param distX Number distance in points in direction X
* @param distY Number distance in points in direction Y
*
* There is a preference for the horizontal swipe; if that doesn't
* happen (i.e., the distance travelled horizontally is less than
* negligible), then the vertical swipe (in either direction) means
* jump to today.
*/
handle_move(distX: number, distY: number) {
var negligible = 100;
console.log('distX = ' + distX);
console.log('distY = ' + distY);
if (distX < -negligible) {
console.log("swipe left");
this.next();
}
else if (distX > negligible) {
console.log("swipe right");
this.prev();
}
else if (Math.abs(distY) > negligible) {
console.log("jump to today!");
this.display();
}
}
// cur_watchword is actually just a virtual property, which is not stored anywhere and its
// accessor methods change the value of the cur_section property instead.
get cur_watchword(): Date {
if (this.cur_section === null) {
this.cur_section = new Date();
}
return this.cur_section;
}
set cur_watchword(value: Date) {
// Remove 'visible' style from the currently displayed psalm, if
// there is any
this.hide();
this.cur_section = value;
// set the parameter directly to avoid call to getter.
this.display(this.cur_section);
}
/**
* Display losungen for given day
*
* @param new_date String with ISO formatted date (optional)
* or Number with the relative distance of the day from the date
* currently displayed.
*
* Displays the Losungen for the given date (or today if not defined)
*/
display(date:any = this.cur_watchword) {
// if (this.cur_section !== null) {
// document.getElementById(this.cur_section.toISODateString()).style.display = 'none';
// }
console.log("cur_section = " + this.cur_section);
// document.getElementById(this.cur_section.toISODateString()).style.display = 'block';
document.getElementById(this.cur_section.toISODateString()).classList.add("visible");
}
/**
* Hides the current Losungen
*/
hide() {
document.getElementById(this.cur_watchword).classList.remove('visible');
}
shiftDate(shift: number) {
var cur_date = this.cur_watchword;
cur_date.setDate(cur_date.getDate() + shift);
this.cur_watchword = cur_date;
}
next() {
console.log("Next day!");
this.shiftDate(+1);
}
prev() {
console.log("Previous day!");
this.shiftDate(-1);
}
// Switch langauge
/**
* Handler for the switch language event
*
* Switches the displayed langauge page according to the state stored
* in the localStorage.langauge variable which contains ISO code for
* the chosen language ('de' and 'cs' currently).
*/
lang_reload() {
var new_basename = "index.html", new_url = window.location.href,
old_basename = window.location.pathname.split("/").slice(-1)[0];
console.log('old_basename = ' + old_basename);
if (localStorage.language && (localStorage.language === "de")) {
new_basename = "index_de.html";
}
console.log('new_basename = ' + new_basename);
if ((old_basename !== new_basename) || (window.location.pathname.length === 0)) {
new_url = window.location.href.replace(/(index[-\w]*\.html)?$/,
new_basename);
}
if (window.location.href !== new_url) {
window.location.assign(new_url);
}
}
}
var thisHesla = new Hesla();
thisHesla.lang_reload();
thisHesla.display();
|