aboutsummaryrefslogtreecommitdiffstats
path: root/hesla.es
diff options
context:
space:
mode:
Diffstat (limited to 'hesla.es')
-rw-r--r--hesla.es44
1 files changed, 27 insertions, 17 deletions
diff --git a/hesla.es b/hesla.es
index 4952662..8f94bbf 100644
--- a/hesla.es
+++ b/hesla.es
@@ -2,10 +2,13 @@ import {ActivePage} from "activePage";
if (!Date.prototype.toISODateString) {
(function() {
+ function pad(n) {
+ return n < 10 ? '0' + n : n;
+ }
Date.prototype.toISODateString = function() {
- return this.toISOString().split('T')[0]
+ return this.getFullYear() + '-' + pad(this.getMonth() + 1) +
+ '-' + pad(this.getDate());
};
-
}());
}
@@ -13,16 +16,28 @@ export class Hesla extends ActivePage {
constructor() {
super();
document.getElementById("czech_nav").addEventListener("click",
- (evt: TouchEvent) => {
+ (evt) => {
localStorage.setItem("language", "cs");
this.lang_reload();
}, false);
document.getElementById("german_nav").addEventListener("click",
- (evt: TouchEvent) => {
+ (evt) => {
localStorage.setItem("language", "de");
this.lang_reload();
}, false);
+
+ // requires IE 10, Opera 12.10, Safari 7,
+ // FIXME Android browser requires 4.4 and has only
+ // webkitHidden and the event is webkitvisibilitychange
+ if (typeof document.hidden !== "undefined") {
+ document.addEventListener("visibilitychange",
+ (evt) => {
+ if (! document.hidden) {
+ this.today();
+ }
+ }, false);
+ }
}
/**
@@ -50,9 +65,7 @@ export class Hesla extends ActivePage {
this.prev();
}
else if (Math.abs(distY) > negligible) {
- console.log("jump to today!");
- this.cur_watchword = new Date();
- this.display();
+ this.today();
}
}
@@ -81,25 +94,22 @@ export class Hesla extends ActivePage {
/**
* 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() {
- // first scroll then switch to avoid blinking of the page
- window.scroll(0, 0);
+ super.display();
- var visibleElems = document.getElementsByClassName("visible");
- Array.prototype.forEach.call(visibleElems, function(e) {
- e.classList.remove("visible");
- });
console.log("cur_watchword = " + this.cur_watchword);
document.getElementById(this.cur_watchword.toISODateString()).
classList.add("visible");
}
+ today() {
+ console.log("jump to today!");
+ this.cur_watchword = new Date();
+ this.display();
+ }
+
shiftDate(shift) {
var cur_date = this.cur_watchword;
cur_date.setDate(cur_date.getDate() + shift);