diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | .vimrc | 3 | ||||
-rw-r--r-- | Makefile | 17 | ||||
l--------- | activePage.ts | 1 | ||||
-rw-r--r-- | config.ts | 7 | ||||
-rwxr-xr-x | generate_html_cs.py | 6 | ||||
-rwxr-xr-x | generate_html_de.py | 15 | ||||
-rw-r--r-- | hesla.appcache | 7 | ||||
-rw-r--r-- | hesla.js | 194 | ||||
-rw-r--r-- | hesla.ts | 153 | ||||
l--------- | require.d.ts | 1 | ||||
l--------- | require.js | 1 | ||||
-rw-r--r-- | screen.css | 4 | ||||
-rw-r--r-- | templates/base.html | 3 | ||||
l--------- | touchEvent.d.ts | 1 |
15 files changed, 203 insertions, 214 deletions
@@ -1,3 +1,7 @@ +*~ *.pyc output.html index*.html +*.js +*.js.map +!require.js @@ -1,3 +0,0 @@ -let g:flake8_cmd="/usr/bin/python3-flake8" -let g:syntastic_python_python_exe = 'python3' -let g:syntastic_python_pylint_exe = 'python3-pylint' @@ -1,8 +1,12 @@ -#FILES=favicon.png -FILES=hesla.js icon-*.png index_de.html index.html screen.css \ - hesla.appcache hesla.webapp google9815148f4ac1407f.html +FILES=hesla.js hesla.js.map require.js config.js config.js.map \ + activePage.js activePage.js.map icon-*.png \ + index_de.html index.html screen.css hesla.appcache hesla.webapp \ + google9815148f4ac1407f.html config.ts hesla.ts activePage.ts -all: index.html index_de.html +%.js: %.ts + tsc --sourcemap -t ES5 -m amd $< + +all: index.html index_de.html config.js activePage.js hesla.js index.html: generate_html_cs.py hes14-10.xml templates/czech.html templates/base.html ./generate_html_cs.py hes14-10.xml >$@ @@ -10,15 +14,14 @@ index.html: generate_html_cs.py hes14-10.xml templates/czech.html templates/base index_de.html: generate_html_de.py hernnhut/2014/Losungen\ Free\ 2014.xml templates/german.html templates/base.html ./generate_html_de.py hernnhut/2014/Losungen\ Free\ 2014.xml >$@ - hesla-chrome.zip: zip -9vT $@ google9815148f4ac1407f.html hesla.appcache \ hesla.js icon-128.png icon-30.png icon-60.png \ index_de.html index.html manifest.json screen.css install: $(FILES) - rsync -avz --delete $(FILES) /home/matej/Dokumenty/website/luther/hesla/ + rsync -avLz --delete $(FILES) /home/matej/Dokumenty/website/luther/hesla/ websync clean: - rm -fv index*.html *~ + rm -fv index*.html *~ {activePage,config,hesla}.js *.js.map diff --git a/activePage.ts b/activePage.ts new file mode 120000 index 0000000..4f46b9c --- /dev/null +++ b/activePage.ts @@ -0,0 +1 @@ +../../../2014/projekty/zalmy/activePage.ts
\ No newline at end of file diff --git a/config.ts b/config.ts new file mode 100644 index 0000000..5a7d274 --- /dev/null +++ b/config.ts @@ -0,0 +1,7 @@ +/// <reference path="require.d.ts" /> + +import hsl = require("./hesla"); + +require([], () => { + var thisHesla = new hsl.Hesla(); +});
\ No newline at end of file diff --git a/generate_html_cs.py b/generate_html_cs.py index 93a7d7c..52e2057 100755 --- a/generate_html_cs.py +++ b/generate_html_cs.py @@ -1,4 +1,6 @@ -#!/usr/bin/python3 +#!/usr/bin/python +# -*- coding: utf-8 -*- +from __future__ import absolute_import, print_function, unicode_literals import re import codecs import lxml.etree as et @@ -215,7 +217,7 @@ def parse_file(filename): article_keys = sorted(article_dict.keys()) for key in article_keys: article_list.append(article_dict[key]) - return template.render(articles=article_list) + return template.render(articles=article_list).encode('utf8') if __name__ == "__main__": diff --git a/generate_html_de.py b/generate_html_de.py index f3c8924..ea3e9fd 100755 --- a/generate_html_de.py +++ b/generate_html_de.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals import datetime @@ -19,7 +19,12 @@ def parse_one(elem): <Sonntag>Neujahr</Sonntag> <Losungstext>Die Furcht des HERRN wird Zions Schatz sein.</Losungstext> <Losungsvers>Jesaja 33,6</Losungsvers> - <Lehrtext>Ein Mann war in Jerusalem, mit Namen Simeon; und dieser Mann war fromm und gottesfürchtig und wartete auf den Trost Israels. Er nahm Jesus auf seine Arme und lobte Gott und sprach: Herr, nun lässt du deinen Diener in Frieden fahren, wie du gesagt hast; denn meine Augen haben deinen Heiland gesehen.</Lehrtext> + <Lehrtext>Ein Mann war in Jerusalem, mit Namen Simeon; und + dieser Mann war fromm und gottesfürchtig und wartete auf den + Trost Israels. Er nahm Jesus auf seine Arme und lobte Gott und + sprach: Herr, nun lässt du deinen Diener in Frieden fahren, wie + du gesagt hast; denn meine Augen haben deinen Heiland + gesehen.</Lehrtext> <Lehrtextvers>Lukas 2,25.28-30</Lehrtextvers> </Losungen> """ @@ -37,7 +42,7 @@ def parse_one(elem): out['watchwords'] = [] for tst in (('Losungstext', 'Losungsvers'), - ('Lehrtext', 'Lehrtextvers')): + ('Lehrtext', 'Lehrtextvers')): wword = { 'text': '' } @@ -57,13 +62,13 @@ def parse_file(filename): for los in tree.getiterator("Losungen"): article_list.append(parse_one(los)) - return template.render(articles=article_list) + return template.render(articles=article_list).encode('utf8') if __name__ == "__main__": locale.setlocale(locale.LC_ALL, '') loc = locale.getlocale() - locale.setlocale(locale.LC_ALL, 'de_DE.utf8') + locale.setlocale(locale.LC_ALL, ('de_DE', 'utf8')) articles = parse_file(sys.argv[1]) locale.setlocale(locale.LC_ALL, loc) diff --git a/hesla.appcache b/hesla.appcache index 6cfee1d..e3387d4 100644 --- a/hesla.appcache +++ b/hesla.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# v59 - 2014-10-25 +# v60 - 2014-11-14 hesla.js icon-128.png icon-30.png @@ -7,3 +7,8 @@ icon-60.png index.html index_de.html screen.css +activePage.js +config.js +hesla.js +hesla.webapp +require.js diff --git a/hesla.js b/hesla.js deleted file mode 100644 index e9e001d..0000000 --- a/hesla.js +++ /dev/null @@ -1,194 +0,0 @@ -if (!Date.prototype.toISODateString) { - - (function() { - "use strict"; - - function pad(number) { - var r = String(number); - if ( r.length === 1 ) { - r = '0' + r; - } - return r; - } - - Date.prototype.toISODateString = function() { - return this.getFullYear() + - '-' + pad( this.getMonth() + 1 ) + - '-' + pad( this.getDate() ); - }; - - }()); -} - -(function () { - "use strict"; - - function Page() { - var that = this; - this.cur_date = null; - this.swipe_pos_x = 0; - this.swipe_pos_y = 0; - - document.getElementById("czech_nav").addEventListener("click", - function() { - localStorage.language = "cs"; - that.lang_reload(); - }, false); - - document.getElementById("german_nav").addEventListener("click", - function() { - localStorage.language = "de"; - that.lang_reload(); - }, false); - - // Swipe event handlers - document.body.addEventListener("dblclick", - function() { - console.log("dblclick"); - that.display(); - }, false); - - document.body.addEventListener("mousedown", - function(evt) { - that.swipe_pos_x = evt.screenX; - that.swipe_pos_y = evt.screenY; - console.log("mousedown; pos = " + that.swipe_pos_x + - " / " + that.swipe_pos_y); - }, false); - - document.body.addEventListener("mouseup", - function(evt) { - console.log("mouseup; end_pos = " + evt.screenX + - " / " + evt.screenY); - that.handle_move(that.swipe_pos_x - evt.screenX, - that.swipe_pos_y - evt.screenY); - }, false); - - document.body.addEventListener("touchstart", - function(evt) { - that.swipe_pos_x = evt.changedTouches[0].screenX; - that.swipe_pos_y = evt.changedTouches[0].screenY; - console.log("touchstart; pos = " + that.swipe_pos_x + - " / " + that.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 - that.handle_move(end_pos.screenX - that.swipe_pos_x, - end_pos.screenY - that.swipe_pos_y); - }, false); - - document.body.addEventListener("touchcancel", - function() { - console.log("touchcancel"); - that.swipe_pos_x = 0; - that.swipe_pos_y = 0; - }, false); - - } - - /** - * 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. - */ - Page.prototype.handle_move = function handle_move(distX, distY) { - var negligible = 50; - - if (distX < -negligible) { - console.log("swipe left"); - this.next_day(); - } - else if (distX > negligible) { - console.log("swipe right"); - this.prev_day(); - } - else if (Math.abs(distY) > negligible) { - console.log("jump to today!"); - this.display(); - } - }; - - /** - * Display losungen for given day - * - * @param new_date String with ISO formatted date (optional) - * or Number with the relative distance of the day from the date - * currently displayed. - * - * Displays the Losungen for the given date (or today if not defined) - */ - Page.prototype.display = function display(new_date) { - if (this.cur_date !== null) { - document.getElementById(this.cur_date.toISODateString()).style.display = 'none'; - } - - console.log("new_date = " + new_date + ", cur_date = " + this.cur_date); - if (new_date === undefined) { - this.cur_date = new Date(); - } - else if (typeof new_date === 'number') { - if (this.cur_date) { - this.cur_date.setDate(this.cur_date.getDate() + new_date); - } - } - else { - this.cur_date = new Date(new_date); - } - - console.log("cur_date = " + this.cur_date); - document.getElementById(this.cur_date.toISODateString()).style.display = 'block'; - }; - - Page.prototype.next_day = function next_day() { - console.log("Next day!"); - this.display(+1); - }; - - Page.prototype.prev_day = function prev_day() { - console.log("Previous day!"); - this.display(-1); - }; - - // Switch langauge - /** - * Handler for the switch language event - * - * Switches the displayed langauge page according to the state stored - * in the localStorage.langauge variable which contains ISO code for - * the chosen language ('de' and 'cs' currently). - */ - Page.prototype.lang_reload = function lang_reload() { - var new_basename = "index.html", new_url = "NOURL", - old_basename = window.location.pathname.split("/").slice(-1); - - if (localStorage.language && (localStorage.language === "de")) { - new_basename = "index_de.html"; - } - - if ((old_basename !== new_basename) || (window.location.pathname.length === 0)) { - new_url = window.location.href.replace(/(index[-\w]*\.html)?$/, - new_basename); - } - - if (window.location.href !== new_url) { - window.location.assign(new_url); - } - }; - - var thisPage = new Page(); - thisPage.lang_reload(); - thisPage.display(); - -}()); diff --git a/hesla.ts b/hesla.ts new file mode 100644 index 0000000..2051fea --- /dev/null +++ b/hesla.ts @@ -0,0 +1,153 @@ +/// <reference path='touchEvent.d.ts' /> +import ap = require("./activePage"); + +if (!Date.prototype.hasOwnProperty("toISODateString")) { + Date.prototype.toISODateString = function() { + function pad(number) { + var r = String(number); + if (r.length === 1) { + r = '0' + r; + } + return r; + } + + return this.getFullYear() + + '-' + pad(this.getMonth() + 1) + + '-' + pad(this.getDate()); + }; +} + +export class Hesla extends ap.ActivePage { + constructor() { + super(); + document.getElementById("czech_nav").addEventListener("click", + (evt: TouchEvent) => { + localStorage.setItem("language", "cs"); + this.lang_reload(); + }, false); + + document.getElementById("german_nav").addEventListener("click", + (evt: TouchEvent) => { + localStorage.setItem("language", "de"); + this.lang_reload(); + }, false); + } + + /** + * 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(); + } + else if (Math.abs(distY) > negligible) { + console.log("jump to today!"); + this.display(); + } + } + + // cur_watchword 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_watchword(): Date { + if (this.cur_section === null) { + this.cur_section = new Date(); + } + + return this.cur_section; + } + + set cur_watchword(value: Date) { + // Remove 'visible' style from the currently displayed psalm, if + // there is any + this.hide(); + + this.cur_section = value; + + // set the parameter directly to avoid call to getter. + this.display(this.cur_section); + } + + /** + * Display losungen for given day + * + * @param new_date String with ISO formatted date (optional) + * or Number with the relative distance of the day from the date + * currently displayed. + * + * Displays the Losungen for the given date (or today if not defined) + */ + display(date:any = this.cur_watchword) { + // if (this.cur_section !== null) { + // document.getElementById(this.cur_section.toISODateString()).style.display = 'none'; + // } + + console.log("cur_section = " + this.cur_section); + // document.getElementById(this.cur_section.toISODateString()).style.display = 'block'; + document.getElementById(this.cur_section.toISODateString()).classList.add("visible"); + } + + shiftDate(shift: number) { + var cur_date = this.cur_watchword; + cur_date.setDate(cur_date.getDate() + shift); + this.cur_watchword = cur_date; + } + + next() { + console.log("Next day!"); + this.shiftDate(+1); + } + + prev() { + console.log("Previous day!"); + this.shiftDate(-1); + } + + // Switch langauge + /** + * Handler for the switch language event + * + * Switches the displayed langauge page according to the state stored + * in the localStorage.langauge variable which contains ISO code for + * the chosen language ('de' and 'cs' currently). + */ + lang_reload() { + var new_basename = "index.html", new_url = window.location.href, + old_basename = window.location.pathname.split("/").slice(-1)[0]; + console.log('old_basename = ' + old_basename); + + if (localStorage.language && (localStorage.language === "de")) { + new_basename = "index_de.html"; + } + + console.log('new_basename = ' + new_basename); + if ((old_basename !== new_basename) || (window.location.pathname.length === 0)) { + new_url = window.location.href.replace(/(index[-\w]*\.html)?$/, + new_basename); + } + + if (window.location.href !== new_url) { + window.location.assign(new_url); + } + } +} + +var thisHesla = new Hesla(); +thisHesla.lang_reload(); +thisHesla.display(); diff --git a/require.d.ts b/require.d.ts new file mode 120000 index 0000000..198a2c6 --- /dev/null +++ b/require.d.ts @@ -0,0 +1 @@ +../../../2014/projekty/zalmy/require.d.ts
\ No newline at end of file diff --git a/require.js b/require.js new file mode 120000 index 0000000..42d8353 --- /dev/null +++ b/require.js @@ -0,0 +1 @@ +../../../2014/projekty/zalmy/require.js
\ No newline at end of file @@ -16,6 +16,10 @@ article { text-align: right; } +.visible { + display: block; +} + ul.readings { display: block; clear: both; diff --git a/templates/base.html b/templates/base.html index 768bb61..0771304 100644 --- a/templates/base.html +++ b/templates/base.html @@ -18,8 +18,7 @@ <meta content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" name="viewport"/> <link href="screen.css" type="text/css" rel="stylesheet"/> <title>{{ title }}</title> - <script src="hesla.js" type="text/javascript" defer="defer"> -</script> + <script data-main="config" type="text/javascript" src="require.js"></script> </head> <body> <noscript>{{ noscript_message }}</noscript> diff --git a/touchEvent.d.ts b/touchEvent.d.ts new file mode 120000 index 0000000..965374b --- /dev/null +++ b/touchEvent.d.ts @@ -0,0 +1 @@ +../../../2014/projekty/zalmy/touchEvent.d.ts
\ No newline at end of file |