mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
updated how tasks are added to queue
This commit is contained in:
parent
ee19c03287
commit
338bc64884
5 changed files with 1540 additions and 2092 deletions
3164
dist/epub.js
vendored
3164
dist/epub.js
vendored
File diff suppressed because it is too large
Load diff
6
dist/epub.min.js
vendored
6
dist/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -7,17 +7,39 @@ EPUBJS.Queue = function(_context){
|
|||
|
||||
// Add an item to the queue
|
||||
EPUBJS.Queue.prototype.enqueue = function(task, args, context) {
|
||||
var deferred, promise;
|
||||
var queued;
|
||||
|
||||
// Handle single args without context
|
||||
if(args && !args.length) {
|
||||
args = [args];
|
||||
}
|
||||
|
||||
this._q.push({
|
||||
if(typeof task === "function"){
|
||||
|
||||
deferred = new RSVP.defer();
|
||||
promise = deferred.promise;
|
||||
|
||||
queued = {
|
||||
"task" : task,
|
||||
"args" : args,
|
||||
"context" : context
|
||||
});
|
||||
return this._q;
|
||||
"context" : context,
|
||||
"deferred" : deferred,
|
||||
"promise" : promise
|
||||
};
|
||||
|
||||
} else {
|
||||
// Task is a promise
|
||||
queued = {
|
||||
"promise" : task
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
this._q.push(queued);
|
||||
|
||||
|
||||
return queued.promise;
|
||||
};
|
||||
|
||||
// Run one item
|
||||
|
@ -28,12 +50,15 @@ EPUBJS.Queue.prototype.dequeue = function(){
|
|||
inwait = this._q.shift();
|
||||
task = inwait.task;
|
||||
|
||||
if(typeof task === "function"){
|
||||
if(task){
|
||||
// Task is a function that returns a promise
|
||||
return task.apply(inwait.context || this.context, inwait.args);
|
||||
return task.apply(inwait.context || this.context, inwait.args).then(function(){
|
||||
inwait.deferred.resolve.apply(inwait.context || this.context, arguments);
|
||||
}.bind(this));
|
||||
|
||||
} else {
|
||||
// Task is a promise
|
||||
return task;
|
||||
return inwait.promise;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -71,13 +96,11 @@ EPUBJS.Queue.prototype.length = function(){
|
|||
|
||||
// Create a new tast from a callback
|
||||
EPUBJS.Task = function(task, args, context){
|
||||
var toApply = args || [];
|
||||
var scope = context || this.context;
|
||||
|
||||
return function(){
|
||||
var toApply = arguments || [];
|
||||
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
|
||||
var callback = function(value){
|
||||
resolve(value);
|
||||
};
|
||||
|
@ -85,9 +108,9 @@ EPUBJS.Task = function(task, args, context){
|
|||
toApply.push(callback);
|
||||
|
||||
// Apply all arguments to the functions
|
||||
task.apply(scope, toApply);
|
||||
task.apply(this, toApply);
|
||||
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -143,21 +143,12 @@ EPUBJS.Rendition.prototype.bounds = function() {
|
|||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.display = function(what){
|
||||
var displaying = new RSVP.defer();
|
||||
var displayed = displaying.promise;
|
||||
|
||||
// Check for fragments
|
||||
if(typeof what === 'string') {
|
||||
what = what.split("#")[0];
|
||||
}
|
||||
return this.q.enqueue(this.load, what);
|
||||
|
||||
this.q.enqueue(this.move, what);
|
||||
|
||||
|
||||
return displayed;
|
||||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.move = function(what){
|
||||
EPUBJS.Rendition.prototype.load = function(what){
|
||||
var displaying = new RSVP.defer();
|
||||
var displayed = displaying.promise;
|
||||
|
||||
|
@ -168,16 +159,13 @@ EPUBJS.Rendition.prototype.move = function(what){
|
|||
|
||||
if(section){
|
||||
view = new EPUBJS.View(section);
|
||||
// Clear views
|
||||
// this.clear();
|
||||
this.fill(view);
|
||||
// rendered = this.render(section);
|
||||
|
||||
// if(this.settings.infinite) {
|
||||
// rendered.then(function(){
|
||||
// return this.fill.call(this);
|
||||
// }.bind(this));
|
||||
// }
|
||||
// This will clear all previous views
|
||||
this.fill(view);
|
||||
|
||||
// Move to correct place within the section, if needed
|
||||
// this.moveTo(what)
|
||||
|
||||
this.check();
|
||||
|
||||
view.displayed.then(function(){
|
||||
|
@ -193,6 +181,11 @@ EPUBJS.Rendition.prototype.move = function(what){
|
|||
return displayed;
|
||||
};
|
||||
|
||||
// Takes a cfi, fragment or page?
|
||||
EPUBJS.Rendition.prototype.moveTo = function(what){
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.render = function(view) {
|
||||
// var view = new EPUBJS.View(section);
|
||||
//
|
||||
|
|
|
@ -54,6 +54,8 @@ EPUBJS.Spine.prototype.get = function(target) {
|
|||
} else if(target && target.indexOf("#") === 0) {
|
||||
index = this.spineById[target.substring(1)];
|
||||
} else if(target) {
|
||||
// Remove fragments
|
||||
target = target.split("#")[0];
|
||||
index = this.spineByHref[target];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue