From e73d8386d7b54e88a03b20d9ae64458559b9896e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 15 Nov 2013 14:42:14 +0000 Subject: [PATCH] --- js/libs/cube/util.js | 3 +-- js/main.js | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/js/libs/cube/util.js b/js/libs/cube/util.js index da0d2cc5..da9692c4 100644 --- a/js/libs/cube/util.js +++ b/js/libs/cube/util.js @@ -19,10 +19,9 @@ function json_parse(str, info) { return JSON.parse(str); } catch (err) { if (info != undefined) { - fb('::::' + info); + } fb(err); - fb(str); } } diff --git a/js/main.js b/js/main.js index dd001469..6c6fefa5 100644 --- a/js/main.js +++ b/js/main.js @@ -11,6 +11,7 @@ var gal = null; var home = window.location.toString(); var resolution = 'auto'; var OFFLINEAPP = false; +var FINISHLOADING = false; try { $(function() { @@ -61,6 +62,9 @@ try { document.addEventListener('deviceready', onDeviceReady, false); document.addEventListener("resume", onAppResume, false); + if (!OFFLINEAPP) { + document.addEventListener("offline", onDeviceOffline, false); + } loadJSLibrary( cordova @@ -68,6 +72,19 @@ try { }); } + function onDeviceOffline() { + if (OFFLINEAPP) { + return; + } + + if (!FINISHLOADING) { + navigator.notification.alert(__('This publication is not available offline. To read it, an internet connection is required'), + function() { + window.location = window.sessionStorage.getItem('apphome'); + }, __('An internet connection is required')); + } + } + function onAppResume() { if (!INITED) { return; @@ -76,7 +93,7 @@ try { } function onDeviceReady() { - var manifest = window.sessionStorage.getItem('manifest.' + DATAS.id); + var manifest = window.localStorage.getItem('manifest.' + DATAS.id); var fsprefix = window.sessionStorage.getItem('galfsprefix'); if (DATAS.phonegap == 'ios') { @@ -109,7 +126,7 @@ try { if (navigator.onLine && manifest && !OFFLINEAPP) { var readyToLoad = false; var finishedLoading = false; - gal = new GameAssetLoader(json_parse(manifest), fsprefix); + gal = new GameAssetLoader(json_parse(manifest, 'manifest'), fsprefix); gal.init(function() { startAfterLoading = true; @@ -276,8 +293,8 @@ try { if (OFFLINEAPP) { window.location = getPublicationURL(id); } else { - var topmanifest = window.sessionStorage.getItem('topmanifest'); - window.gallocale = new GameAssetLoader(json_parse(topmanifest,'topmanifest'), window.sessionStorage.getItem('galfsprefix')); + var topmanifest = window.localStorage.getItem('topmanifest'); + window.gallocale = new GameAssetLoader(json_parse(topmanifest, 'topmanifest'), window.sessionStorage.getItem('galfsprefix')); window.gallocale.init(function() { window.gallocale.downloadAndCall('p_' + id, function() { window.location = getPublicationURL(id); -- 2.39.5