mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Add map for sections and pages, update queue to handle function without promise
This commit is contained in:
parent
f998e5be0a
commit
5c33f9c52b
14 changed files with 1044 additions and 93 deletions
|
@ -6,6 +6,7 @@ EPUBJS.Rendition = function(book, options) {
|
|||
width: false,
|
||||
height: false,
|
||||
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'},
|
||||
axis: "vertical"
|
||||
});
|
||||
|
||||
EPUBJS.core.extend(this.settings, options);
|
||||
|
@ -22,6 +23,7 @@ EPUBJS.Rendition = function(book, options) {
|
|||
|
||||
//-- Adds Hook methods to the Rendition prototype
|
||||
this.hooks = {};
|
||||
this.hooks.display = new EPUBJS.Hook(this);
|
||||
this.hooks.layout = new EPUBJS.Hook(this);
|
||||
this.hooks.replacements = new EPUBJS.Hook(this);
|
||||
|
||||
|
@ -174,6 +176,8 @@ EPUBJS.Rendition.prototype.display = function(what){
|
|||
// Move to correct place within the section, if needed
|
||||
// this.moveTo(what)
|
||||
|
||||
this.hooks.display.trigger(view);
|
||||
|
||||
displaying.resolve(this);
|
||||
|
||||
} else {
|
||||
|
@ -211,7 +215,11 @@ EPUBJS.Rendition.prototype.render = function(view) {
|
|||
return view.show()
|
||||
}.bind(this))
|
||||
.then(function(view){
|
||||
|
||||
// this.map = new EPUBJS.Map(view, this.layout);
|
||||
|
||||
this.trigger("rendered", view.section);
|
||||
|
||||
}.bind(this))
|
||||
.catch(function(e){
|
||||
this.trigger("loaderror", e);
|
||||
|
@ -333,7 +341,7 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
|||
|
||||
EPUBJS.Rendition.prototype.layoutMethod = function() {
|
||||
|
||||
this.layout = new EPUBJS.Layout.Scroll();
|
||||
this.layout = new EPUBJS.Layout.Scroll(this.stage.width, this.stage.height);
|
||||
|
||||
};
|
||||
|
||||
|
@ -412,6 +420,55 @@ EPUBJS.Rendition.prototype.parseLayoutProperties = function(metadata){
|
|||
};
|
||||
|
||||
|
||||
EPUBJS.Rendition.prototype.current = function(){
|
||||
var visible = this.visible();
|
||||
if(visible.length){
|
||||
// Current is the last visible view
|
||||
return visible[visible.length-1];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.isVisible = function(view, offset, _container){
|
||||
var position = view.position();
|
||||
var container = _container || this.container.getBoundingClientRect();
|
||||
|
||||
if(this.settings.axis === "horizontal" &&
|
||||
(position.right > container.left - offset) &&
|
||||
!(position.left >= container.right + offset)) {
|
||||
|
||||
return true;
|
||||
|
||||
} else if(this.settings.axis === "vertical" &&
|
||||
(position.bottom > container.top - offset) &&
|
||||
!(position.top >= container.bottom + offset)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.visible = function(){
|
||||
var container = this.container.getBoundingClientRect();
|
||||
var visible = [];
|
||||
var isVisible;
|
||||
var view;
|
||||
|
||||
for (var i = 0; i < this.views.length; i++) {
|
||||
view = this.views[i];
|
||||
isVisible = this.isVisible(view, 0, container);
|
||||
|
||||
if(isVisible === true) {
|
||||
visible.push(view);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return visible;
|
||||
|
||||
};
|
||||
|
||||
//-- Enable binding events to Renderer
|
||||
RSVP.EventTarget.mixin(EPUBJS.Rendition.prototype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue