1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

basic scrolling renderer

This commit is contained in:
Fred Chasen 2014-07-31 17:25:56 -04:00
parent 849625fc83
commit b1b98f9d57
15 changed files with 1020 additions and 22 deletions

70
lib/epubjs/listeners.js Normal file
View file

@ -0,0 +1,70 @@
EPUBJS.Renderer.prototype.listeners = function(){
// Dom events to listen for
this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"];
this.upEvent = "mouseup";
this.downEvent = "mousedown";
if('ontouchstart' in document.documentElement) {
this.listenedEvents.push("touchstart", "touchend");
this.upEvent = "touchend";
this.downEvent = "touchstart";
}
// Resize events
// this.resized = _.debounce(this.onResized.bind(this), 100);
};
//-- Listeners for events in the frame
EPUBJS.Renderer.prototype.onResized = function(e) {
var width = this.container.clientWidth;
var height = this.container.clientHeight;
this.resize(width, height, false);
};
EPUBJS.Renderer.prototype.addEventListeners = function(){
if(!this.render.document) {
return;
}
this.listenedEvents.forEach(function(eventName){
this.render.document.addEventListener(eventName, this.triggerEvent.bind(this), false);
}, this);
};
EPUBJS.Renderer.prototype.removeEventListeners = function(){
if(!this.render.document) {
return;
}
this.listenedEvents.forEach(function(eventName){
this.render.document.removeEventListener(eventName, this.triggerEvent, false);
}, this);
};
// Pass browser events
EPUBJS.Renderer.prototype.triggerEvent = function(e){
this.trigger("renderer:"+e.type, e);
};
EPUBJS.Renderer.prototype.addSelectionListeners = function(){
this.render.document.addEventListener("selectionchange", this.onSelectionChange.bind(this), false);
};
EPUBJS.Renderer.prototype.removeSelectionListeners = function(){
if(!this.render.document) {
return;
}
this.doc.removeEventListener("selectionchange", this.onSelectionChange, false);
};
EPUBJS.Renderer.prototype.onSelectionChange = function(e){
if (this.selectionEndTimeout) {
clearTimeout(this.selectionEndTimeout);
}
this.selectionEndTimeout = setTimeout(function() {
this.selectedRange = this.render.window.getSelection();
this.trigger("renderer:selected", this.selectedRange);
}.bind(this), 500);
};