diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2014-12-13 22:05:27 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2014-12-13 22:07:16 +0100 |
commit | 694097355ed942351ed8763825fb23d3f3c84499 (patch) | |
tree | 17b2b8224e91b38938dfefccf1c2374fa5a9d541 /hesla.ts | |
parent | a549540ed004f792b972713c478d882a1052e6e0 (diff) | |
download | hesla-694097355ed942351ed8763825fb23d3f3c84499.tar.gz |
More cleanup of hesla.ts, but still buggy.
We currently don’t hide the old Losungen, so they tend to cumulate.
Diffstat (limited to 'hesla.ts')
-rw-r--r-- | hesla.ts | 56 |
1 files changed, 27 insertions, 29 deletions
@@ -1,22 +1,6 @@ /// <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(); @@ -33,6 +17,22 @@ export class Hesla extends ap.ActivePage { }, false); } + toISODateString(ind: Date): string { + function pad(number) { + var r = String(number); + if (r.length === 1) + { + r = '0' + r; + } + return r; + } + + return ind.getFullYear() + + '-' + pad(ind.getMonth() + 1) + + '-' + pad(ind.getDate()); + } + + /** * react to the discovered distance of swipe * @@ -59,6 +59,7 @@ export class Hesla extends ap.ActivePage { } else if (Math.abs(distY) > negligible) { console.log("jump to today!"); + this.cur_watchword = new Date(); this.display(); } } @@ -76,12 +77,12 @@ export class Hesla extends ap.ActivePage { 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); + console.log('Displaying ' + this.cur_section); + this.display(); } /** @@ -93,17 +94,14 @@ export class Hesla extends ap.ActivePage { * * Displays the Losungen for the given date (or today if not defined) */ - display(date:any = this.cur_watchword) { - - console.log("cur_section = " + this.cur_section); - document.getElementById(this.cur_section.toISODateString()).classList.add("visible"); - } - - /** - * Hides the current Losungen - */ - hide() { - document.getElementById(this.cur_watchword.toISODateString()).classList.remove('visible'); + 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.toISODateString(this.cur_watchword)). + classList.add("visible"); } shiftDate(shift: number) { |