From 25e2e4bcd0ce93e56e91341b881f15016e35d9cb Mon Sep 17 00:00:00 2001 From: Willem Date: Mon, 18 Jan 2016 22:41:52 +0100 Subject: [PATCH] clearup some old if statements --- README.md | 2 +- es5-ff-spa-loader.js | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 92c357c..90634e2 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ A javascript library providing server defined loading of assets for a single pag * boot.angular.modules = The angular modules to boot. (default: empty) * server.url = The server url like 'https://myhost', when null the user will get promted to input it. (default: null) * server.assets = The server path to the assets resources definition file, is required (default: null) - * server.timeout = The timeout to download the server resources. + * server.timeout = The timeout to download the server resources. (default: 4096) * server.flag = The window flag which is set when the server.url is know. (default: 'FFServerUrl') * server.question.transport = The transport to prefix the server.url with. (default: 'http://') * server.question.title = The question ui title. (default: 'Server') diff --git a/es5-ff-spa-loader.js b/es5-ff-spa-loader.js index 7fc246e..780885f 100644 --- a/es5-ff-spa-loader.js +++ b/es5-ff-spa-loader.js @@ -97,7 +97,7 @@ localStorage: function() { try { var testData = 'localStorageDetect'; - rootWindow.localStorage.setItem(testData, testData); + rootWindow.localStorage.setItem(testData, testData); // throws err in private browsing mode rootWindow.localStorage.removeItem(testData); return true; } catch(e) { @@ -180,10 +180,13 @@ return { cacheOpen: function(cb) { if (cacheDB !== null) { - cb(null); // open once. - return; + return cb(null); // open once. + } + try { + cacheDB = rootWindow.openDatabase(opt.name, opt.version, opt.name, opt.size); + } catch(e) { + return cb(e); } - cacheDB = rootWindow.openDatabase(opt.name, opt.version, opt.name, opt.size); cacheDB.transaction(function(tx) { var query = 'SELECT value FROM cache_store WHERE key = \"test-for-table\"'; utilDebug('websql.cacheOpen query '+query); @@ -455,7 +458,7 @@ utilDebug('injectResources'); resources.forEach(function (resource) { cacheGetValue(resource.type,resource.hash,function(err,item) { - // TODO injectResourceData + // TODO reuse injectResourceData var tag = null; if (resource.type === 'css' || resource.type === 'cssData') { @@ -549,10 +552,11 @@ } options.server.url = ''; - if (options.server.question.transport !== undefined) { + if (inputTag.value.indexOf('http') === -1) { options.server.url += options.server.question.transport; } options.server.url += inputTag.value; + // TODO: auto rm ending / var resourcesUrl = options.server.url + options.server.assets; utilDebug('askUrlStart check assets '+resourcesUrl); @@ -608,12 +612,11 @@ var formTag = document.createElement('div'); rootTag.appendChild(formTag); - if (options.server.question.transport !== undefined) { - var transportTag = document.createElement('label'); - rootTag.setAttribute('for','serverInput'); - transportTag.appendChild(document.createTextNode(options.server.question.transport)); - formTag.appendChild(transportTag); - } + var transportTag = document.createElement('label'); + rootTag.setAttribute('for','serverInput'); + transportTag.appendChild(document.createTextNode(options.server.question.transport)); + formTag.appendChild(transportTag); + var inputTag = document.createElement('input'); inputTag.type = 'text'; inputTag.id = 'serverInput'; @@ -781,11 +784,13 @@ utilDebug('bootCordova done in '+(new Date().getTime()-startTime)+' ms.'); callback(); }; - utilDebug('bootCordova timeout '+options.boot.cordova.timeout); - setTimeout ( function () { - utilDebug('bootCordova timeout'); - bootOnce(); - }, options.boot.cordova.timeout); + if (options.boot.cordova.timeout > 0) { + utilDebug('bootCordova timeout '+options.boot.cordova.timeout); + setTimeout ( function () { + utilDebug('bootCordova timeout'); + bootOnce(); + }, options.boot.cordova.timeout); + } document.addEventListener("deviceready", function () { rootWindow[options.boot.cordova.flag] = true; utilDebug('bootCordova '+options.boot.cordova.flag);