diff options
-rw-r--r-- | .babelrc | 20 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | favicon.ico | bin | 0 -> 9662 bytes | |||
-rw-r--r-- | hesla.appcache | 16 | ||||
-rw-r--r-- | hesla.es | 44 | ||||
-rw-r--r-- | package.json | 40 | ||||
-rw-r--r-- | sworker.js | 53 | ||||
-rw-r--r-- | templates/base.html | 11 |
9 files changed, 156 insertions, 37 deletions
diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..414ede1 --- /dev/null +++ b/.babelrc @@ -0,0 +1,20 @@ +{ + "plugins": [ + "transform-es2015-block-scoped-functions", + "transform-es2015-block-scoping", + "transform-es2015-classes", + "transform-es2015-computed-properties", + "transform-es2015-destructuring", + "transform-es2015-function-name", + "transform-es2015-literals", + "transform-es2015-object-super", + "transform-es2015-parameters", + "transform-es2015-shorthand-properties", + "transform-es2015-spread", + "transform-es2015-sticky-regex", + "transform-es2015-template-literals", + "transform-es2015-typeof-symbol", + "transform-es2015-unicode-regex", + "transform-es2015-modules-amd" + ] +} @@ -5,3 +5,5 @@ index*.html *.js *.js.map !require.js +!sworker.js +node_modules/ @@ -1,10 +1,11 @@ +BABEL=node node_modules/babel-cli/bin/babel.js 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 \ + activePage.js activePage.js.map icon-*.png sworker.js \ + index_de.html index.html screen.css hesla.webapp favicon.ico \ google9815148f4ac1407f.html config.es hesla.es activePage.es %.js: %.es - babel --source-maps true -t ES5 -m amdStrict -o $@ $< + $(BABEL) --source-maps true -o $@ $< all: index.html index_de.html config.js activePage.js hesla.js diff --git a/favicon.ico b/favicon.ico Binary files differnew file mode 100644 index 0000000..0f20c3c --- /dev/null +++ b/favicon.ico diff --git a/hesla.appcache b/hesla.appcache deleted file mode 100644 index cd1b94c..0000000 --- a/hesla.appcache +++ /dev/null @@ -1,16 +0,0 @@ -CACHE MANIFEST -# v71 - 2015-09-22 -activePage.js -activePage.js.map -config.js -config.js.map -hesla.js -hesla.js.map -hesla.webapp -icon-128.png -icon-30.png -icon-60.png -index_de.html -index.html -require.js -screen.css @@ -2,10 +2,13 @@ import {ActivePage} from "activePage"; if (!Date.prototype.toISODateString) { (function() { + function pad(n) { + return n < 10 ? '0' + n : n; + } Date.prototype.toISODateString = function() { - return this.toISOString().split('T')[0] + return this.getFullYear() + '-' + pad(this.getMonth() + 1) + + '-' + pad(this.getDate()); }; - }()); } @@ -13,16 +16,28 @@ export class Hesla extends ActivePage { constructor() { super(); document.getElementById("czech_nav").addEventListener("click", - (evt: TouchEvent) => { + (evt) => { localStorage.setItem("language", "cs"); this.lang_reload(); }, false); document.getElementById("german_nav").addEventListener("click", - (evt: TouchEvent) => { + (evt) => { localStorage.setItem("language", "de"); this.lang_reload(); }, false); + + // requires IE 10, Opera 12.10, Safari 7, + // FIXME Android browser requires 4.4 and has only + // webkitHidden and the event is webkitvisibilitychange + if (typeof document.hidden !== "undefined") { + document.addEventListener("visibilitychange", + (evt) => { + if (! document.hidden) { + this.today(); + } + }, false); + } } /** @@ -50,9 +65,7 @@ export class Hesla extends ActivePage { this.prev(); } else if (Math.abs(distY) > negligible) { - console.log("jump to today!"); - this.cur_watchword = new Date(); - this.display(); + this.today(); } } @@ -81,25 +94,22 @@ export class Hesla extends ActivePage { /** * 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() { - // first scroll then switch to avoid blinking of the page - window.scroll(0, 0); + super.display(); - var visibleElems = document.getElementsByClassName("visible"); - Array.prototype.forEach.call(visibleElems, function(e) { - e.classList.remove("visible"); - }); console.log("cur_watchword = " + this.cur_watchword); document.getElementById(this.cur_watchword.toISODateString()). classList.add("visible"); } + today() { + console.log("jump to today!"); + this.cur_watchword = new Date(); + this.display(); + } + shiftDate(shift) { var cur_date = this.cur_watchword; cur_date.setDate(cur_date.getDate() + shift); diff --git a/package.json b/package.json new file mode 100644 index 0000000..e1824a3 --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "hesla", + "version": "0.2.0", + "description": "Losungen reader", + "repository": { + "type": "git", + "url": "https://gitlab.com/mcepl/hesla.git" + }, + "keywords": [ + "hesla", + "reader", + "mobile" + ], + "author": "Matěj Cepl <mcepl@cepl.eu>", + "license": "MIT", + "devDependencies": { + "babel-core": "~6.1.21", + "babel-cli": "~6.1.18", + "babel-preset-es2015": "~6.1.18", + "babel-plugin-transform-es2015-literals": "~6.1.18", + "babel-plugin-transform-es2015-modules-amd": "~6.1.18", + "babel-plugin-transform-es2015-destructuring": "~6.1.18", + "babel-plugin-transform-es2015-modules-commonjs": "~6.1.20", + "babel-plugin-transform-es2015-modules-umd": "~6.1.18", + "babel-plugin-transform-es2015-parameters": "~6.1.18", + "babel-plugin-transform-es2015-computed-properties": "~6.1.18", + "babel-plugin-transform-es2015-unicode-regex": "~6.1.18", + "babel-plugin-transform-es2015-modules-systemjs": "~6.1.18", + "babel-plugin-transform-es2015-object-super": "~6.1.18", + "babel-plugin-transform-es2015-function-name": "~6.1.18", + "babel-plugin-transform-es2015-classes": "~6.1.21", + "babel-plugin-transform-es2015-block-scoped-functions": "~6.1.18", + "babel-plugin-transform-es2015-template-literals": "~6.1.18", + "babel-plugin-transform-es2015-sticky-regex": "~6.1.18", + "babel-plugin-transform-es2015-shorthand-properties": "~6.1.18", + "babel-plugin-transform-es2015-typeof-symbol": "~6.1.18", + "babel-plugin-transform-es2015-block-scoping": "~6.1.18", + "babel-plugin-transform-es2015-spread": "~6.1.18" + } +} diff --git a/sworker.js b/sworker.js new file mode 100644 index 0000000..e04691c --- /dev/null +++ b/sworker.js @@ -0,0 +1,53 @@ +var version = 'v2 - 2011-11-16'; +var toCache = [ + '/', + 'index.html', + 'activePage.js', + 'activePage.js.map', + 'config.js', + 'config.js.map', + 'hesla.js', + 'hesla.js.map', + 'hesla.webapp', + 'require.js', + 'favicon.ico', + 'icon-128.png', + 'icon-30.png', + 'icon-60.png', + 'index_de.html', + 'index.html', + 'require.js', + 'screen.css' +]; + +self.addEventListener('install', event => { + event.waitUntil( + caches.open('static' + version).then(c => c.addAll(toCache)) + ); +}); + +self.addEventListener('activate', event => { + event.waitUntil( + Promise.all( + caches.keys().then(keys => + keys.filter(key => key != 'static' + version).map(key => caches.delete(key)) + ) + ) + ); +}); + +self.addEventListener('fetch', event => { + event.respondWith(caches.match(event.request)); +}); + +// this.addEventListener('fetch', function(event) { +// event.respondWith( +// caches.match(event.request).then(function(pro) { +// console.log('Fullfilling ' + event.request.url + ' from cache'); +// return pro; +// }).catch(function() { +// console.log('Loading ' + event.request.url); +// return fetch(event.request); +// }) +// ); +// }); diff --git a/templates/base.html b/templates/base.html index 66e4923..b543d80 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,7 +12,7 @@ {{ word.ref }} {%- endif %}</p>{%- endmacro -%} <!DOCTYPE html> -<html manifest="hesla.appcache"> +<html> <head> <meta charset="utf-8"/> <meta content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" name="viewport"/> @@ -24,6 +24,15 @@ display: none; } </style> + <script type="text/javascript"> + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sworker.js').then(function(reg) { + console.log('Yey!', reg); + }).catch(function(err) { + console.log('Boo!', err); + }); + } + </script> </head> <body> <noscript>{{ noscript_message }}</noscript> |