1
0
Fork 0
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:
fchasen 2014-12-04 19:58:07 -05:00
parent ee19c03287
commit 338bc64884
5 changed files with 1540 additions and 2092 deletions

3536
dist/epub.js vendored

File diff suppressed because it is too large Load diff

6
dist/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -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];
} }
if(typeof task === "function"){
deferred = new RSVP.defer();
promise = deferred.promise;
queued = {
"task" : task,
"args" : args,
"context" : context,
"deferred" : deferred,
"promise" : promise
};
} else {
// Task is a promise
queued = {
"promise" : task
};
}
this._q.push(queued);
this._q.push({
"task" : task, return queued.promise;
"args" : args,
"context" : context
});
return this._q;
}; };
// 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));
}; };

View file

@ -143,41 +143,29 @@ 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; return this.q.enqueue(this.load, what);
// Check for fragments
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;
var section = this.book.spine.get(what); var section = this.book.spine.get(what);
var view; var view;
this.displaying = true; this.displaying = true;
if(section){ if(section){
view = new EPUBJS.View(section); view = new EPUBJS.View(section);
// Clear views
// this.clear(); // This will clear all previous views
this.fill(view); this.fill(view);
// rendered = this.render(section);
// Move to correct place within the section, if needed
// this.moveTo(what)
// if(this.settings.infinite) {
// rendered.then(function(){
// return this.fill.call(this);
// }.bind(this));
// }
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);
// //

View file

@ -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];
} }