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
3198
dist/epub.js
vendored
3198
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
|
// Add an item to the queue
|
||||||
EPUBJS.Queue.prototype.enqueue = function(task, args, context) {
|
EPUBJS.Queue.prototype.enqueue = function(task, args, context) {
|
||||||
|
var deferred, promise;
|
||||||
|
var queued;
|
||||||
|
|
||||||
// Handle single args without context
|
// Handle single args without context
|
||||||
if(args && !args.length) {
|
if(args && !args.length) {
|
||||||
args = [args];
|
args = [args];
|
||||||
}
|
}
|
||||||
|
|
||||||
this._q.push({
|
if(typeof task === "function"){
|
||||||
|
|
||||||
|
deferred = new RSVP.defer();
|
||||||
|
promise = deferred.promise;
|
||||||
|
|
||||||
|
queued = {
|
||||||
"task" : task,
|
"task" : task,
|
||||||
"args" : args,
|
"args" : args,
|
||||||
"context" : context
|
"context" : context,
|
||||||
});
|
"deferred" : deferred,
|
||||||
return this._q;
|
"promise" : promise
|
||||||
|
};
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Task is a promise
|
||||||
|
queued = {
|
||||||
|
"promise" : task
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this._q.push(queued);
|
||||||
|
|
||||||
|
|
||||||
|
return queued.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run one item
|
// Run one item
|
||||||
|
@ -28,12 +50,15 @@ EPUBJS.Queue.prototype.dequeue = function(){
|
||||||
inwait = this._q.shift();
|
inwait = this._q.shift();
|
||||||
task = inwait.task;
|
task = inwait.task;
|
||||||
|
|
||||||
if(typeof task === "function"){
|
if(task){
|
||||||
// Task is a function that returns a promise
|
// 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 {
|
} else {
|
||||||
// Task is a promise
|
// Task is a promise
|
||||||
return task;
|
return inwait.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,13 +96,11 @@ EPUBJS.Queue.prototype.length = function(){
|
||||||
|
|
||||||
// Create a new tast from a callback
|
// Create a new tast from a callback
|
||||||
EPUBJS.Task = function(task, args, context){
|
EPUBJS.Task = function(task, args, context){
|
||||||
var toApply = args || [];
|
|
||||||
var scope = context || this.context;
|
|
||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
|
var toApply = arguments || [];
|
||||||
|
|
||||||
return new RSVP.Promise(function(resolve, reject) {
|
return new RSVP.Promise(function(resolve, reject) {
|
||||||
|
|
||||||
var callback = function(value){
|
var callback = function(value){
|
||||||
resolve(value);
|
resolve(value);
|
||||||
};
|
};
|
||||||
|
@ -85,9 +108,9 @@ EPUBJS.Task = function(task, args, context){
|
||||||
toApply.push(callback);
|
toApply.push(callback);
|
||||||
|
|
||||||
// Apply all arguments to the functions
|
// 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){
|
EPUBJS.Rendition.prototype.display = function(what){
|
||||||
var displaying = new RSVP.defer();
|
|
||||||
var displayed = displaying.promise;
|
|
||||||
|
|
||||||
// Check for fragments
|
return this.q.enqueue(this.load, what);
|
||||||
if(typeof what === 'string') {
|
|
||||||
what = what.split("#")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
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 displaying = new RSVP.defer();
|
||||||
var displayed = displaying.promise;
|
var displayed = displaying.promise;
|
||||||
|
|
||||||
|
@ -168,16 +159,13 @@ EPUBJS.Rendition.prototype.move = function(what){
|
||||||
|
|
||||||
if(section){
|
if(section){
|
||||||
view = new EPUBJS.View(section);
|
view = new EPUBJS.View(section);
|
||||||
// Clear views
|
|
||||||
// this.clear();
|
|
||||||
this.fill(view);
|
|
||||||
// rendered = this.render(section);
|
|
||||||
|
|
||||||
// if(this.settings.infinite) {
|
// This will clear all previous views
|
||||||
// rendered.then(function(){
|
this.fill(view);
|
||||||
// return this.fill.call(this);
|
|
||||||
// }.bind(this));
|
// Move to correct place within the section, if needed
|
||||||
// }
|
// this.moveTo(what)
|
||||||
|
|
||||||
this.check();
|
this.check();
|
||||||
|
|
||||||
view.displayed.then(function(){
|
view.displayed.then(function(){
|
||||||
|
@ -193,6 +181,11 @@ EPUBJS.Rendition.prototype.move = function(what){
|
||||||
return displayed;
|
return displayed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Takes a cfi, fragment or page?
|
||||||
|
EPUBJS.Rendition.prototype.moveTo = function(what){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Rendition.prototype.render = function(view) {
|
EPUBJS.Rendition.prototype.render = function(view) {
|
||||||
// var view = new EPUBJS.View(section);
|
// var view = new EPUBJS.View(section);
|
||||||
//
|
//
|
||||||
|
|
|
@ -54,6 +54,8 @@ EPUBJS.Spine.prototype.get = function(target) {
|
||||||
} else if(target && target.indexOf("#") === 0) {
|
} else if(target && target.indexOf("#") === 0) {
|
||||||
index = this.spineById[target.substring(1)];
|
index = this.spineById[target.substring(1)];
|
||||||
} else if(target) {
|
} else if(target) {
|
||||||
|
// Remove fragments
|
||||||
|
target = target.split("#")[0];
|
||||||
index = this.spineByHref[target];
|
index = this.spineByHref[target];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue