2
0
Fork 0

fixed json header added and added boot clean options

This commit is contained in:
Willem 2016-03-16 21:58:27 +01:00
parent 0b75b3efb5
commit f0918dce75
4 changed files with 58 additions and 9 deletions

View file

@ -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.

View file

@ -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.
*

View file

@ -3,13 +3,18 @@
<head>
<meta charset="UTF-8"/>
<title>Loading</title>
<link rel="stylesheet" type="text/css" href="/static/spa-loader.css" />
<link id="ffCleanupCss" rel="stylesheet" type="text/css" href="/static/spa-loader.css" />
</head>
<body>
<script><%- inlineScript %></script>
<script>
<script id="ffCleanupScript"><%- inlineScript %></script>
<script id="ffCleanupConfig">
//FFSpaLoader.options.cache.css = false;
//FFSpaLoader.options.cache.dss = false;
FFSpaLoader.options.debug.enable = true;
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
FFSpaLoader.options.boot.cleanup.tags.push('ffCleanupCss');
FFSpaLoader.options.boot.cleanup.tags.push('ffCleanupScript');
FFSpaLoader.options.boot.cleanup.tags.push('ffCleanupConfig');
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
FFSpaLoader.options.server.header.response['X-My-Api'] = 'noknok';
FFSpaLoader.start();

View file

@ -1,6 +1,6 @@
{
"name": "es5-ff-spa-loader",
"version": "0.2.0",
"version": "0.2.1",
"description": "Javascript Single Page Application Loader",
"main": "es5-ff-spa-loader.js",
"scripts": {