mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
basic scrolling renderer
This commit is contained in:
parent
849625fc83
commit
b1b98f9d57
15 changed files with 1020 additions and 22 deletions
|
@ -153,4 +153,108 @@ EPUBJS.core.folder = function(url){
|
|||
|
||||
return folder;
|
||||
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.core.queue = function(_scope){
|
||||
var _q = [];
|
||||
var scope = _scope;
|
||||
// Add an item to the queue
|
||||
var enqueue = function(funcName, args, context) {
|
||||
_q.push({
|
||||
"funcName" : funcName,
|
||||
"args" : args,
|
||||
"context" : context
|
||||
});
|
||||
return _q;
|
||||
};
|
||||
// Run one item
|
||||
var dequeue = function(){
|
||||
var inwait;
|
||||
if(_q.length) {
|
||||
inwait = _q.shift();
|
||||
// Defer to any current tasks
|
||||
// setTimeout(function(){
|
||||
scope[inwait.funcName].apply(inwait.context || scope, inwait.args);
|
||||
// }, 0);
|
||||
}
|
||||
};
|
||||
|
||||
// Run All
|
||||
var flush = function(){
|
||||
while(_q.length) {
|
||||
dequeue();
|
||||
}
|
||||
};
|
||||
// Clear all items in wait
|
||||
var clear = function(){
|
||||
_q = [];
|
||||
};
|
||||
|
||||
var length = function(){
|
||||
return _q.length;
|
||||
};
|
||||
|
||||
return {
|
||||
"enqueue" : enqueue,
|
||||
"dequeue" : dequeue,
|
||||
"flush" : flush,
|
||||
"clear" : clear,
|
||||
"length" : length
|
||||
};
|
||||
};
|
||||
|
||||
EPUBJS.core.isElement = function(obj) {
|
||||
return !!(obj && obj.nodeType == 1);
|
||||
};
|
||||
|
||||
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
|
||||
EPUBJS.core.uuid = function() {
|
||||
var d = new Date().getTime();
|
||||
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = (d + Math.random()*16)%16 | 0;
|
||||
d = Math.floor(d/16);
|
||||
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
|
||||
});
|
||||
return uuid;
|
||||
};
|
||||
|
||||
// From Lodash
|
||||
EPUBJS.core.values = function(object) {
|
||||
var index = -1,
|
||||
props = Object.keys(object),
|
||||
length = props.length,
|
||||
result = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = object[props[index]];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
EPUBJS.core.resolveUrl = function(base, path) {
|
||||
var url,
|
||||
segments = [],
|
||||
// uri = EPUBJS.core.uri(path),
|
||||
folders = base.split("/"),
|
||||
paths;
|
||||
|
||||
// if(uri.host) {
|
||||
// return path;
|
||||
// }
|
||||
|
||||
folders.pop();
|
||||
|
||||
paths = path.split("/");
|
||||
paths.forEach(function(p){
|
||||
if(p === ".."){
|
||||
folders.pop();
|
||||
}else{
|
||||
segments.push(p);
|
||||
}
|
||||
});
|
||||
|
||||
url = folders.concat(segments);
|
||||
|
||||
return url.join("/");
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue