mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Add event-emitter for node compatible events
This commit is contained in:
parent
da8d7a97cc
commit
a4e76029d4
9 changed files with 51 additions and 43 deletions
|
@ -51,6 +51,7 @@
|
|||
"webpack-dev-server": "^1.16.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"event-emitter": "^0.3.4",
|
||||
"jszip": "^3.1.1",
|
||||
"rsvp": "^3.0.18",
|
||||
"urijs": "^1.17.0",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var URI = require('urijs');
|
||||
var core = require('./core');
|
||||
var Spine = require('./spine');
|
||||
|
@ -60,7 +61,7 @@ function Book(_url, options){
|
|||
var err = new Error("Cannot load book at "+ _url );
|
||||
console.error(err);
|
||||
|
||||
this.trigger("loadFailed", error);
|
||||
this.emit("loadFailed", error);
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
@ -331,7 +332,7 @@ Book.prototype.range = function(cfiRange) {
|
|||
module.exports = Book;
|
||||
|
||||
//-- Enable binding events to book
|
||||
RSVP.EventTarget.mixin(Book.prototype);
|
||||
EventEmitter(Book.prototype);
|
||||
|
||||
//-- Handle RSVP Errors
|
||||
RSVP.on('error', function(event) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var core = require('./core');
|
||||
var EpubCFI = require('./epubcfi');
|
||||
var Mapping = require('./mapping');
|
||||
|
@ -245,7 +246,7 @@ Contents.prototype.viewport = function(options) {
|
|||
// };
|
||||
|
||||
Contents.prototype.expand = function() {
|
||||
this.trigger("expand");
|
||||
this.emit("expand");
|
||||
};
|
||||
|
||||
Contents.prototype.listeners = function() {
|
||||
|
@ -286,7 +287,7 @@ Contents.prototype.resizeListeners = function() {
|
|||
height: height
|
||||
}
|
||||
|
||||
this.trigger("resize", this._size);
|
||||
this.emit("resize", this._size);
|
||||
}
|
||||
|
||||
this.expanding = setTimeout(this.resizeListeners.bind(this), 350);
|
||||
|
@ -517,7 +518,7 @@ Contents.prototype.removeEventListeners = function(){
|
|||
|
||||
// Pass browser events
|
||||
Contents.prototype.triggerEvent = function(e){
|
||||
this.trigger(e.type, e);
|
||||
this.emit(e.type, e);
|
||||
};
|
||||
|
||||
Contents.prototype.addSelectionListeners = function(){
|
||||
|
@ -552,8 +553,8 @@ Contents.prototype.triggerSelectedEvent = function(selection){
|
|||
if(!range.collapsed) {
|
||||
// cfirange = this.section.cfiFromRange(range);
|
||||
cfirange = new EpubCFI(range, this.cfiBase).toString();
|
||||
this.trigger("selected", cfirange);
|
||||
this.trigger("selectedRange", range);
|
||||
this.emit("selected", cfirange);
|
||||
this.emit("selectedRange", range);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -659,6 +660,6 @@ Contents.prototype.destroy = function() {
|
|||
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(Contents.prototype);
|
||||
EventEmitter(Contents.prototype);
|
||||
|
||||
module.exports = Contents;
|
||||
|
|
|
@ -2,6 +2,7 @@ var core = require('./core');
|
|||
var Queue = require('./queue');
|
||||
var EpubCFI = require('./epubcfi');
|
||||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
|
||||
function Locations(spine, request) {
|
||||
this.spine = spine;
|
||||
|
@ -204,7 +205,7 @@ Locations.prototype.setCurrent = function(curr){
|
|||
loc = curr;
|
||||
}
|
||||
|
||||
this.trigger("changed", {
|
||||
this.emit("changed", {
|
||||
percentage: this.precentageFromLocation(loc)
|
||||
});
|
||||
};
|
||||
|
@ -218,6 +219,6 @@ Object.defineProperty(Locations.prototype, 'currentLocation', {
|
|||
}
|
||||
});
|
||||
|
||||
RSVP.EventTarget.mixin(Locations.prototype);
|
||||
EventEmitter(Locations.prototype);
|
||||
|
||||
module.exports = Locations;
|
||||
|
|
|
@ -105,7 +105,7 @@ ContinuousViewManager.prototype.afterDisplayed = function(currView){
|
|||
|
||||
// this.removeShownListeners(currView);
|
||||
// currView.onShown = this.afterDisplayed.bind(this);
|
||||
this.trigger("added", currView.section);
|
||||
this.emit("added", currView.section);
|
||||
|
||||
};
|
||||
*/
|
||||
|
@ -133,7 +133,7 @@ ContinuousViewManager.prototype.resize = function(width, height){
|
|||
// this.rendition.display(this.location.start);
|
||||
// }
|
||||
|
||||
this.trigger("resized", {
|
||||
this.emit("resized", {
|
||||
width: this.stage.width,
|
||||
height: this.stage.height
|
||||
});
|
||||
|
@ -151,7 +151,7 @@ ContinuousViewManager.prototype.onResized = function(e) {
|
|||
};
|
||||
|
||||
ContinuousViewManager.prototype.afterResized = function(view){
|
||||
this.trigger("resize", view.section);
|
||||
this.emit("resize", view.section);
|
||||
};
|
||||
|
||||
// Remove Previous Listeners if present
|
||||
|
@ -436,14 +436,14 @@ ContinuousViewManager.prototype.onScroll = function(){
|
|||
this.scrollDeltaVert = 0;
|
||||
this.scrollDeltaHorz = 0;
|
||||
|
||||
this.trigger("scroll", {
|
||||
this.emit("scroll", {
|
||||
top: scrollTop,
|
||||
left: scrollLeft
|
||||
});
|
||||
|
||||
clearTimeout(this.afterScrolled);
|
||||
this.afterScrolled = setTimeout(function () {
|
||||
this.trigger("scrolled", {
|
||||
this.emit("scrolled", {
|
||||
top: this.scrollTop,
|
||||
left: this.scrollLeft
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var core = require('../../core');
|
||||
var EpubCFI = require('../../epubcfi');
|
||||
var Mapping = require('../../mapping');
|
||||
|
@ -126,7 +127,7 @@ DefaultViewManager.prototype.resize = function(width, height){
|
|||
|
||||
this.updateLayout();
|
||||
|
||||
this.trigger("resized", {
|
||||
this.emit("resized", {
|
||||
width: this.stage.width,
|
||||
height: this.stage.height
|
||||
});
|
||||
|
@ -192,11 +193,11 @@ DefaultViewManager.prototype.display = function(section, target){
|
|||
};
|
||||
|
||||
DefaultViewManager.prototype.afterDisplayed = function(view){
|
||||
this.trigger("added", view);
|
||||
this.emit("added", view);
|
||||
};
|
||||
|
||||
DefaultViewManager.prototype.afterResized = function(view){
|
||||
this.trigger("resize", view.section);
|
||||
this.emit("resize", view.section);
|
||||
};
|
||||
|
||||
// DefaultViewManager.prototype.moveTo = function(offset){
|
||||
|
@ -538,6 +539,6 @@ DefaultViewManager.prototype.updateFlow = function(flow){
|
|||
};
|
||||
|
||||
//-- Enable binding events to Manager
|
||||
RSVP.EventTarget.mixin(DefaultViewManager.prototype);
|
||||
EventEmitter(DefaultViewManager.prototype);
|
||||
|
||||
module.exports = DefaultViewManager;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var core = require('../../core');
|
||||
var EpubCFI = require('../../epubcfi');
|
||||
var Contents = require('../../contents');
|
||||
|
@ -158,11 +159,11 @@ IframeView.prototype.render = function(request, show) {
|
|||
}
|
||||
// this.map = new Map(view, this.layout);
|
||||
//this.hooks.show.trigger(view, this);
|
||||
this.trigger("rendered", this.section);
|
||||
this.emit("rendered", this.section);
|
||||
|
||||
}.bind(this))
|
||||
.catch(function(e){
|
||||
this.trigger("loaderror", e);
|
||||
this.emit("loaderror", e);
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
|
@ -363,7 +364,7 @@ IframeView.prototype.reframe = function(width, height) {
|
|||
|
||||
this.onResize(this, size);
|
||||
|
||||
this.trigger("resized", size);
|
||||
this.emit("resized", size);
|
||||
|
||||
};
|
||||
|
||||
|
@ -483,7 +484,7 @@ IframeView.prototype.display = function(request) {
|
|||
|
||||
this.render(request).then(function () {
|
||||
|
||||
this.trigger("displayed", this);
|
||||
this.emit("displayed", this);
|
||||
this.onDisplayed(this);
|
||||
|
||||
this.displayed = true;
|
||||
|
@ -507,7 +508,7 @@ IframeView.prototype.show = function() {
|
|||
this.iframe.style.visibility = "visible";
|
||||
}
|
||||
|
||||
this.trigger("shown", this);
|
||||
this.emit("shown", this);
|
||||
};
|
||||
|
||||
IframeView.prototype.hide = function() {
|
||||
|
@ -516,7 +517,7 @@ IframeView.prototype.hide = function() {
|
|||
this.iframe.style.visibility = "hidden";
|
||||
|
||||
this.stopExpanding = true;
|
||||
this.trigger("hidden", this);
|
||||
this.emit("hidden", this);
|
||||
};
|
||||
|
||||
IframeView.prototype.position = function() {
|
||||
|
@ -569,6 +570,6 @@ IframeView.prototype.destroy = function() {
|
|||
// this.element.style.width = "0px";
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(IframeView.prototype);
|
||||
EventEmitter(IframeView.prototype);
|
||||
|
||||
module.exports = IframeView;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var core = require('../../core');
|
||||
var EpubCFI = require('../../epubcfi');
|
||||
var Contents = require('../../contents');
|
||||
|
@ -148,11 +149,11 @@ InlineView.prototype.render = function(request, show) {
|
|||
}
|
||||
// this.map = new Map(view, this.layout);
|
||||
//this.hooks.show.trigger(view, this);
|
||||
this.trigger("rendered", this.section);
|
||||
this.emit("rendered", this.section);
|
||||
|
||||
}.bind(this))
|
||||
.catch(function(e){
|
||||
this.trigger("loaderror", e);
|
||||
this.emit("loaderror", e);
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
|
@ -271,7 +272,7 @@ InlineView.prototype.resize = function(width, height) {
|
|||
|
||||
this.onResize(this, size);
|
||||
|
||||
this.trigger("resized", size);
|
||||
this.emit("resized", size);
|
||||
|
||||
};
|
||||
|
||||
|
@ -337,7 +338,7 @@ InlineView.prototype.display = function(request) {
|
|||
|
||||
this.render(request).then(function () {
|
||||
|
||||
this.trigger("displayed", this);
|
||||
this.emit("displayed", this);
|
||||
this.onDisplayed(this);
|
||||
|
||||
this.displayed = true;
|
||||
|
@ -362,7 +363,7 @@ InlineView.prototype.show = function() {
|
|||
this.frame.style.visibility = "visible";
|
||||
}
|
||||
|
||||
this.trigger("shown", this);
|
||||
this.emit("shown", this);
|
||||
};
|
||||
|
||||
InlineView.prototype.hide = function() {
|
||||
|
@ -371,7 +372,7 @@ InlineView.prototype.hide = function() {
|
|||
this.frame.style.visibility = "hidden";
|
||||
|
||||
this.stopExpanding = true;
|
||||
this.trigger("hidden", this);
|
||||
this.emit("hidden", this);
|
||||
};
|
||||
|
||||
InlineView.prototype.position = function() {
|
||||
|
@ -424,6 +425,6 @@ InlineView.prototype.destroy = function() {
|
|||
// this.element.style.width = "0px";
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(InlineView.prototype);
|
||||
EventEmitter(InlineView.prototype);
|
||||
|
||||
module.exports = InlineView;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var RSVP = require('rsvp');
|
||||
var EventEmitter = require('event-emitter');
|
||||
var URI = require('urijs');
|
||||
var core = require('./core');
|
||||
var replace = require('./replacements');
|
||||
|
@ -131,7 +132,7 @@ Rendition.prototype.start = function(){
|
|||
this.on('displayed', this.reportLocation.bind(this));
|
||||
|
||||
// Trigger that rendering has started
|
||||
this.trigger("started");
|
||||
this.emit("started");
|
||||
|
||||
// Start processing queue
|
||||
// this.starting.resolve();
|
||||
|
@ -150,7 +151,7 @@ Rendition.prototype.attachTo = function(element){
|
|||
});
|
||||
|
||||
// Trigger Attached
|
||||
this.trigger("attached");
|
||||
this.emit("attached");
|
||||
|
||||
}.bind(this));
|
||||
|
||||
|
@ -194,7 +195,7 @@ Rendition.prototype._display = function(target){
|
|||
|
||||
return this.manager.display(section, moveTo)
|
||||
.then(function(){
|
||||
this.trigger("displayed", section);
|
||||
this.emit("displayed", section);
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
|
@ -246,7 +247,7 @@ Rendition.prototype.render = function(view, show) {
|
|||
|
||||
Rendition.prototype.afterDisplayed = function(view){
|
||||
this.hooks.content.trigger(view, this);
|
||||
this.trigger("rendered", view.section);
|
||||
this.emit("rendered", view.section);
|
||||
this.reportLocation();
|
||||
};
|
||||
|
||||
|
@ -256,7 +257,7 @@ Rendition.prototype.onResized = function(size){
|
|||
this.display(this.location.start);
|
||||
}
|
||||
|
||||
this.trigger("resized", {
|
||||
this.emit("resized", {
|
||||
width: size.width,
|
||||
height: size.height
|
||||
});
|
||||
|
@ -365,11 +366,11 @@ Rendition.prototype.reportLocation = function(){
|
|||
if (location && location.then && typeof location.then === 'function') {
|
||||
location.then(function(result) {
|
||||
this.location = result;
|
||||
this.trigger("locationChanged", this.location);
|
||||
this.emit("locationChanged", this.location);
|
||||
}.bind(this));
|
||||
} else if (location) {
|
||||
this.location = location;
|
||||
this.trigger("locationChanged", this.location);
|
||||
this.emit("locationChanged", this.location);
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
|
@ -392,11 +393,11 @@ Rendition.prototype.passViewEvents = function(view){
|
|||
};
|
||||
|
||||
Rendition.prototype.triggerViewEvent = function(e){
|
||||
this.trigger(e.type, e);
|
||||
this.emit(e.type, e);
|
||||
};
|
||||
|
||||
Rendition.prototype.triggerSelectedEvent = function(cfirange){
|
||||
this.trigger("selected", cfirange);
|
||||
this.emit("selected", cfirange);
|
||||
};
|
||||
|
||||
Rendition.prototype.replacements = function(){
|
||||
|
@ -563,6 +564,6 @@ Rendition.prototype.adjustImages = function(view) {
|
|||
};
|
||||
|
||||
//-- Enable binding events to Renderer
|
||||
RSVP.EventTarget.mixin(Rendition.prototype);
|
||||
EventEmitter(Rendition.prototype);
|
||||
|
||||
module.exports = Rendition;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue