summaryrefslogtreecommitdiffstats
path: root/zalmy.es
blob: 3cffae46983c505f538c068464183efae575d91b (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import {ActivePage} from "activePage";

export class Psalm extends ActivePage
{
  constructor()
  {
    super('zalmy');
  }

  // 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.
  get cur_psalm() {
    console.log('this.cur_section = ' + this.cur_section);
    // If this.cur_section has not been initialized yet, do it
    if (!this.cur_section) {
      var storedStr = localStorage.getItem("curPsalm");
      var stored = JSON.parse(storedStr);
      if ((stored == null) || (stored < 1) || (stored > 150)) {
        this.cur_section = 1;
        localStorage.setItem("curPsalm", JSON.stringify(this.cur_section));
      }
      else {
        this.cur_section = stored;
      }
    }

    return this.cur_section;
  }

  set cur_psalm(value) {
    if (value < 1) {
      this.cur_section = 150;
    }
    else if (value > 150) {
      this.cur_section = 1;
    }
    else {
      this.cur_section = value;
    }
    localStorage.setItem("curPsalm", JSON.stringify(this.cur_section));

    // set the parameter directly to avoid call to getter.
    this.display();
  }

  // Methods

  /**
   * Display the current Psalm
   *
   * @param number Number of the psalm to be displayed (optional)
   *
   * Displays the particular Psalm
   */
  display() {
    super.display();

    let psalm_id = `Ps.${this.cur_psalm}`;
    console.log(`psalm_id = ${psalm_id}`);
    document.getElementById(psalm_id).parentElement.
      classList.add('visible');
  }

  // We have to override activePage’s next() and prev() methods to call
  // this.cur_psalm setter whcih does actual refresh of the page.
  next() {
    this.cur_psalm += 1;
  }

  prev() {
    this.cur_psalm -= 1;
  }

}

var thisPsalm = new Psalm();