summaryrefslogtreecommitdiffstats
path: root/zalmy.es
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-04-20 18:38:01 +0200
committerMatěj Cepl <mcepl@cepl.eu>2015-04-20 18:38:01 +0200
commita9ad02b3ff96f020fe7a90e2fc7b1aef15726a63 (patch)
tree0a795a7340d56e329afeb199ee4ffacd90af56db /zalmy.es
parent1e4f993958510626aaf814875e58e952548b63cd (diff)
downloadzalmy-a9ad02b3ff96f020fe7a90e2fc7b1aef15726a63.tar.gz
Switch to Babel and pure ES6.
Diffstat (limited to 'zalmy.es')
-rw-r--r--zalmy.es87
1 files changed, 87 insertions, 0 deletions
diff --git a/zalmy.es b/zalmy.es
new file mode 100644
index 0000000..aa433c1
--- /dev/null
+++ b/zalmy.es
@@ -0,0 +1,87 @@
+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");
+ console.log('storedStr = ' + storedStr);
+ var stored = JSON.parse(storedStr);
+ console.log('stored = ' + stored);
+ 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() {
+ // first scroll then switch to avoid blinking of the page
+ window.scroll(0, 0);
+
+ var visibleElems = document.getElementsByClassName("visible");
+ Array.prototype.forEach.call(visibleElems, function(e) {
+ e.classList.remove("visible");
+ });
+ console.log("cur_psalm = " + this.cur_psalm);
+
+ 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() {
+ console.log("Next!");
+ this.cur_psalm += 1;
+ }
+
+ prev() {
+ console.log("Previous!");
+ this.cur_psalm -= 1;
+ }
+
+}
+
+var thisPsalm = new Psalm();