From f0918dce75e5f29a275433e8c3c25010a382437a Mon Sep 17 00:00:00 2001 From: Willem Date: Wed, 16 Mar 2016 21:58:27 +0100 Subject: [PATCH] fixed json header added and added boot clean options --- README.md | 8 +++++ es5-ff-spa-loader.js | 46 +++++++++++++++++++++++--- example/app_server/www_views/index.ejs | 11 ++++-- package.json | 2 +- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 02f067e..f73fd8a 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,9 @@ A javascript library providing server defined loading of assets for a single pag * boot.cordova.flag = The window flag which is set when cordova is booted. (default: 'FFCordovaDevice') * boot.angular.enable = Auto bootstrap angular modules. (default: true) * boot.angular.modules = The angular modules to boot. (default: empty) + * boot.cleanup.enable = Auto cleanup the loader html tags. (default: true) + * boot.cleanup.timeout = Cleanup after timeout(in ms) so css effects are done. (default: 1000) + * boot.cleanup.tags = The array of tag ids to remove. (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. (default: 4096) @@ -214,6 +217,11 @@ Add unit tests for any new or changed functionality. Lint and test your code. ## Release History +### 0.2.1 +* Fixed clearCache method to added json header. +* Added url to non 200 http status error message. +* Added boot.cleanup.tags options. + ### 0.2.0 * Moved error.style and question.style to css file. * Changed dist with extra css/js folder. diff --git a/es5-ff-spa-loader.js b/es5-ff-spa-loader.js index 11bded6..ec6072d 100644 --- a/es5-ff-spa-loader.js +++ b/es5-ff-spa-loader.js @@ -57,13 +57,18 @@ boot: { cordova: { enable: true, - timeout: -1, + timeout: -1, flag: 'FFCordovaDevice' }, angular: { enable: true, modules: [] - }, + }, + cleanup: { + enable: true, + timeout: 1000, + tags: [] + } }, server: { url: null, @@ -355,7 +360,7 @@ cb(null, httpRequest); } else if (httpRequest.readyState === 4) { - cb('Wrong status '+httpRequest.status); + cb('Wrong status '+httpRequest.status+' of '+url); } }; httpRequest.open('GET', url, true); @@ -1002,7 +1007,8 @@ if (err !== null) { options.error.handler(err); } else { - utilDebug('start done in '+(new Date().getTime()-startTime)+' ms.'); // last debug line TODO: move bootAngular to onjsloaded + utilDebug('start done in '+(new Date().getTime()-startTime)+' ms.'); // last debug line TODO: move bootAngular to onjsloaded + bootCleanup(); // move after ang. bootAngular(function(err) { if (err !== null) { return options.error.handler(err); } if (typeof cbArgu === 'function') { @@ -1094,10 +1100,40 @@ } var resources = JSON.parse(httpRequest.responseText).data.resources; cleanupCache(resources,false,cb); - }); + }, true); // TODO: create resourcesListFetch(); } }; + /** + * Boot cleanup removed the html tags by id after the timeout. + * + * note: sync function + * + * @private + */ + var bootCleanup = function() { + if (options.boot.cleanup.enable !== true) { + utilDebug('bootCleanup disabled by options'); + return; + } + if (options.boot.cleanup.tags.length === 0) { + utilDebug('bootCleanup disabled by no tags ids.'); + return; + } + utilDebug('bootCleanup after '+options.boot.cleanup.timeout+' ms.'); + setTimeout ( function () { + utilDebug('bootCleanup run'); + for (var tagIdx in options.boot.cleanup.tags) { + var tagId = options.boot.cleanup.tags[tagIdx]; + var tag = document.getElementById(tagId); + if (tag !== null) { + tag.parentNode.removeChild(tag); + utilDebug('bootCleanup removed '+tagId); + } + } + }, options.boot.cleanup.timeout); + }; + /** * Boots angular modules if enabled. * diff --git a/example/app_server/www_views/index.ejs b/example/app_server/www_views/index.ejs index d4508a6..bf7bafb 100644 --- a/example/app_server/www_views/index.ejs +++ b/example/app_server/www_views/index.ejs @@ -3,13 +3,18 @@ Loading - + - - +