diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-02-08 22:40:08 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-02-12 02:24:00 +0100 |
commit | d1353a7e24f6c9792a2e2584381f0b96c8cccb7e (patch) | |
tree | 04a14b745f94bd2609ade36059475c3dc5bfe557 /zalmy.ts | |
parent | dfc1167e2643c26d27212fe3e527ddaf65a20942 (diff) | |
download | zalmy-d1353a7e24f6c9792a2e2584381f0b96c8cccb7e.tar.gz |
Make Psalm reader working.
Mainly Psalm.display must work with cur_psalm not cur_section (to get
all goodies from the getter).
Diffstat (limited to 'zalmy.ts')
-rw-r--r-- | zalmy.ts | 53 |
1 files changed, 23 insertions, 30 deletions
@@ -1,26 +1,28 @@ /// <reference path='touchEvent.d.ts' /> import ap = require("./activePage"); -export class Psalm extends ap.ActivePage { - constructor() { +export class Psalm extends ap.ActivePage +{ + constructor() + { super(); } // cur_psalm is actually just a virtual property, which is not stored anywhere and its // accessor methods change the value of the cur_section property instead. public get cur_psalm(): number { + console.log('this.cur_section = ' + this.cur_section); // If this.cur_section has not been initialized yet, do it - if (this.cur_section === null) - { + if (this.cur_section === null) { var storedStr = localStorage.getItem("curPsalm"); + console.log('storedStr = ' + storedStr); var stored = JSON.parse(storedStr); - if ((stored === null) || (stored < 1) || (stored > 150)) - { + console.log('stored = ' + stored); + if ((stored === null) || (stored < 1) || (stored > 150)) { this.cur_section = 1; localStorage.setItem("curPsalm", JSON.stringify(this.cur_section)); } - else - { + else { this.cur_section = stored; } } @@ -29,26 +31,19 @@ export class Psalm extends ap.ActivePage { } public set cur_psalm(value: number) { - // Remove 'visible' style from the currently displayed psalm, if - // there is any - this.hide(); - - if (value < 1) - { + if (value < 1) { this.cur_section = 150; } - else if (value > 150) - { + else if (value > 150) { this.cur_section = 1; } - else - { + else { this.cur_section = value; } localStorage.setItem("curPsalm", JSON.stringify(this.cur_section)); // set the parameter directly to avoid call to getter. - this.display(this.cur_section); + this.display(); } // Methods @@ -60,20 +55,18 @@ export class Psalm extends ap.ActivePage { * * Displays the particular Psalm */ - display(disp_no: number = this.cur_psalm) { - console.log("cur_psalm = " + disp_no); + display() { // first scroll then switch to avoid blinking of the page window.scroll(0, 0); - document.getElementById("Ps." + disp_no).parentElement. - classList.add('visible'); - } - /** - * Hides the current Psalm - */ - hide() { + var visibleElems = document.getElementsByClassName("visible"); + Array.prototype.forEach.call(visibleElems, function(e) { + e.classList.remove("visible"); + }); + console.log("cur_psalm = " + this.cur_psalm); + document.getElementById("Ps." + this.cur_psalm).parentElement. - classList.remove('visible'); + classList.add('visible'); } // We have to override activePage’s next() and prev() methods to call @@ -90,4 +83,4 @@ export class Psalm extends ap.ActivePage { } -var thisPsalm = new Psalm();
\ No newline at end of file +var thisPsalm = new Psalm(); |