summaryrefslogtreecommitdiffstats
path: root/zalmy.js
diff options
context:
space:
mode:
Diffstat (limited to 'zalmy.js')
-rw-r--r--zalmy.js214
1 files changed, 71 insertions, 143 deletions
diff --git a/zalmy.js b/zalmy.js
index 7010267..dac8f32 100644
--- a/zalmy.js
+++ b/zalmy.js
@@ -1,150 +1,78 @@
-/// <reference path='touchEvent.d.ts' />
-var Psalm = (function () {
- function Psalm() {
- var _this = this;
- this._cur_psalm = null;
- this.swipe_pos_x = 0;
- this.swipe_pos_y = 0;
- // Swipe event handlers
- document.body.addEventListener("dblclick", function () {
- console.log("dblclick");
- _this.display();
- }, false);
-
- document.body.addEventListener("mousedown", function (evt) {
- _this.swipe_pos_x = evt.screenX;
- _this.swipe_pos_y = evt.screenY;
- console.log("mousedown; pos = " + _this.swipe_pos_x + " / " + _this.swipe_pos_y);
- }, false);
-
- document.body.addEventListener("mouseup", function (evt) {
- console.log("mouseup; end_pos = " + evt.screenX + " / " + evt.screenY);
- _this.handle_move(_this.swipe_pos_x - evt.screenX, _this.swipe_pos_y - evt.screenY);
- }, false);
-
- document.body.addEventListener("touchstart", function (evt) {
- _this.swipe_pos_x = evt.changedTouches[0].screenX;
- _this.swipe_pos_y = evt.changedTouches[0].screenY;
- console.log("touchstart; pos = " + _this.swipe_pos_x + " / " + _this.swipe_pos_y);
- }, false);
-
- document.body.addEventListener("touchend", function (evt) {
- var end_pos = evt.changedTouches[evt.changedTouches.length - 1];
- console.log("touchend; end_pos = " + end_pos.screenX + " / " + end_pos.screenY);
-
- // We want't opposite direction to Mouse gestures here
- // so the difference should be opposite
- _this.handle_move(end_pos.screenX - _this.swipe_pos_x, end_pos.screenY - _this.swipe_pos_y);
- }, false);
-
- document.body.addEventListener("touchcancel", function () {
- console.log("touchcancel");
- _this.swipe_pos_x = 0;
- _this.swipe_pos_y = 0;
- }, false);
-
- applicationCache.addEventListener("updateready", function () {
- location.reload();
- });
+var __extends = this.__extends || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+define(["require", "exports", "activePage"], function(require, exports, ap) {
+ var Psalm = (function (_super) {
+ __extends(Psalm, _super);
+ function Psalm() {
+ _super.call(this);
+ }
+ Object.defineProperty(Psalm.prototype, "cur_psalm", {
+ get: function () {
+ // If this.cur_section has not been initialized yet, do it
+ if (this.cur_section === null) {
+ 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;
+ }
+ }
- this.display();
- }
- Object.defineProperty(Psalm.prototype, "cur_psalm", {
- get: function () {
- // If this._cur_psalm has not been initialized yet, do it
- if (this._cur_psalm === null) {
- var storedStr = localStorage.getItem("curPsalm");
- var stored = JSON.parse(storedStr);
- if ((stored === null) || (stored < 1) || (stored > 150)) {
- this._cur_psalm = 1;
- localStorage.setItem("curPsalm", JSON.stringify(this._cur_psalm));
+ return this.cur_section;
+ },
+ set: function (value) {
+ // Remove 'visible' style from the currently displayed psalm, if
+ // there is any
+ this.hide();
+
+ if (value < 1) {
+ this.cur_section = 150;
+ } else if (value > 150) {
+ this.cur_section = 1;
} else {
- this._cur_psalm = stored;
+ this.cur_section = value;
}
- }
+ localStorage.setItem("curPsalm", JSON.stringify(this.cur_section));
- return this._cur_psalm;
- },
- set: function (value) {
- // Remove 'visible' style from the currently displayed psalm, if
- // there is any
- this.hide();
-
- if (value < 1) {
- this._cur_psalm = 150;
- } else if (value > 150) {
- this._cur_psalm = 1;
- } else {
- this._cur_psalm = value;
- }
- localStorage.setItem("curPsalm", JSON.stringify(this._cur_psalm));
-
- // set the parameter directly to avoid call to getter.
- this.display(this._cur_psalm);
- },
- enumerable: true,
- configurable: true
- });
-
-
- // Methods
- /**
- * react to the discovered distance of swipe
- *
- * @param distX Number distance in points in direction X
- * @param distY Number distance in points in direction Y
- *
- * There is a preference for the horizontal swipe; if that doesn't
- * happen (i.e., the distance travelled horizontally is less than
- * negligible), then the vertical swipe (in either direction) means
- * jump to today.
- */
- Psalm.prototype.handle_move = function (distX, distY) {
- var negligible = 100;
- console.log('distX = ' + distX);
- console.log('distY = ' + distY);
-
- if (distX < -negligible) {
- console.log("swipe left");
- this.next_psalm();
- } else if (distX > negligible) {
- console.log("swipe right");
- this.prev_psalm();
- }
- };
-
- /**
- * Display the current Psalm
- *
- * @param number Number of the psalm to be displayed (optional)
- *
- * Displays the particular Psalm
- */
- Psalm.prototype.display = function (disp_no) {
- if (typeof disp_no === "undefined") { disp_no = this.cur_psalm; }
- console.log("cur_psalm = " + disp_no);
- document.getElementById("Ps." + disp_no).parentElement.classList.add('visible');
- window.scroll(0, 0);
- };
-
- /**
- * Hides the current Psalm
- */
- Psalm.prototype.hide = function () {
- document.getElementById("Ps." + this.cur_psalm).parentElement.classList.remove('visible');
- };
-
- Psalm.prototype.next_psalm = function () {
- console.log("Next day!");
- this.cur_psalm += 1;
- };
+ // set the parameter directly to avoid call to getter.
+ this.display(this.cur_section);
+ },
+ enumerable: true,
+ configurable: true
+ });
- Psalm.prototype.prev_psalm = function () {
- console.log("Previous day!");
- this.cur_psalm -= 1;
- };
- return Psalm;
-})();
-var thisPsalm = new Psalm();
+ // Methods
+ /**
+ * Display the current Psalm
+ *
+ * @param number Number of the psalm to be displayed (optional)
+ *
+ * Displays the particular Psalm
+ */
+ Psalm.prototype.display = function (disp_no) {
+ if (typeof disp_no === "undefined") { disp_no = this.cur_psalm; }
+ console.log("cur_psalm = " + disp_no);
+ document.getElementById("Ps." + disp_no).parentElement.classList.add('visible');
+ window.scroll(0, 0);
+ };
+
+ /**
+ * Hides the current Psalm
+ */
+ Psalm.prototype.hide = function () {
+ document.getElementById("Ps." + this.cur_psalm).parentElement.classList.remove('visible');
+ };
+ return Psalm;
+ })(ap.ActivePage);
+ exports.Psalm = Psalm;
+
+ var thisPsalm = new Psalm();
+});
//# sourceMappingURL=zalmy.js.map