From 8a3b1aefc9d3c29ee77075ce49b48ac74f70c1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 21 Aug 2015 22:58:33 +0200 Subject: [PATCH] always load local manifest at startup This gives proper content from the start, without requiring the user to check for updates to get something out of the app. This also gives us proper URLs for manifest and assets updates. --- www/js/index.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/www/js/index.js b/www/js/index.js index 7f2aafb..6cfb6ab 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -116,7 +116,33 @@ var app = { // Device ready callback onDeviceReady: function() { + var request = new XMLHttpRequest(); + request.open('GET', '../index.json'); + request.onload = function() { + if (request.status != 200) { + /* this should never happen */ + app.utils.setLoadingMsg("Initialisation de l'application : erreur de chargement"); + } else { + var new_manifest = JSON.parse(this.responseText); + for (var attr in new_manifest.meta) { + if (new_manifest.meta.hasOwnProperty(attr)) { + app.manifest.meta[attr] = new_manifest.meta[attr]; + } + } + app.manifest.title = new_manifest.title; + app.manifest.content = new_manifest.content; + app.manifest.pages = new_manifest.pages; + app.onDefaultManifestLoaded(); + } + }; + request.send(); + }, + onDefaultManifestLoaded: function() { + app.initApplication(); + }, + + initApplication: function() { // Init fileSystem app.initFileSystem();