mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Tabify src
This commit is contained in:
parent
f6247e5612
commit
32993dc58c
31 changed files with 7759 additions and 7758 deletions
52
src/hook.js
52
src/hook.js
|
@ -9,51 +9,51 @@ var RSVP = require('rsvp');
|
|||
// this.content.trigger(args).then(function(){});
|
||||
|
||||
function Hook(context){
|
||||
this.context = context || this;
|
||||
this.hooks = [];
|
||||
this.context = context || this;
|
||||
this.hooks = [];
|
||||
};
|
||||
|
||||
// Adds a function to be run before a hook completes
|
||||
Hook.prototype.register = function(){
|
||||
for(var i = 0; i < arguments.length; ++i) {
|
||||
if (typeof arguments[i] === "function") {
|
||||
this.hooks.push(arguments[i]);
|
||||
} else {
|
||||
// unpack array
|
||||
for(var j = 0; j < arguments[i].length; ++j) {
|
||||
this.hooks.push(arguments[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(var i = 0; i < arguments.length; ++i) {
|
||||
if (typeof arguments[i] === "function") {
|
||||
this.hooks.push(arguments[i]);
|
||||
} else {
|
||||
// unpack array
|
||||
for(var j = 0; j < arguments[i].length; ++j) {
|
||||
this.hooks.push(arguments[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Triggers a hook to run all functions
|
||||
Hook.prototype.trigger = function(){
|
||||
var args = arguments;
|
||||
var context = this.context;
|
||||
var promises = [];
|
||||
var args = arguments;
|
||||
var context = this.context;
|
||||
var promises = [];
|
||||
|
||||
this.hooks.forEach(function(task, i) {
|
||||
var executing = task.apply(context, args);
|
||||
this.hooks.forEach(function(task, i) {
|
||||
var executing = task.apply(context, args);
|
||||
|
||||
if(executing && typeof executing["then"] === "function") {
|
||||
// Task is a function that returns a promise
|
||||
promises.push(executing);
|
||||
}
|
||||
// Otherwise Task resolves immediately, continue
|
||||
});
|
||||
if(executing && typeof executing["then"] === "function") {
|
||||
// Task is a function that returns a promise
|
||||
promises.push(executing);
|
||||
}
|
||||
// Otherwise Task resolves immediately, continue
|
||||
});
|
||||
|
||||
|
||||
return RSVP.all(promises);
|
||||
return RSVP.all(promises);
|
||||
};
|
||||
|
||||
// Adds a function to be run before a hook completes
|
||||
Hook.prototype.list = function(){
|
||||
return this.hooks;
|
||||
return this.hooks;
|
||||
};
|
||||
|
||||
Hook.prototype.clear = function(){
|
||||
return this.hooks = [];
|
||||
return this.hooks = [];
|
||||
};
|
||||
|
||||
module.exports = Hook;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue