From 0b90a830168ae70c99a5f2bdd965c9777b5c9804 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 28 Feb 2014 13:18:00 +0100 Subject: Rewrite to modular style (and use require.js modules). --- Makefile | 12 +- activePage.js | 98 +++ activePage.js.map | 1 + activePage.ts | 109 +++ config.js | 7 + config.js.map | 1 + config.ts | 7 + index.html | 2 +- require.d.ts | 330 +++++++++ require.js | 2068 +++++++++++++++++++++++++++++++++++++++++++++++++++++ zalmy.appcache | 7 +- zalmy.js | 214 ++---- zalmy.ts | 120 +--- 13 files changed, 2720 insertions(+), 256 deletions(-) create mode 100644 activePage.js create mode 100644 activePage.js.map create mode 100644 activePage.ts create mode 100644 config.js create mode 100644 config.js.map create mode 100644 config.ts create mode 100644 require.d.ts create mode 100644 require.js diff --git a/Makefile b/Makefile index 3b3f54c..2d2bcc7 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ #FILES=favicon.png -FILES=zalmy.js zalmy.js.map style index.html zalmy.appcache zalmy.webapp +FILES=zalmy.js zalmy.js.map style index.html zalmy.appcache zalmy.webapp \ + require.js config.js config.js.map activePage.js activePage.js.map \ + config.ts activePage.ts zalmy.ts -all: zalmy.js +all: config.js activePage.js zalmy.js -zalmy.js: zalmy.ts - tsc --sourcemap -t ES5 --out $@ $< +%.js: %.ts + tsc --sourcemap -t ES5 -m amd $< install: $(FILES) rsync -avz --delete $(FILES) /home/matej/Dokumenty/website/luther/zalmy/ websync clean: - rm -fv zalmy.js* *~ + rm -fv {zalmy,activePage,config}.js* *~ diff --git a/activePage.js b/activePage.js new file mode 100644 index 0000000..bbc3afe --- /dev/null +++ b/activePage.js @@ -0,0 +1,98 @@ +/// +define(["require", "exports"], function(require, exports) { + var ActivePage = (function () { + function ActivePage() { + var _this = this; + this.cur_section = 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(); + }); + + this.display(); + } + ActivePage.prototype.display = function (disp_no) { + if (typeof disp_no === "undefined") { disp_no = 0; } + }; + + ActivePage.prototype.hide = function () { + }; + + /** + * 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. + */ + ActivePage.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(); + } else if (distX > negligible) { + console.log("swipe right"); + this.prev(); + } + }; + + ActivePage.prototype.next = function () { + console.log("Next!"); + this.cur_section += 1; + }; + + ActivePage.prototype.prev = function () { + console.log("Previous!"); + this.cur_section -= 1; + }; + return ActivePage; + })(); + exports.ActivePage = ActivePage; +}); +//# sourceMappingURL=activePage.js.map diff --git a/activePage.js.map b/activePage.js.map new file mode 100644 index 0000000..edd3f58 --- /dev/null +++ b/activePage.js.map @@ -0,0 +1 @@ +{"version":3,"file":"activePage.js","sourceRoot":"","sources":["activePage.ts"],"names":["ActivePage","ActivePage.constructor","ActivePage.display","ActivePage.hide","ActivePage.handle_move","ActivePage.next","ActivePage.prev"],"mappings":"AAAA,wCAAwC;AAAxC;IAEA;QAKEA;YAAAC,iBAuDCA;YA3DDA,KAAOA,WAAWA,GAAGA,IAAIA,CAACA;YAC1BA,KAAQA,WAAWA,GAAGA,CAACA,CAACA;YACxBA,KAAQA,WAAWA,GAAGA,CAACA,CAACA;YAGtBA,uBAAuBA;YACvBA,QAAQA,CAACA,IAAIA,CAACA,gBAAgBA,CAACA,UAAUA,EACvCA;gBACEA,OAAOA,CAACA,GAAGA,CAACA,UAAUA,CAACA;gBACvBA,KAAIA,CAACA,OAAOA,CAACA,CAACA;YAChBA,CAACA,EAAEA,KAAKA,CAACA;;YAEXA,QAAQA,CAACA,IAAIA,CAACA,gBAAgBA,CAACA,WAAWA,EACxCA,UAACA,GAAeA;gBACdA,KAAIA,CAACA,WAAWA,GAAGA,GAAGA,CAACA,OAAOA;gBAC9BA,KAAIA,CAACA,WAAWA,GAAGA,GAAGA,CAACA,OAAOA;gBAC9BA,OAAOA,CAACA,GAAGA,CAACA,mBAAmBA,GAAGA,KAAIA,CAACA,WAAWA,GAChDA,KAAKA,GAAGA,KAAIA,CAACA,WAAWA,CAACA;YAC7BA,CAACA,EAAEA,KAAKA,CAACA;;YAEXA,QAAQA,CAACA,IAAIA,CAACA,gBAAgBA,CAACA,SAASA,EACtCA,UAACA,GAAeA;gBACdA,OAAOA,CAACA,GAAGA,CAACA,qBAAqBA,GAAGA,GAAGA,CAACA,OAAOA,GAC7CA,KAAKA,GAAGA,GAAGA,CAACA,OAAOA,CAACA;gBACtBA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A,CAACA,WAAWA,GAAGA,CAACA;gBACpBA,KAAIA,CAACA,WAAWA,GAAGA,CAACA;YACtBA,CAACA,EAAEA,KAAKA,CAACA;;YAEXA,gBAAgBA,CAACA,gBAAgBA,CAACA,aAAaA,EAC7CA;gBAAQA,QAAQA,CAACA,MAAMA,CAACA,CAACA;YAAEA,CAACA,CAC3BA;;YAEHA,IAAIA,CAACA,OAAOA,CAACA,CAACA;QAChBA,CAACA;QAEDD,+BAAAA,UAAQA,OAAmBA;YAAnBE,sCAAAA,OAAOA,GAAWA,CAACA;AAAAA,QAC3BA,CAACA;;QAEDF,4BAAAA;QACAG,CAACA;;QAaDH;;;;;;;;;;UADGA;2CACHA,UAAYA,KAAaA,EAAEA,KAAaA;YACtCI,IAAIA,UAAUA,GAAGA,GAAGA;YACpBA,OAAOA,CAACA,GAAGA,CAACA,UAAUA,GAAGA,KAAKA,CAACA;YAC/BA,OAAOA,CAACA,GAAGA,CAACA,UAAUA,GAAGA,KAAKA,CAACA;;YAE/BA,IAAIA,KAAKA,GAAGA,CAACA,UAAUA,CACvBA;gBACEA,OAAOA,CAACA,GAAGA,CAACA,YAAYA,CAACA;gBACzBA,IAAIA,CAACA,IAAIA,CAACA,CAACA;aACZA,MACIA,IAAIA,KAAKA,GAAGA,UAAUA,CAC3BA;gBACEA,OAAOA,CAACA,GAAGA,CAACA,aAAaA,CAACA;gBAC1BA,IAAIA,CAACA,IAAIA,CAACA,CAACA;aACZA;QACHA,CAACA;;QAEDJ,4BAAAA;YACEK,OAAOA,CAACA,GAAGA,CAACA,OAAOA,CAACA;YACpBA,IAAIA,CAACA,WAAWA,IAAIA,CAACA;QACvBA,CAACA;;QAEDL,4BAAAA;YACEM,OAAOA,CAACA,GAAGA,CAACA,WAAWA,CAACA;YACxBA,IAAIA,CAACA,WAAWA,IAAIA,CAACA;QACvBA,CAACA;QAEHN,kBAACA;IAADA,CAACA,IAAA;IA1GD,gCA0GC;GAAA"} \ No newline at end of file diff --git a/activePage.ts b/activePage.ts new file mode 100644 index 0000000..d5c5650 --- /dev/null +++ b/activePage.ts @@ -0,0 +1,109 @@ +/// + +export class ActivePage { + public cur_section = null; + private swipe_pos_x = 0; + private swipe_pos_y = 0; + + constructor() { + // Swipe event handlers + document.body.addEventListener("dblclick", + () => { + console.log("dblclick"); + this.display(); + }, false); + + document.body.addEventListener("mousedown", + (evt: MouseEvent) => { + 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", + (evt: MouseEvent) => { + 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", + (evt: TouchEvent) => { + 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", + (evt: TouchEvent) => { + 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", + () => { + console.log("touchcancel"); + this.swipe_pos_x = 0; + this.swipe_pos_y = 0; + }, false); + + applicationCache.addEventListener("updateready", + () => { location.reload(); } + ); + + this.display(); + } + + display(disp_no: number = 0) { + } + + hide() { + } + + /** + * 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. + */ + handle_move(distX: number, distY: number) { + var negligible = 100; + console.log('distX = ' + distX); + console.log('distY = ' + distY); + + if (distX < -negligible) + { + console.log("swipe left"); + this.next(); + } + else if (distX > negligible) + { + console.log("swipe right"); + this.prev(); + } + } + + next() { + console.log("Next!"); + this.cur_section += 1; + } + + prev() { + console.log("Previous!"); + this.cur_section -= 1; + } + +} \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..80134d7 --- /dev/null +++ b/config.js @@ -0,0 +1,7 @@ +/// +define(["require", "exports", "zalmy"], function(require, exports, zl) { + require([], function () { + var thisPsalm = new zl.Psalm(); + }); +}); +//# sourceMappingURL=config.js.map diff --git a/config.js.map b/config.js.map new file mode 100644 index 0000000..1651d70 --- /dev/null +++ b/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAArC;IAIA,OAAO,CAAC,EAAE,EAAE;QACR,IAAI,SAAS,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;GAAC"} \ No newline at end of file diff --git a/config.ts b/config.ts new file mode 100644 index 0000000..b0de287 --- /dev/null +++ b/config.ts @@ -0,0 +1,7 @@ +/// + +import zl = require("zalmy"); + +require([], () => { + var thisPsalm = new zl.Psalm(); +}); \ No newline at end of file diff --git a/index.html b/index.html index d34f555..6ecf03f 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ -