2
Fork 0

Prepared next release

This commit is contained in:
Willem Cazander 2022-11-14 12:11:33 +01:00
parent ae59d82f97
commit 5024a9c99c
3 changed files with 45 additions and 142 deletions

View file

@ -20,8 +20,18 @@ A javascript library providing server defined loading of assets for a single pag
* Loader error ui. * Loader error ui.
* No external dependencies. * No external dependencies.
* Technology agnostic booting. * Technology agnostic booting.
* Build-in Cordova booting.
* Build-in AngularJS-1 booting. ## Todo
* Make cordova example work again
* Make tests work again
* Add instance websql options so it can also be used in application code.
* Split assets per type so do js first then boot then css + dss.
* Add more tests
* css: set tag.media = 'only you';
* css: add media in resouces
* Add in browser tests
* cache limits for soft fallback to injecting ?
## Usage ## Usage
@ -36,16 +46,6 @@ A javascript library providing server defined loading of assets for a single pag
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources'; FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
FFSpaLoader.start(); FFSpaLoader.start();
### Usage Angular
FFSpaLoader.options.boot.debug.enable = true;
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
FFSpaLoader.options.server.url = 'http://myserver';
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
FFSpaLoader.start(function(err) {
console.log('FFExample.boot done');
});
## Assets format ## Assets format
{ {
@ -81,11 +81,6 @@ A javascript library providing server defined loading of assets for a single pag
* boot.debug.prefix = Debug message prefix. (default: 'FFSpaLoader.') * boot.debug.prefix = Debug message prefix. (default: 'FFSpaLoader.')
* boot.error.enable = Enables the ui error handler. (default: true) * boot.error.enable = Enables the ui error handler. (default: true)
* boot.error.title = The error title. (default: 'Loader '); * boot.error.title = The error title. (default: 'Loader ');
* boot.cordova.enable = Use deviceready event to boot when cordova is detected. (default: true)
* boot.cordova.timeout = Boot after (if<0=no-)timeout when deviceready event is not received. (default: -1)
* 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.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.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) * boot.cleanup.tags = The array of tag ids to remove. (default: empty)
@ -134,8 +129,6 @@ A javascript library providing server defined loading of assets for a single pag
* detect.localStorage() = Checks is localStorage is working. * detect.localStorage() = Checks is localStorage is working.
* detect.openDatabase() = Checks if openDatabase is defined. * detect.openDatabase() = Checks if openDatabase is defined.
* detect.sqlitePlugin() = Checks if sqlitePlugin is defined. * detect.sqlitePlugin() = Checks if sqlitePlugin is defined.
* detect.cordova() = Checks if cordova is defined.
* detect.cordovaDevice() = Checks if the options.boot.cordova.flag is defined in the window.(NOTE: is always false before calling start();)
* cache.localStorage() = Creates an localStorage service. * cache.localStorage() = Creates an localStorage service.
* cache.websql(opt) = Creates an websql service. * cache.websql(opt) = Creates an websql service.
@ -152,7 +145,7 @@ A javascript library providing server defined loading of assets for a single pag
Per default all cache types are auto selected in the following order; Per default all cache types are auto selected in the following order;
* detect.sqlitePlugin() and detect.cordovaDevice() * detect.sqlitePlugin()
* detect.openDatabase() * detect.openDatabase()
* detect.localStorage() * detect.localStorage()
* none * none
@ -177,7 +170,7 @@ A javascript library providing server defined loading of assets for a single pag
There is a nodejs example application in the example folder; There is a nodejs example application in the example folder;
* git clone https://bitbucket.org/im_ik/es5-ff-spa-loader.git * git clone https://bitbucket.org/immetoo/es5-ff-spa-loader.git
* cd es5-ff-spa-loader * cd es5-ff-spa-loader
* npm install * npm install
* npm start * npm start
@ -203,17 +196,6 @@ A javascript library providing server defined loading of assets for a single pag
* Android 4.4.4 in Cordova + Site * Android 4.4.4 in Cordova + Site
* Android 4.2.2 in Cordova + Site * Android 4.2.2 in Cordova + Site
## Todo
* test in production
* Add instance websql options so it can also be used in application code.
* Split assets per type so do js first then boot then css + dss.
* Add more tests
* css: set tag.media = 'only you';
* css: add media in resouces
* Add in browser tests
* cache limits for soft fallback to injecting ?
## Contributing ## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. In lieu of a formal styleguide, take care to maintain the existing coding style.
@ -223,6 +205,7 @@ Add unit tests for any new or changed functionality. Lint and test your code.
### 0.3.1 ### 0.3.1
* Removed cordova support * Removed cordova support
* Removed AngularJS support
### 0.3.0 ### 0.3.0
* Fixed clearServerUrl() to also clean the cached server resources json. * Fixed clearServerUrl() to also clean the cached server resources json.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2016, Willem Cazander * Copyright (c) 2015-2022, Willem Cazander
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided * Redistribution and use in source and binary forms, with or without modification, are permitted provided
@ -21,7 +21,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* jslint browser: true */ /* jslint browser: true */
/* global angular,define,module,sqlitePlugin */ /* global define,module,sqlitePlugin */
/** /**
* FFSpaLoader is an assets loader for single page applications. * FFSpaLoader is an assets loader for single page applications.
@ -54,15 +54,6 @@
enable: true, enable: true,
title: 'Loader ' title: 'Loader '
}, },
cordova: {
enable: true,
timeout: -1,
flag: 'FFCordovaDevice'
},
angular: {
enable: true,
modules: []
},
cleanup: { cleanup: {
enable: true, enable: true,
timeout: 1000, timeout: 1000,
@ -178,12 +169,6 @@
}, },
sqlitePlugin: function() { sqlitePlugin: function() {
return 'sqlitePlugin' in rootWindow; return 'sqlitePlugin' in rootWindow;
},
cordova: function() {
return 'cordova' in rootWindow;
},
cordovaDevice: function() {
return options.boot.cordova.flag in rootWindow;
} }
}, },
cache: { cache: {
@ -1025,7 +1010,7 @@
return cb(null); return cb(null);
} }
if (options.cache[type] === null) { if (options.cache[type] === null) {
if (factory.detect.cordovaDevice() && factory.detect.sqlitePlugin()) { if (factory.detect.sqlitePlugin()) {
utilDebug('startCacheType auto sqlitePlugin for '+type); utilDebug('startCacheType auto sqlitePlugin for '+type);
options.cache[type] = factory.cache.websql({ options.cache[type] = factory.cache.websql({
open: function(dbOpt) { open: function(dbOpt) {
@ -1081,26 +1066,6 @@
}); });
}; };
/**
* Boots angular modules if enabled.
*
* @param {function} cb Error first callback gets called done.
* @private
*/
var bootAngular = function(cb) {
if (options.boot.angular.enable !== true) {
utilDebug('bootAngular disabled by options');
return cb(null);
}
if (options.boot.angular.modules.length === 0) {
utilDebug('bootAngular disabled by no modules');
return cb(null);
}
utilDebug('bootAngular start '+options.boot.angular.modules);
angular.bootstrap(document, options.boot.angular.modules);
cb(null);
};
/** /**
* Boot cleanup removed the html tags by id after the timeout. * Boot cleanup removed the html tags by id after the timeout.
* *
@ -1128,44 +1093,6 @@
}, options.boot.cleanup.timeout); }, options.boot.cleanup.timeout);
}; };
/**
* Boots cordova applications which want to use the sqllite plugin as cache.
* Note: On none cordova page it will callback directly.
* Note: On none cordova device page is will timeout if option is set.
*
* @param {function} cb Error first callback gets called device is ready.
* @private
*/
var bootCordova = function(cb) {
if (options.boot.cordova.enable !== true) {
utilDebug('bootCordova disabled by options');
return cb(null);
}
if (factory.detect.cordova() !== true) {
utilDebug('bootCordova disabled by detect');
return cb(null);
}
var startTime = new Date().getTime();
var bootOnce = function() {
var callback = cb;
cb = null;
utilDebug('bootCordova done in '+(new Date().getTime()-startTime)+' ms.');
callback(null);
};
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);
bootOnce();
}, false);
};
/** /**
* Starts the loader. * Starts the loader.
* *
@ -1189,12 +1116,10 @@
if (err !== null) { if (err !== null) {
cbRoot(err); cbRoot(err);
} else { } 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.');
bootCleanup(); // move after ang. bootCleanup();
bootAngular(function(err) { loadDelayedResouces();
loadDelayedResouces(); cbRoot(err);
cbRoot(err);
});
} }
}; };
utilDebug('start spa-loader'); // first debug line TODO: Add version utilDebug('start spa-loader'); // first debug line TODO: Add version
@ -1210,33 +1135,28 @@
utilDebug('start config '+key+' '+JSON.stringify(options[key])); utilDebug('start config '+key+' '+JSON.stringify(options[key]));
} }
} }
bootCordova(function(err) { startCache(function(err) {
if (err !== null) { if (err !== null) {
return cb(err); return cb(err);
} }
startCache(function(err) { if (options.server.url !== null) {
if (err !== null) { startLoader(cb);
return cb(err); return;
} }
if (options.server.url !== null) { if (cacheHasService('meta')) {
startLoader(cb); cacheGetValue('meta','server_url',function(err, value) {
return; if (err !== null) {
} cb(err);
if (cacheHasService('meta')) { } else if (value === undefined || value === null || value === '') {
cacheGetValue('meta','server_url',function(err, value) { askUrl(cb);
if (err !== null) { } else {
cb(err); options.server.url = value;
} else if (value === undefined || value === null || value === '') { startLoader(cb);
askUrl(cb); }
} else { });
options.server.url = value; } else {
startLoader(cb); askUrl(cb);
} }
});
} else {
askUrl(cb);
}
});
}); });
}; };

View file

@ -1,6 +1,6 @@
{ {
"name": "es5-ff-spa-loader", "name": "es5-ff-spa-loader",
"version": "0.3.0", "version": "0.4.0",
"description": "Javascript Single Page Application Loader", "description": "Javascript Single Page Application Loader",
"main": "es5-ff-spa-loader.js", "main": "es5-ff-spa-loader.js",
"scripts": { "scripts": {
@ -10,7 +10,7 @@
"test": "gulp test", "test": "gulp test",
"start": "node example/app_server/example.js" "start": "node example/app_server/example.js"
}, },
"author": "Willem <willem.git.2016@forwardfire.net> (http://forwardfire.net/)", "author": "Willem <willemtsade.git.2022@distributedrebirth.love>",
"keywords": [ "keywords": [
"offline", "offline",
"website", "website",
@ -30,10 +30,10 @@
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://bitbucket.org/im_ik/es5-ff-spa-loader.git" "url": "https://bitbucket.org/immetoo/es5-ff-spa-loader.git"
}, },
"bugs": { "bugs": {
"url": "https://bitbucket.org/im_ik/es5-ff-spa-loader/issues" "url": "https://bitbucket.org/immetoo/es5-ff-spa-loader/issues"
}, },
"devDependencies": { "devDependencies": {
"angular": "^1.4.8", "angular": "^1.4.8",