2
0
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.
* No external dependencies.
* 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
@ -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.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
{
@ -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.error.enable = Enables the ui error handler. (default: true)
* 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.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)
@ -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.openDatabase() = Checks if openDatabase 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.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;
* detect.sqlitePlugin() and detect.cordovaDevice()
* detect.sqlitePlugin()
* detect.openDatabase()
* detect.localStorage()
* 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;
* 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
* npm install
* 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.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
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
* Removed cordova support
* Removed AngularJS support
### 0.3.0
* 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.
*
* 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.
*/
/* jslint browser: true */
/* global angular,define,module,sqlitePlugin */
/* global define,module,sqlitePlugin */
/**
* FFSpaLoader is an assets loader for single page applications.
@ -54,15 +54,6 @@
enable: true,
title: 'Loader '
},
cordova: {
enable: true,
timeout: -1,
flag: 'FFCordovaDevice'
},
angular: {
enable: true,
modules: []
},
cleanup: {
enable: true,
timeout: 1000,
@ -178,12 +169,6 @@
},
sqlitePlugin: function() {
return 'sqlitePlugin' in rootWindow;
},
cordova: function() {
return 'cordova' in rootWindow;
},
cordovaDevice: function() {
return options.boot.cordova.flag in rootWindow;
}
},
cache: {
@ -1025,7 +1010,7 @@
return cb(null);
}
if (options.cache[type] === null) {
if (factory.detect.cordovaDevice() && factory.detect.sqlitePlugin()) {
if (factory.detect.sqlitePlugin()) {
utilDebug('startCacheType auto sqlitePlugin for '+type);
options.cache[type] = factory.cache.websql({
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.
*
@ -1128,44 +1093,6 @@
}, 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.
*
@ -1189,12 +1116,10 @@
if (err !== null) {
cbRoot(err);
} else {
utilDebug('start done in '+(new Date().getTime()-startTime)+' ms.'); // last debug line TODO: move bootAngular to onjsloaded
bootCleanup(); // move after ang.
bootAngular(function(err) {
loadDelayedResouces();
cbRoot(err);
});
utilDebug('start done in '+(new Date().getTime()-startTime)+' ms.');
bootCleanup();
loadDelayedResouces();
cbRoot(err);
}
};
utilDebug('start spa-loader'); // first debug line TODO: Add version
@ -1210,33 +1135,28 @@
utilDebug('start config '+key+' '+JSON.stringify(options[key]));
}
}
bootCordova(function(err) {
startCache(function(err) {
if (err !== null) {
return cb(err);
}
startCache(function(err) {
if (err !== null) {
return cb(err);
}
if (options.server.url !== null) {
startLoader(cb);
return;
}
if (cacheHasService('meta')) {
cacheGetValue('meta','server_url',function(err, value) {
if (err !== null) {
cb(err);
} else if (value === undefined || value === null || value === '') {
askUrl(cb);
} else {
options.server.url = value;
startLoader(cb);
}
});
} else {
askUrl(cb);
}
});
if (options.server.url !== null) {
startLoader(cb);
return;
}
if (cacheHasService('meta')) {
cacheGetValue('meta','server_url',function(err, value) {
if (err !== null) {
cb(err);
} else if (value === undefined || value === null || value === '') {
askUrl(cb);
} else {
options.server.url = value;
startLoader(cb);
}
});
} else {
askUrl(cb);
}
});
};

View File

@ -1,6 +1,6 @@
{
"name": "es5-ff-spa-loader",
"version": "0.3.0",
"version": "0.4.0",
"description": "Javascript Single Page Application Loader",
"main": "es5-ff-spa-loader.js",
"scripts": {
@ -10,7 +10,7 @@
"test": "gulp test",
"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": [
"offline",
"website",
@ -30,10 +30,10 @@
"license": "BSD-2-Clause",
"repository": {
"type": "git",
"url": "https://bitbucket.org/im_ik/es5-ff-spa-loader.git"
"url": "https://bitbucket.org/immetoo/es5-ff-spa-loader.git"
},
"bugs": {
"url": "https://bitbucket.org/im_ik/es5-ff-spa-loader/issues"
"url": "https://bitbucket.org/immetoo/es5-ff-spa-loader/issues"
},
"devDependencies": {
"angular": "^1.4.8",