diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-02-15 01:55:40 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-02-15 01:55:40 +0100 |
commit | 20796be1100055c17b63bd5ee59ad0977889395a (patch) | |
tree | 78d1a641a3e8492a16750906bb88103b018b083b | |
parent | d1353a7e24f6c9792a2e2584381f0b96c8cccb7e (diff) | |
download | zalmy-20796be1100055c17b63bd5ee59ad0977889395a.tar.gz |
An attempt to add self-installing button.
-rw-r--r-- | activePage.ts | 33 | ||||
-rw-r--r-- | index.html | 1 | ||||
-rw-r--r-- | zalmy.appcache | 4 | ||||
-rw-r--r-- | zalmy.ts | 2 |
4 files changed, 35 insertions, 5 deletions
diff --git a/activePage.ts b/activePage.ts index 736ddca..9b93908 100644 --- a/activePage.ts +++ b/activePage.ts @@ -8,9 +8,40 @@ export class ActivePage { public cur_section = null; private swipe_pos_x = 0; private swipe_pos_y = 0; + private app_record = null; - constructor() { + constructor(appName: string) { // Swipe event handlers + var cur_location = window.location.href; + var last_slash = cur_location.lastIndexOf('/'); + var base_url = cur_location.slice(0, last_slash + 1) + appName + '.webapp'; + this.app_record = null; + + var chk_inst_req = window.navigator.mozApps.checkInstalled(base_url); + chk_inst_req.onsuccess = function(e) { + if (!chk_inst_req.result) { + var install_but_loc = document.getElementById('installButton'); + install_but_loc.innerHTML( + '<button id="installAction">Install App</button>'); + } + document.getElementById('installAction').addEventListener('click', + (evt: TouchEvent) => { + var install_req = window.navigator.mozApps.install(base_url); + install_req.onsuccess = function() { + this.app_record = this.result; + console.log('Installed with success!'); + }; + install_req.onerror = function() { + console.log('I cannot install the app!'); + }; + }, false); + }; + chk_inst_req.onerror = function(e) { + // Most likely we are not on Firefox or something. + console.log('Cannot check whether the app has been installed.'); + }; + + document.body.addEventListener("dblclick", () => { console.log("dblclick"); @@ -26,6 +26,7 @@ </head> <body> + <div class="installButton"/> <div class="psalm"> <h1 id="Ps.1">Žalm 1</h1> diff --git a/zalmy.appcache b/zalmy.appcache index 3a9d194..4df12d7 100644 --- a/zalmy.appcache +++ b/zalmy.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# v20 - 2015-02-08 +# v22 - 2015-02-15 index.html activePage.js config.js @@ -7,8 +7,6 @@ require.js zalmy.webapp zalmy.js style/basic.css -style/brick-1.0.0rc1.css -style/brick-1.0.0rc1.js style/OpenSans-SemiBold.ttf style/icon-128.png style/icon-512.png @@ -5,7 +5,7 @@ export class Psalm extends ap.ActivePage { constructor() { - super(); + super('zalmy'); } // cur_psalm is actually just a virtual property, which is not stored anywhere and its |