mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
commented code and cleaned up
This commit is contained in:
parent
3c151efdb5
commit
2ddae3a024
7 changed files with 223 additions and 315 deletions
|
@ -53,201 +53,4 @@ FP.storage = function(){
|
|||
"getStorageType" : getStorageType
|
||||
}
|
||||
|
||||
}();
|
||||
|
||||
/*
|
||||
FP.storage.ram = function() {
|
||||
var _store = {},
|
||||
_blobs = {},
|
||||
_queue = new FP.Queue("loader_ram.js", 3);
|
||||
|
||||
|
||||
//-- TODO: this should be prototypes?
|
||||
|
||||
//-- Used for preloading
|
||||
function preload(path) {
|
||||
var fromCache = check(path);
|
||||
|
||||
if(!fromCache){
|
||||
request(path);
|
||||
}
|
||||
}
|
||||
|
||||
function batch(group, callback){
|
||||
_queue.addGroup(group)
|
||||
}
|
||||
|
||||
//-- Fetches url
|
||||
function get(path, callback) {
|
||||
var fromCache = check(path),
|
||||
url;
|
||||
|
||||
if(fromCache){
|
||||
url = getURL(path, fromCache);
|
||||
if(typeof(callback) != "undefined"){
|
||||
callback(url);
|
||||
}
|
||||
}else{
|
||||
request(path, function(file){
|
||||
url = getURL(path, file);
|
||||
if(typeof(callback) != "undefined"){
|
||||
callback(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function check(path) {
|
||||
var file = _store[file];
|
||||
|
||||
if(typeof(file) != "undefined"){
|
||||
return file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function request(path, callback) {
|
||||
var xhr = new FP.core.loadFile(path);
|
||||
|
||||
xhr.succeeded = function(file) {
|
||||
//console.log("file", file)
|
||||
cache(path, file);
|
||||
if(typeof(callback) != "undefined"){
|
||||
callback(file);
|
||||
}
|
||||
}
|
||||
|
||||
xhr.failed = _error;
|
||||
|
||||
xhr.start();
|
||||
}
|
||||
|
||||
function cache(path, file) {
|
||||
if(_store[path]) return;
|
||||
|
||||
_store[path] = file;
|
||||
|
||||
}
|
||||
|
||||
function getURL(path, file){
|
||||
var url;
|
||||
|
||||
if(typeof(_blobs[path]) != "undefined"){
|
||||
return _blobs[path];
|
||||
}
|
||||
|
||||
url = this._URL.createObjectURL(file);
|
||||
|
||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
||||
// this.createdURLs.forEach(function(url){
|
||||
// this._URL.revokeObjectURL(url);
|
||||
// });
|
||||
|
||||
_blobs[path] = url;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// this.succeeded = function(){
|
||||
// console.log("loaded");
|
||||
// }
|
||||
//
|
||||
// this.failed = function(){
|
||||
// console.log("loaded");
|
||||
// }
|
||||
|
||||
function _error(err){
|
||||
if(typeof(this.failed) == "undefined"){
|
||||
console.log("Error: ", err);
|
||||
}else{
|
||||
this.failed(err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"get" : get,
|
||||
"preload" : preload
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
FP.store = FP.store || {};
|
||||
|
||||
FP.store.none = function() {
|
||||
var _store = {};
|
||||
|
||||
//-- Used for preloading
|
||||
function preload(path) {
|
||||
var fromCache = check(path);
|
||||
|
||||
if(!fromCache){
|
||||
request(path);
|
||||
}
|
||||
}
|
||||
|
||||
//-- need to add batch!
|
||||
|
||||
//-- Fetches url
|
||||
function get(path, callback) {
|
||||
var fromCache = check(path),
|
||||
url;
|
||||
|
||||
if(fromCache){
|
||||
callback(path);
|
||||
}else{
|
||||
request(path, function(file){
|
||||
callback(path);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function check(path) {
|
||||
var file = _store[path];
|
||||
|
||||
if(typeof(file) != "undefined"){
|
||||
return file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function request(path, callback) {
|
||||
var xhr = new FP.core.loadFile(path);
|
||||
|
||||
xhr.succeeded = function(file) {
|
||||
cache(path, file);
|
||||
if(typeof(callback) != "undefined"){
|
||||
callback(file);
|
||||
}
|
||||
}
|
||||
|
||||
xhr.failed = _error;
|
||||
|
||||
xhr.start();
|
||||
}
|
||||
|
||||
function cache(path, file) {
|
||||
if(_store[path]) return;
|
||||
|
||||
_store[path] = file;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function _error(err){
|
||||
if(typeof(this.failed) == "undefined"){
|
||||
console.log("Error: ", err);
|
||||
}else{
|
||||
this.failed(err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"get" : get,
|
||||
"preload" : preload
|
||||
}
|
||||
}
|
||||
|
||||
}();
|
Loading…
Add table
Add a link
Reference in a new issue