mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
split up layout functions into format and page calculate
This commit is contained in:
parent
0b6d852586
commit
c7b35c51fb
13 changed files with 317 additions and 219 deletions
212
build/epub.js
212
build/epub.js
|
@ -1711,7 +1711,7 @@ global.RSVP = requireModule('rsvp');
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var EPUBJS = EPUBJS || {};
|
var EPUBJS = EPUBJS || {};
|
||||||
EPUBJS.VERSION = "0.1.9";
|
EPUBJS.VERSION = "0.2.0";
|
||||||
|
|
||||||
EPUBJS.plugins = EPUBJS.plugins || {};
|
EPUBJS.plugins = EPUBJS.plugins || {};
|
||||||
|
|
||||||
|
@ -1789,8 +1789,7 @@ EPUBJS.Book = function(options){
|
||||||
contained : false,
|
contained : false,
|
||||||
width : null,
|
width : null,
|
||||||
height: null,
|
height: null,
|
||||||
spread: null,
|
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'}
|
||||||
layout : null,
|
|
||||||
orientation : null,
|
orientation : null,
|
||||||
minSpreadWidth: 800, //-- overridden by spread: none (never) / both (always)
|
minSpreadWidth: 800, //-- overridden by spread: none (never) / both (always)
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -1800,7 +1799,7 @@ EPUBJS.Book = function(options){
|
||||||
styles : {},
|
styles : {},
|
||||||
headTags : {},
|
headTags : {},
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
renderer: "Iframe"
|
render_method: "Iframe"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
||||||
|
@ -1864,7 +1863,7 @@ EPUBJS.Book = function(options){
|
||||||
* Creates a new renderer.
|
* Creates a new renderer.
|
||||||
* The renderer will handle displaying the content using the method provided in the settings
|
* The renderer will handle displaying the content using the method provided in the settings
|
||||||
*/
|
*/
|
||||||
this.renderer = new EPUBJS.Renderer(this.settings.renderer);
|
this.renderer = new EPUBJS.Renderer(this.settings.render_method);
|
||||||
//-- Set the width at which to switch from spreads to single pages
|
//-- Set the width at which to switch from spreads to single pages
|
||||||
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
||||||
//-- Pass through the renderer events
|
//-- Pass through the renderer events
|
||||||
|
@ -2221,7 +2220,7 @@ EPUBJS.Book.prototype.startDisplay = function(){
|
||||||
EPUBJS.Book.prototype.restore = function(identifier){
|
EPUBJS.Book.prototype.restore = function(identifier){
|
||||||
|
|
||||||
var book = this,
|
var book = this,
|
||||||
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'],
|
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL', 'globalLayoutProperties'],
|
||||||
reject = false,
|
reject = false,
|
||||||
bookKey = this.generateBookKey(identifier),
|
bookKey = this.generateBookKey(identifier),
|
||||||
fromStore = localStorage.getItem(bookKey),
|
fromStore = localStorage.getItem(bookKey),
|
||||||
|
@ -2536,18 +2535,19 @@ EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.useSpreads = function(use) {
|
EPUBJS.Book.prototype.useSpreads = function(use) {
|
||||||
if(use) {
|
console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead");
|
||||||
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
if(use === false) {
|
||||||
this.settings.spreads = true;
|
this.forceSingle(true);
|
||||||
} else {
|
} else {
|
||||||
this.renderer.setMinSpreadWidth(0);
|
this.forceSingle(false);
|
||||||
this.settings.spreads = false;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.forceSingle = function(use) {
|
||||||
|
this.renderer.forceSingle(use);
|
||||||
if(this.isRendered) {
|
if(this.isRendered) {
|
||||||
this.renderer.reformat();
|
this.renderer.reformat();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.unload = function(){
|
EPUBJS.Book.prototype.unload = function(){
|
||||||
|
@ -2654,9 +2654,9 @@ EPUBJS.Book.prototype._needsAssetReplacement = function(){
|
||||||
|
|
||||||
//-- http://www.idpf.org/epub/fxl/
|
//-- http://www.idpf.org/epub/fxl/
|
||||||
EPUBJS.Book.prototype.parseLayoutProperties = function(metadata){
|
EPUBJS.Book.prototype.parseLayoutProperties = function(metadata){
|
||||||
var layout = this.settings.layout || metadata.layout || "reflowable";
|
var layout = (this.layoutOveride && this.layoutOveride.layout) || metadata.layout || "reflowable";
|
||||||
var spread = this.settings.spread || metadata.spread || "auto";
|
var spread = (this.layoutOveride && this.layoutOveride.spread) || metadata.spread || "auto";
|
||||||
var orientation = this.settings.orientations || metadata.orientation || "auto";
|
var orientation = (this.layoutOveride && this.layoutOveride.orientation) || metadata.orientation || "auto";
|
||||||
return {
|
return {
|
||||||
layout : layout,
|
layout : layout,
|
||||||
spread : spread,
|
spread : spread,
|
||||||
|
@ -3376,7 +3376,12 @@ EPUBJS.Hooks = (function(){
|
||||||
|
|
||||||
EPUBJS.Layout = EPUBJS.Layout || {};
|
EPUBJS.Layout = EPUBJS.Layout || {};
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
EPUBJS.Layout.Reflowable = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
this.spreadWidth = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _height){
|
||||||
// Get the prefixed CSS commands
|
// Get the prefixed CSS commands
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
|
@ -3387,9 +3392,9 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
||||||
var section = Math.ceil(width / 8);
|
var section = Math.ceil(width / 8);
|
||||||
var gap = (section % 2 === 0) ? section : section - 1;
|
var gap = (section % 2 === 0) ? section : section - 1;
|
||||||
|
|
||||||
|
this.documentElement = documentElement;
|
||||||
//-- Single Page
|
//-- Single Page
|
||||||
var spreadWidth = (width + gap);
|
this.spreadWidth = (width + gap);
|
||||||
var totalWidth, displayedPages;
|
|
||||||
|
|
||||||
documentElement.style.width = "auto"; //-- reset width for calculations
|
documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
|
||||||
|
@ -3405,19 +3410,30 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
||||||
|
|
||||||
documentElement.style.width = width + "px";
|
documentElement.style.width = width + "px";
|
||||||
|
|
||||||
|
return {
|
||||||
|
pageWidth : this.spreadWidth,
|
||||||
|
pageHeight : _height
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
totalWidth = documentElement.scrollWidth;
|
EPUBJS.Layout.Reflowable.prototype.calculatePages = function() {
|
||||||
displayedPages = Math.round(totalWidth / spreadWidth);
|
var totalWidth, displayedPages;
|
||||||
|
this.documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
totalWidth = this.documentElement.scrollWidth;
|
||||||
|
displayedPages = Math.round(totalWidth / this.spreadWidth);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : spreadWidth,
|
|
||||||
pageHeight : _height,
|
|
||||||
displayedPages : displayedPages,
|
displayedPages : displayedPages,
|
||||||
pageCount : displayedPages
|
pageCount : displayedPages
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
EPUBJS.Layout.ReflowableSpreads = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
this.spreadWidth = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.ReflowableSpreads.prototype.format = function(documentElement, _width, _height){
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
|
@ -3432,15 +3448,16 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
||||||
|
|
||||||
//-- Double Page
|
//-- Double Page
|
||||||
var colWidth = Math.floor((width - gap) / divisor);
|
var colWidth = Math.floor((width - gap) / divisor);
|
||||||
var spreadWidth = (colWidth + gap) * divisor;
|
|
||||||
|
|
||||||
var totalWidth, displayedPages;
|
this.documentElement = documentElement;
|
||||||
|
this.spreadWidth = (colWidth + gap) * divisor;
|
||||||
|
|
||||||
|
|
||||||
documentElement.style.width = "auto"; //-- reset width for calculations
|
documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
|
||||||
documentElement.style.overflow = "hidden";
|
documentElement.style.overflow = "hidden";
|
||||||
|
|
||||||
documentElement.style.width = width + "px";
|
//documentElement.style.width = width + "px";
|
||||||
|
|
||||||
//-- Adjust height
|
//-- Adjust height
|
||||||
documentElement.style.height = _height + "px";
|
documentElement.style.height = _height + "px";
|
||||||
|
@ -3450,20 +3467,29 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
||||||
documentElement.style[columnGap] = gap+"px";
|
documentElement.style[columnGap] = gap+"px";
|
||||||
documentElement.style[columnWidth] = colWidth+"px";
|
documentElement.style[columnWidth] = colWidth+"px";
|
||||||
|
|
||||||
totalWidth = documentElement.scrollWidth;
|
return {
|
||||||
displayedPages = Math.ceil(totalWidth / spreadWidth);
|
pageWidth : this.spreadWidth,
|
||||||
|
pageHeight : _height
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function() {
|
||||||
|
var totalWidth = this.documentElement.scrollWidth;
|
||||||
|
var displayedPages = Math.round(totalWidth / this.spreadWidth);
|
||||||
|
|
||||||
//-- Add a page to the width of the document to account an for odd number of pages
|
//-- Add a page to the width of the document to account an for odd number of pages
|
||||||
documentElement.style.width = totalWidth + spreadWidth + "px";
|
this.documentElement.style.width = totalWidth + this.spreadWidth + "px";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : spreadWidth,
|
|
||||||
pageHeight : _height,
|
|
||||||
displayedPages : displayedPages,
|
displayedPages : displayedPages,
|
||||||
pageCount : displayedPages * 2
|
pageCount : displayedPages * 2
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
var viewport = documentElement.querySelector("[name=viewport");
|
var viewport = documentElement.querySelector("[name=viewport");
|
||||||
|
@ -3471,6 +3497,7 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
var contents;
|
var contents;
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
this.documentElement = documentElement;
|
||||||
/**
|
/**
|
||||||
* check for the viewport size
|
* check for the viewport size
|
||||||
* <meta name="viewport" content="width=1024,height=697" />
|
* <meta name="viewport" content="width=1024,height=697" />
|
||||||
|
@ -3499,11 +3526,16 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : width,
|
pageWidth : width,
|
||||||
pageHeight : height,
|
pageHeight : height
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
|
||||||
|
return {
|
||||||
displayedPages : 1,
|
displayedPages : 1,
|
||||||
pageCount : 1
|
pageCount : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Parser = function(baseUrl){
|
EPUBJS.Parser = function(baseUrl){
|
||||||
|
@ -3727,11 +3759,12 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
|
||||||
items.forEach(function(item, index){
|
items.forEach(function(item, index){
|
||||||
var Id = item.getAttribute('idref');
|
var Id = item.getAttribute('idref');
|
||||||
var cfiBase = epubcfi.generateChapter(spineNodeIndex, index, Id);
|
var cfiBase = epubcfi.generateChapter(spineNodeIndex, index, Id);
|
||||||
|
var props = item.getAttribute('properties') || '';
|
||||||
var vert = {
|
var vert = {
|
||||||
'id' : Id,
|
'id' : Id,
|
||||||
'linear' : item.getAttribute('linear') || '',
|
'linear' : item.getAttribute('linear') || '',
|
||||||
'properties' : item.getAttribute('properties') || '',
|
'properties' : props.split(' '),
|
||||||
'manifestProperties' : manifest[Id].properties || '',
|
'manifestProperties' : manifest[Id].properties.split(' '),
|
||||||
'href' : manifest[Id].href,
|
'href' : manifest[Id].href,
|
||||||
'url' : manifest[Id].url,
|
'url' : manifest[Id].url,
|
||||||
'index' : index,
|
'index' : index,
|
||||||
|
@ -4065,7 +4098,7 @@ EPUBJS.Render.Iframe.prototype.scroll = function(bool){
|
||||||
EPUBJS.Render.Iframe.prototype.unload = function(){
|
EPUBJS.Render.Iframe.prototype.unload = function(){
|
||||||
this.window.removeEventListener("resize", this.resized);
|
this.window.removeEventListener("resize", this.resized);
|
||||||
};
|
};
|
||||||
EPUBJS.Renderer = function(type) {
|
EPUBJS.Renderer = function(renderMethod) {
|
||||||
// Dom events to listen for
|
// Dom events to listen for
|
||||||
this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"];
|
this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"];
|
||||||
|
|
||||||
|
@ -4073,8 +4106,8 @@ EPUBJS.Renderer = function(type) {
|
||||||
* Setup a render method.
|
* Setup a render method.
|
||||||
* Options are: Iframe
|
* Options are: Iframe
|
||||||
*/
|
*/
|
||||||
if(type && typeof(EPUBJS.Render[type]) != "undefined"){
|
if(renderMethod && typeof(EPUBJS.Render[renderMethod]) != "undefined"){
|
||||||
this.render = new EPUBJS.Render[type]();
|
this.render = new EPUBJS.Render[renderMethod]();
|
||||||
} else {
|
} else {
|
||||||
console.error("Not a Valid Rendering Method");
|
console.error("Not a Valid Rendering Method");
|
||||||
}
|
}
|
||||||
|
@ -4086,8 +4119,11 @@ EPUBJS.Renderer = function(type) {
|
||||||
this.epubcfi = new EPUBJS.EpubCFI();
|
this.epubcfi = new EPUBJS.EpubCFI();
|
||||||
|
|
||||||
this.spreads = true;
|
this.spreads = true;
|
||||||
|
this.isForcedSingle = false;
|
||||||
this.resized = _.throttle(this.onResized.bind(this), 10);
|
this.resized = _.throttle(this.onResized.bind(this), 10);
|
||||||
|
|
||||||
|
this.layoutSettings = {};
|
||||||
|
|
||||||
//-- Adds Hook methods to the Book prototype
|
//-- Adds Hook methods to the Book prototype
|
||||||
// Hooks will all return before triggering the callback.
|
// Hooks will all return before triggering the callback.
|
||||||
EPUBJS.Hooks.mixin(this);
|
EPUBJS.Hooks.mixin(this);
|
||||||
|
@ -4158,7 +4194,7 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
||||||
|
|
||||||
this.currentChapterCfiBase = chapter.cfiBase;
|
this.currentChapterCfiBase = chapter.cfiBase;
|
||||||
|
|
||||||
this.settings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||||
|
|
||||||
// Get the url string from the chapter (may be from storage)
|
// Get the url string from the chapter (may be from storage)
|
||||||
return chapter.url().
|
return chapter.url().
|
||||||
|
@ -4178,16 +4214,24 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
var deferred = new RSVP.defer();
|
var deferred = new RSVP.defer();
|
||||||
var loaded;
|
var loaded;
|
||||||
|
|
||||||
this.layoutMethod = this.determineLayout(this.settings);
|
// Switch to the required layout method for the settings
|
||||||
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
|
|
||||||
this.visible(false);
|
this.visible(false);
|
||||||
|
|
||||||
loaded = this.render.load(url);
|
loaded = this.render.load(url);
|
||||||
|
|
||||||
loaded.then(function(contents) {
|
loaded.then(function(contents) {
|
||||||
|
var formated;
|
||||||
|
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
this.doc = this.render.document;
|
this.doc = this.render.document;
|
||||||
|
|
||||||
|
// Format the contents using the current layout method
|
||||||
|
formated = this.layout.format(contents, this.render.width, this.render.height);
|
||||||
|
this.render.setPageDimensions(formated.pageWidth, formated.pageHeight);
|
||||||
|
|
||||||
if(!this.initWidth && !this.initHeight){
|
if(!this.initWidth && !this.initHeight){
|
||||||
this.render.window.addEventListener("resize", this.resized, false);
|
this.render.window.addEventListener("resize", this.resized, false);
|
||||||
}
|
}
|
||||||
|
@ -4197,6 +4241,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
|
|
||||||
//-- Trigger registered hooks before displaying
|
//-- Trigger registered hooks before displaying
|
||||||
this.beforeDisplay(function(){
|
this.beforeDisplay(function(){
|
||||||
|
var pages = this.layout.calculatePages();
|
||||||
var msg = this.currentChapter;
|
var msg = this.currentChapter;
|
||||||
|
|
||||||
msg.cfi = this.currentLocationCfi = this.getPageCfi();
|
msg.cfi = this.currentLocationCfi = this.getPageCfi();
|
||||||
|
@ -4204,8 +4249,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
this.trigger("renderer:chapterDisplayed", msg);
|
this.trigger("renderer:chapterDisplayed", msg);
|
||||||
this.trigger("renderer:pageChanged", this.currentLocationCfi);
|
this.trigger("renderer:pageChanged", this.currentLocationCfi);
|
||||||
|
|
||||||
this.layout = this.layoutMethod(contents, this.render.width, this.render.height);
|
this.updatePages(pages);
|
||||||
this.updatePages(this.layout);
|
|
||||||
|
|
||||||
this.visible(true);
|
this.visible(true);
|
||||||
|
|
||||||
|
@ -4224,10 +4268,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
* Returns: Object with layout properties
|
* Returns: Object with layout properties
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
var layoutMethod = "ReflowableSpreads"; // Default to Spreads
|
|
||||||
var properties = chapter.split(' ');
|
|
||||||
var settings = {};
|
var settings = {};
|
||||||
var spreads = true;
|
|
||||||
|
|
||||||
//-- Get the global defaults
|
//-- Get the global defaults
|
||||||
for (var attr in global) {
|
for (var attr in global) {
|
||||||
|
@ -4236,7 +4277,7 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-- Get the chapter's display type
|
//-- Get the chapter's display type
|
||||||
properties.forEach(function(prop){
|
chapter.forEach(function(prop){
|
||||||
var rendition = prop.replace("rendition:", '');
|
var rendition = prop.replace("rendition:", '');
|
||||||
var split = rendition.indexOf("-");
|
var split = rendition.indexOf("-");
|
||||||
var property, value;
|
var property, value;
|
||||||
|
@ -4254,47 +4295,38 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the settings to determine which Layout Method is needed
|
* Uses the settings to determine which Layout Method is needed
|
||||||
|
* Triggers events based on the method choosen
|
||||||
* Takes: Layout settings object
|
* Takes: Layout settings object
|
||||||
* Returns: EPUBJS.Layout function
|
* Returns: String of appropriate for EPUBJS.Layout function
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
||||||
var layoutMethod = "ReflowableSpreads";
|
// Default is layout: reflowable & spread: auto
|
||||||
|
var spreads = this.determineSpreads(this.minSpreadWidth);
|
||||||
|
var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
|
||||||
|
var scroll = false;
|
||||||
|
|
||||||
if(settings.layout === "pre-paginated") {
|
if(settings.layout === "pre-paginated") {
|
||||||
layoutMethod = "Fixed";
|
layoutMethod = "Fixed";
|
||||||
this.render.scroll(true);
|
scroll = true;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
spreads = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.layout === "reflowable" && settings.spread === "none") {
|
if(settings.layout === "reflowable" && settings.spread === "none") {
|
||||||
layoutMethod = "Reflowable";
|
layoutMethod = "Reflowable";
|
||||||
this.render.scroll(false);
|
scroll = false;
|
||||||
this.trigger("renderer:spreads", false);
|
spreads = false;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.layout === "reflowable" && settings.spread === "both") {
|
if(settings.layout === "reflowable" && settings.spread === "both") {
|
||||||
layoutMethod = "ReflowableSpreads";
|
layoutMethod = "ReflowableSpreads";
|
||||||
this.render.scroll(false);
|
scroll = false;
|
||||||
this.trigger("renderer:spreads", true);
|
spreads = true;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reflowable Auto adjustments for width
|
this.spreads = spreads;
|
||||||
if(settings.layout === "reflowable" && settings.spread === "auto"){
|
this.render.scroll(scroll);
|
||||||
spreads = this.determineSpreads(this.minSpreadWidth);
|
this.trigger("renderer:spreads", spreads);
|
||||||
if(spreads){
|
return layoutMethod;
|
||||||
layoutMethod = "ReflowableSpreads";
|
|
||||||
this.trigger("renderer:spreads", true);
|
|
||||||
} else {
|
|
||||||
layoutMethod = "Reflowable";
|
|
||||||
this.trigger("renderer:spreads", false);
|
|
||||||
}
|
|
||||||
this.render.scroll(false);
|
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shortcut to trigger the hook before displaying the chapter
|
// Shortcut to trigger the hook before displaying the chapter
|
||||||
|
@ -4305,25 +4337,29 @@ EPUBJS.Renderer.prototype.beforeDisplay = function(callback, renderer){
|
||||||
// Update the renderer with the information passed by the layout
|
// Update the renderer with the information passed by the layout
|
||||||
EPUBJS.Renderer.prototype.updatePages = function(layout){
|
EPUBJS.Renderer.prototype.updatePages = function(layout){
|
||||||
this.displayedPages = layout.displayedPages;
|
this.displayedPages = layout.displayedPages;
|
||||||
this.currentChapter.pages = layout.displayedPages;
|
this.currentChapter.pages = layout.pageCount;
|
||||||
this.render.setPageDimensions(layout.pageWidth, layout.pageHeight);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the layout again and jump back to the previous cfi position
|
// Apply the layout again and jump back to the previous cfi position
|
||||||
EPUBJS.Renderer.prototype.reformat = function(){
|
EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
var renderer = this;
|
var renderer = this;
|
||||||
|
var formated, pages;
|
||||||
if(!this.contents) return;
|
if(!this.contents) return;
|
||||||
|
|
||||||
this.layout = this.layoutMethod(this.contents, this.render.width, this.render.height);
|
formated = this.layout.format(this.contents, this.render.width, this.render.height);
|
||||||
this.updatePages(this.layout);
|
this.render.setPageDimensions(formated.pageWidth, formated.pageHeight);
|
||||||
|
|
||||||
setTimeout(function(){
|
pages = renderer.layout.calculatePages();
|
||||||
|
renderer.updatePages(pages);
|
||||||
|
|
||||||
|
// Give the css styles time to update
|
||||||
|
clearTimeout(this.timeoutTillCfi);
|
||||||
|
this.timeoutTillCfi = setTimeout(function(){
|
||||||
//-- Go to current page after formating
|
//-- Go to current page after formating
|
||||||
if(renderer.currentLocationCfi){
|
if(renderer.currentLocationCfi){
|
||||||
renderer.gotoCfi(renderer.currentLocationCfi);
|
renderer.gotoCfi(renderer.currentLocationCfi);
|
||||||
}
|
}
|
||||||
|
this.timeoutTillCfi = null;
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -4547,7 +4583,8 @@ EPUBJS.Renderer.prototype.onResized = function(e){
|
||||||
// Only re-layout if the spreads have switched
|
// Only re-layout if the spreads have switched
|
||||||
if(spreads != this.spreads){
|
if(spreads != this.spreads){
|
||||||
this.spreads = spreads;
|
this.spreads = spreads;
|
||||||
this.layoutMethod = this.determineLayout(this.settings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.contents){
|
if(this.contents){
|
||||||
|
@ -4611,16 +4648,27 @@ EPUBJS.Renderer.prototype.onMouseUp = function(e){
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){
|
EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){
|
||||||
this.minSpreadWidth = width;
|
this.minSpreadWidth = width;
|
||||||
|
this.spreads = this.determineSpreads(width);
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
||||||
if(this.width < cutoff || !cutoff) {
|
if(this.isForcedSingle || !cutoff || this.width < cutoff) {
|
||||||
return false; //-- Single Page
|
return false; //-- Single Page
|
||||||
}else{
|
}else{
|
||||||
return true; //-- Double Page
|
return true; //-- Double Page
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Renderer.prototype.forceSingle = function(bool){
|
||||||
|
if(bool) {
|
||||||
|
this.isForcedSingle = true;
|
||||||
|
this.spreads = false;
|
||||||
|
} else {
|
||||||
|
this.isForcedSingle = false;
|
||||||
|
this.spreads = this.determineSpreads(width);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//-- Content Replacements
|
//-- Content Replacements
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
||||||
|
|
6
build/epub.min.js
vendored
6
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1710,7 +1710,7 @@ global.RSVP = requireModule('rsvp');
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var EPUBJS = EPUBJS || {};
|
var EPUBJS = EPUBJS || {};
|
||||||
EPUBJS.VERSION = "0.1.9";
|
EPUBJS.VERSION = "0.2.0";
|
||||||
|
|
||||||
EPUBJS.plugins = EPUBJS.plugins || {};
|
EPUBJS.plugins = EPUBJS.plugins || {};
|
||||||
|
|
||||||
|
@ -1788,8 +1788,7 @@ EPUBJS.Book = function(options){
|
||||||
contained : false,
|
contained : false,
|
||||||
width : null,
|
width : null,
|
||||||
height: null,
|
height: null,
|
||||||
spread: null,
|
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'}
|
||||||
layout : null,
|
|
||||||
orientation : null,
|
orientation : null,
|
||||||
minSpreadWidth: 800, //-- overridden by spread: none (never) / both (always)
|
minSpreadWidth: 800, //-- overridden by spread: none (never) / both (always)
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -1799,7 +1798,7 @@ EPUBJS.Book = function(options){
|
||||||
styles : {},
|
styles : {},
|
||||||
headTags : {},
|
headTags : {},
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
renderer: "Iframe"
|
render_method: "Iframe"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
||||||
|
@ -1863,7 +1862,7 @@ EPUBJS.Book = function(options){
|
||||||
* Creates a new renderer.
|
* Creates a new renderer.
|
||||||
* The renderer will handle displaying the content using the method provided in the settings
|
* The renderer will handle displaying the content using the method provided in the settings
|
||||||
*/
|
*/
|
||||||
this.renderer = new EPUBJS.Renderer(this.settings.renderer);
|
this.renderer = new EPUBJS.Renderer(this.settings.render_method);
|
||||||
//-- Set the width at which to switch from spreads to single pages
|
//-- Set the width at which to switch from spreads to single pages
|
||||||
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
||||||
//-- Pass through the renderer events
|
//-- Pass through the renderer events
|
||||||
|
@ -2220,7 +2219,7 @@ EPUBJS.Book.prototype.startDisplay = function(){
|
||||||
EPUBJS.Book.prototype.restore = function(identifier){
|
EPUBJS.Book.prototype.restore = function(identifier){
|
||||||
|
|
||||||
var book = this,
|
var book = this,
|
||||||
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'],
|
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL', 'globalLayoutProperties'],
|
||||||
reject = false,
|
reject = false,
|
||||||
bookKey = this.generateBookKey(identifier),
|
bookKey = this.generateBookKey(identifier),
|
||||||
fromStore = localStorage.getItem(bookKey),
|
fromStore = localStorage.getItem(bookKey),
|
||||||
|
@ -2535,18 +2534,19 @@ EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.useSpreads = function(use) {
|
EPUBJS.Book.prototype.useSpreads = function(use) {
|
||||||
if(use) {
|
console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead");
|
||||||
this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth);
|
if(use === false) {
|
||||||
this.settings.spreads = true;
|
this.forceSingle(true);
|
||||||
} else {
|
} else {
|
||||||
this.renderer.setMinSpreadWidth(0);
|
this.forceSingle(false);
|
||||||
this.settings.spreads = false;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.forceSingle = function(use) {
|
||||||
|
this.renderer.forceSingle(use);
|
||||||
if(this.isRendered) {
|
if(this.isRendered) {
|
||||||
this.renderer.reformat();
|
this.renderer.reformat();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.unload = function(){
|
EPUBJS.Book.prototype.unload = function(){
|
||||||
|
@ -2653,9 +2653,9 @@ EPUBJS.Book.prototype._needsAssetReplacement = function(){
|
||||||
|
|
||||||
//-- http://www.idpf.org/epub/fxl/
|
//-- http://www.idpf.org/epub/fxl/
|
||||||
EPUBJS.Book.prototype.parseLayoutProperties = function(metadata){
|
EPUBJS.Book.prototype.parseLayoutProperties = function(metadata){
|
||||||
var layout = this.settings.layout || metadata.layout || "reflowable";
|
var layout = (this.layoutOveride && this.layoutOveride.layout) || metadata.layout || "reflowable";
|
||||||
var spread = this.settings.spread || metadata.spread || "auto";
|
var spread = (this.layoutOveride && this.layoutOveride.spread) || metadata.spread || "auto";
|
||||||
var orientation = this.settings.orientations || metadata.orientation || "auto";
|
var orientation = (this.layoutOveride && this.layoutOveride.orientation) || metadata.orientation || "auto";
|
||||||
return {
|
return {
|
||||||
layout : layout,
|
layout : layout,
|
||||||
spread : spread,
|
spread : spread,
|
||||||
|
@ -3375,7 +3375,12 @@ EPUBJS.Hooks = (function(){
|
||||||
|
|
||||||
EPUBJS.Layout = EPUBJS.Layout || {};
|
EPUBJS.Layout = EPUBJS.Layout || {};
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
EPUBJS.Layout.Reflowable = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
this.spreadWidth = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _height){
|
||||||
// Get the prefixed CSS commands
|
// Get the prefixed CSS commands
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
|
@ -3386,9 +3391,9 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
||||||
var section = Math.ceil(width / 8);
|
var section = Math.ceil(width / 8);
|
||||||
var gap = (section % 2 === 0) ? section : section - 1;
|
var gap = (section % 2 === 0) ? section : section - 1;
|
||||||
|
|
||||||
|
this.documentElement = documentElement;
|
||||||
//-- Single Page
|
//-- Single Page
|
||||||
var spreadWidth = (width + gap);
|
this.spreadWidth = (width + gap);
|
||||||
var totalWidth, displayedPages;
|
|
||||||
|
|
||||||
documentElement.style.width = "auto"; //-- reset width for calculations
|
documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
|
||||||
|
@ -3404,19 +3409,30 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
|
||||||
|
|
||||||
documentElement.style.width = width + "px";
|
documentElement.style.width = width + "px";
|
||||||
|
|
||||||
|
return {
|
||||||
|
pageWidth : this.spreadWidth,
|
||||||
|
pageHeight : _height
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
totalWidth = documentElement.scrollWidth;
|
EPUBJS.Layout.Reflowable.prototype.calculatePages = function() {
|
||||||
displayedPages = Math.round(totalWidth / spreadWidth);
|
var totalWidth, displayedPages;
|
||||||
|
this.documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
totalWidth = this.documentElement.scrollWidth;
|
||||||
|
displayedPages = Math.round(totalWidth / this.spreadWidth);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : spreadWidth,
|
|
||||||
pageHeight : _height,
|
|
||||||
displayedPages : displayedPages,
|
displayedPages : displayedPages,
|
||||||
pageCount : displayedPages
|
pageCount : displayedPages
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
EPUBJS.Layout.ReflowableSpreads = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
this.spreadWidth = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.ReflowableSpreads.prototype.format = function(documentElement, _width, _height){
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
|
@ -3431,15 +3447,16 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
||||||
|
|
||||||
//-- Double Page
|
//-- Double Page
|
||||||
var colWidth = Math.floor((width - gap) / divisor);
|
var colWidth = Math.floor((width - gap) / divisor);
|
||||||
var spreadWidth = (colWidth + gap) * divisor;
|
|
||||||
|
|
||||||
var totalWidth, displayedPages;
|
this.documentElement = documentElement;
|
||||||
|
this.spreadWidth = (colWidth + gap) * divisor;
|
||||||
|
|
||||||
|
|
||||||
documentElement.style.width = "auto"; //-- reset width for calculations
|
documentElement.style.width = "auto"; //-- reset width for calculations
|
||||||
|
|
||||||
documentElement.style.overflow = "hidden";
|
documentElement.style.overflow = "hidden";
|
||||||
|
|
||||||
documentElement.style.width = width + "px";
|
//documentElement.style.width = width + "px";
|
||||||
|
|
||||||
//-- Adjust height
|
//-- Adjust height
|
||||||
documentElement.style.height = _height + "px";
|
documentElement.style.height = _height + "px";
|
||||||
|
@ -3449,20 +3466,29 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
|
||||||
documentElement.style[columnGap] = gap+"px";
|
documentElement.style[columnGap] = gap+"px";
|
||||||
documentElement.style[columnWidth] = colWidth+"px";
|
documentElement.style[columnWidth] = colWidth+"px";
|
||||||
|
|
||||||
totalWidth = documentElement.scrollWidth;
|
return {
|
||||||
displayedPages = Math.ceil(totalWidth / spreadWidth);
|
pageWidth : this.spreadWidth,
|
||||||
|
pageHeight : _height
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function() {
|
||||||
|
var totalWidth = this.documentElement.scrollWidth;
|
||||||
|
var displayedPages = Math.round(totalWidth / this.spreadWidth);
|
||||||
|
|
||||||
//-- Add a page to the width of the document to account an for odd number of pages
|
//-- Add a page to the width of the document to account an for odd number of pages
|
||||||
documentElement.style.width = totalWidth + spreadWidth + "px";
|
this.documentElement.style.width = totalWidth + this.spreadWidth + "px";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : spreadWidth,
|
|
||||||
pageHeight : _height,
|
|
||||||
displayedPages : displayedPages,
|
displayedPages : displayedPages,
|
||||||
pageCount : displayedPages * 2
|
pageCount : displayedPages * 2
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed = function(){
|
||||||
|
this.documentElement = null;
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
var viewport = documentElement.querySelector("[name=viewport");
|
var viewport = documentElement.querySelector("[name=viewport");
|
||||||
|
@ -3470,6 +3496,7 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
var contents;
|
var contents;
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
this.documentElement = documentElement;
|
||||||
/**
|
/**
|
||||||
* check for the viewport size
|
* check for the viewport size
|
||||||
* <meta name="viewport" content="width=1024,height=697" />
|
* <meta name="viewport" content="width=1024,height=697" />
|
||||||
|
@ -3498,11 +3525,16 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : width,
|
pageWidth : width,
|
||||||
pageHeight : height,
|
pageHeight : height
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
|
||||||
|
return {
|
||||||
displayedPages : 1,
|
displayedPages : 1,
|
||||||
pageCount : 1
|
pageCount : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Parser = function(baseUrl){
|
EPUBJS.Parser = function(baseUrl){
|
||||||
|
@ -3726,11 +3758,12 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
|
||||||
items.forEach(function(item, index){
|
items.forEach(function(item, index){
|
||||||
var Id = item.getAttribute('idref');
|
var Id = item.getAttribute('idref');
|
||||||
var cfiBase = epubcfi.generateChapter(spineNodeIndex, index, Id);
|
var cfiBase = epubcfi.generateChapter(spineNodeIndex, index, Id);
|
||||||
|
var props = item.getAttribute('properties') || '';
|
||||||
var vert = {
|
var vert = {
|
||||||
'id' : Id,
|
'id' : Id,
|
||||||
'linear' : item.getAttribute('linear') || '',
|
'linear' : item.getAttribute('linear') || '',
|
||||||
'properties' : item.getAttribute('properties') || '',
|
'properties' : props.split(' '),
|
||||||
'manifestProperties' : manifest[Id].properties || '',
|
'manifestProperties' : manifest[Id].properties.split(' '),
|
||||||
'href' : manifest[Id].href,
|
'href' : manifest[Id].href,
|
||||||
'url' : manifest[Id].url,
|
'url' : manifest[Id].url,
|
||||||
'index' : index,
|
'index' : index,
|
||||||
|
@ -4064,7 +4097,7 @@ EPUBJS.Render.Iframe.prototype.scroll = function(bool){
|
||||||
EPUBJS.Render.Iframe.prototype.unload = function(){
|
EPUBJS.Render.Iframe.prototype.unload = function(){
|
||||||
this.window.removeEventListener("resize", this.resized);
|
this.window.removeEventListener("resize", this.resized);
|
||||||
};
|
};
|
||||||
EPUBJS.Renderer = function(type) {
|
EPUBJS.Renderer = function(renderMethod) {
|
||||||
// Dom events to listen for
|
// Dom events to listen for
|
||||||
this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"];
|
this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"];
|
||||||
|
|
||||||
|
@ -4072,8 +4105,8 @@ EPUBJS.Renderer = function(type) {
|
||||||
* Setup a render method.
|
* Setup a render method.
|
||||||
* Options are: Iframe
|
* Options are: Iframe
|
||||||
*/
|
*/
|
||||||
if(type && typeof(EPUBJS.Render[type]) != "undefined"){
|
if(renderMethod && typeof(EPUBJS.Render[renderMethod]) != "undefined"){
|
||||||
this.render = new EPUBJS.Render[type]();
|
this.render = new EPUBJS.Render[renderMethod]();
|
||||||
} else {
|
} else {
|
||||||
console.error("Not a Valid Rendering Method");
|
console.error("Not a Valid Rendering Method");
|
||||||
}
|
}
|
||||||
|
@ -4085,8 +4118,11 @@ EPUBJS.Renderer = function(type) {
|
||||||
this.epubcfi = new EPUBJS.EpubCFI();
|
this.epubcfi = new EPUBJS.EpubCFI();
|
||||||
|
|
||||||
this.spreads = true;
|
this.spreads = true;
|
||||||
|
this.isForcedSingle = false;
|
||||||
this.resized = _.throttle(this.onResized.bind(this), 10);
|
this.resized = _.throttle(this.onResized.bind(this), 10);
|
||||||
|
|
||||||
|
this.layoutSettings = {};
|
||||||
|
|
||||||
//-- Adds Hook methods to the Book prototype
|
//-- Adds Hook methods to the Book prototype
|
||||||
// Hooks will all return before triggering the callback.
|
// Hooks will all return before triggering the callback.
|
||||||
EPUBJS.Hooks.mixin(this);
|
EPUBJS.Hooks.mixin(this);
|
||||||
|
@ -4157,7 +4193,7 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
||||||
|
|
||||||
this.currentChapterCfiBase = chapter.cfiBase;
|
this.currentChapterCfiBase = chapter.cfiBase;
|
||||||
|
|
||||||
this.settings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||||
|
|
||||||
// Get the url string from the chapter (may be from storage)
|
// Get the url string from the chapter (may be from storage)
|
||||||
return chapter.url().
|
return chapter.url().
|
||||||
|
@ -4177,16 +4213,24 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
var deferred = new RSVP.defer();
|
var deferred = new RSVP.defer();
|
||||||
var loaded;
|
var loaded;
|
||||||
|
|
||||||
this.layoutMethod = this.determineLayout(this.settings);
|
// Switch to the required layout method for the settings
|
||||||
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
|
|
||||||
this.visible(false);
|
this.visible(false);
|
||||||
|
|
||||||
loaded = this.render.load(url);
|
loaded = this.render.load(url);
|
||||||
|
|
||||||
loaded.then(function(contents) {
|
loaded.then(function(contents) {
|
||||||
|
var formated;
|
||||||
|
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
this.doc = this.render.document;
|
this.doc = this.render.document;
|
||||||
|
|
||||||
|
// Format the contents using the current layout method
|
||||||
|
formated = this.layout.format(contents, this.render.width, this.render.height);
|
||||||
|
this.render.setPageDimensions(formated.pageWidth, formated.pageHeight);
|
||||||
|
|
||||||
if(!this.initWidth && !this.initHeight){
|
if(!this.initWidth && !this.initHeight){
|
||||||
this.render.window.addEventListener("resize", this.resized, false);
|
this.render.window.addEventListener("resize", this.resized, false);
|
||||||
}
|
}
|
||||||
|
@ -4196,6 +4240,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
|
|
||||||
//-- Trigger registered hooks before displaying
|
//-- Trigger registered hooks before displaying
|
||||||
this.beforeDisplay(function(){
|
this.beforeDisplay(function(){
|
||||||
|
var pages = this.layout.calculatePages();
|
||||||
var msg = this.currentChapter;
|
var msg = this.currentChapter;
|
||||||
|
|
||||||
msg.cfi = this.currentLocationCfi = this.getPageCfi();
|
msg.cfi = this.currentLocationCfi = this.getPageCfi();
|
||||||
|
@ -4203,8 +4248,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
this.trigger("renderer:chapterDisplayed", msg);
|
this.trigger("renderer:chapterDisplayed", msg);
|
||||||
this.trigger("renderer:pageChanged", this.currentLocationCfi);
|
this.trigger("renderer:pageChanged", this.currentLocationCfi);
|
||||||
|
|
||||||
this.layout = this.layoutMethod(contents, this.render.width, this.render.height);
|
this.updatePages(pages);
|
||||||
this.updatePages(this.layout);
|
|
||||||
|
|
||||||
this.visible(true);
|
this.visible(true);
|
||||||
|
|
||||||
|
@ -4223,10 +4267,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
* Returns: Object with layout properties
|
* Returns: Object with layout properties
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
var layoutMethod = "ReflowableSpreads"; // Default to Spreads
|
|
||||||
var properties = chapter.split(' ');
|
|
||||||
var settings = {};
|
var settings = {};
|
||||||
var spreads = true;
|
|
||||||
|
|
||||||
//-- Get the global defaults
|
//-- Get the global defaults
|
||||||
for (var attr in global) {
|
for (var attr in global) {
|
||||||
|
@ -4235,7 +4276,7 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-- Get the chapter's display type
|
//-- Get the chapter's display type
|
||||||
properties.forEach(function(prop){
|
chapter.forEach(function(prop){
|
||||||
var rendition = prop.replace("rendition:", '');
|
var rendition = prop.replace("rendition:", '');
|
||||||
var split = rendition.indexOf("-");
|
var split = rendition.indexOf("-");
|
||||||
var property, value;
|
var property, value;
|
||||||
|
@ -4253,47 +4294,38 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the settings to determine which Layout Method is needed
|
* Uses the settings to determine which Layout Method is needed
|
||||||
|
* Triggers events based on the method choosen
|
||||||
* Takes: Layout settings object
|
* Takes: Layout settings object
|
||||||
* Returns: EPUBJS.Layout function
|
* Returns: String of appropriate for EPUBJS.Layout function
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
||||||
var layoutMethod = "ReflowableSpreads";
|
// Default is layout: reflowable & spread: auto
|
||||||
|
var spreads = this.determineSpreads(this.minSpreadWidth);
|
||||||
|
var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
|
||||||
|
var scroll = false;
|
||||||
|
|
||||||
if(settings.layout === "pre-paginated") {
|
if(settings.layout === "pre-paginated") {
|
||||||
layoutMethod = "Fixed";
|
layoutMethod = "Fixed";
|
||||||
this.render.scroll(true);
|
scroll = true;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
spreads = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.layout === "reflowable" && settings.spread === "none") {
|
if(settings.layout === "reflowable" && settings.spread === "none") {
|
||||||
layoutMethod = "Reflowable";
|
layoutMethod = "Reflowable";
|
||||||
this.render.scroll(false);
|
scroll = false;
|
||||||
this.trigger("renderer:spreads", false);
|
spreads = false;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.layout === "reflowable" && settings.spread === "both") {
|
if(settings.layout === "reflowable" && settings.spread === "both") {
|
||||||
layoutMethod = "ReflowableSpreads";
|
layoutMethod = "ReflowableSpreads";
|
||||||
this.render.scroll(false);
|
scroll = false;
|
||||||
this.trigger("renderer:spreads", true);
|
spreads = true;
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reflowable Auto adjustments for width
|
this.spreads = spreads;
|
||||||
if(settings.layout === "reflowable" && settings.spread === "auto"){
|
this.render.scroll(scroll);
|
||||||
spreads = this.determineSpreads(this.minSpreadWidth);
|
this.trigger("renderer:spreads", spreads);
|
||||||
if(spreads){
|
return layoutMethod;
|
||||||
layoutMethod = "ReflowableSpreads";
|
|
||||||
this.trigger("renderer:spreads", true);
|
|
||||||
} else {
|
|
||||||
layoutMethod = "Reflowable";
|
|
||||||
this.trigger("renderer:spreads", false);
|
|
||||||
}
|
|
||||||
this.render.scroll(false);
|
|
||||||
return EPUBJS.Layout[layoutMethod];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shortcut to trigger the hook before displaying the chapter
|
// Shortcut to trigger the hook before displaying the chapter
|
||||||
|
@ -4304,25 +4336,29 @@ EPUBJS.Renderer.prototype.beforeDisplay = function(callback, renderer){
|
||||||
// Update the renderer with the information passed by the layout
|
// Update the renderer with the information passed by the layout
|
||||||
EPUBJS.Renderer.prototype.updatePages = function(layout){
|
EPUBJS.Renderer.prototype.updatePages = function(layout){
|
||||||
this.displayedPages = layout.displayedPages;
|
this.displayedPages = layout.displayedPages;
|
||||||
this.currentChapter.pages = layout.displayedPages;
|
this.currentChapter.pages = layout.pageCount;
|
||||||
this.render.setPageDimensions(layout.pageWidth, layout.pageHeight);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the layout again and jump back to the previous cfi position
|
// Apply the layout again and jump back to the previous cfi position
|
||||||
EPUBJS.Renderer.prototype.reformat = function(){
|
EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
var renderer = this;
|
var renderer = this;
|
||||||
|
var formated, pages;
|
||||||
if(!this.contents) return;
|
if(!this.contents) return;
|
||||||
|
|
||||||
this.layout = this.layoutMethod(this.contents, this.render.width, this.render.height);
|
formated = this.layout.format(this.contents, this.render.width, this.render.height);
|
||||||
this.updatePages(this.layout);
|
this.render.setPageDimensions(formated.pageWidth, formated.pageHeight);
|
||||||
|
|
||||||
setTimeout(function(){
|
pages = renderer.layout.calculatePages();
|
||||||
|
renderer.updatePages(pages);
|
||||||
|
|
||||||
|
// Give the css styles time to update
|
||||||
|
clearTimeout(this.timeoutTillCfi);
|
||||||
|
this.timeoutTillCfi = setTimeout(function(){
|
||||||
//-- Go to current page after formating
|
//-- Go to current page after formating
|
||||||
if(renderer.currentLocationCfi){
|
if(renderer.currentLocationCfi){
|
||||||
renderer.gotoCfi(renderer.currentLocationCfi);
|
renderer.gotoCfi(renderer.currentLocationCfi);
|
||||||
}
|
}
|
||||||
|
this.timeoutTillCfi = null;
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -4546,7 +4582,8 @@ EPUBJS.Renderer.prototype.onResized = function(e){
|
||||||
// Only re-layout if the spreads have switched
|
// Only re-layout if the spreads have switched
|
||||||
if(spreads != this.spreads){
|
if(spreads != this.spreads){
|
||||||
this.spreads = spreads;
|
this.spreads = spreads;
|
||||||
this.layoutMethod = this.determineLayout(this.settings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.contents){
|
if(this.contents){
|
||||||
|
@ -4610,16 +4647,27 @@ EPUBJS.Renderer.prototype.onMouseUp = function(e){
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){
|
EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){
|
||||||
this.minSpreadWidth = width;
|
this.minSpreadWidth = width;
|
||||||
|
this.spreads = this.determineSpreads(width);
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
||||||
if(this.width < cutoff || !cutoff) {
|
if(this.isForcedSingle || !cutoff || this.width < cutoff) {
|
||||||
return false; //-- Single Page
|
return false; //-- Single Page
|
||||||
}else{
|
}else{
|
||||||
return true; //-- Double Page
|
return true; //-- Double Page
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Renderer.prototype.forceSingle = function(bool){
|
||||||
|
if(bool) {
|
||||||
|
this.isForcedSingle = true;
|
||||||
|
this.spreads = false;
|
||||||
|
} else {
|
||||||
|
this.isForcedSingle = false;
|
||||||
|
this.spreads = this.determineSpreads(width);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//-- Content Replacements
|
//-- Content Replacements
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
||||||
|
|
|
@ -189,7 +189,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, r
|
||||||
iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
||||||
oheight;
|
oheight;
|
||||||
|
|
||||||
if(renderer.settings.layout != "reflowable") {
|
if(renderer.layoutSettings.layout != "reflowable") {
|
||||||
callback();
|
callback();
|
||||||
return; //-- Only adjust images for reflowable text
|
return; //-- Only adjust images for reflowable text
|
||||||
}
|
}
|
||||||
|
|
2
build/hooks.min.js
vendored
2
build/hooks.min.js
vendored
|
@ -1 +1 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e=b.height,f=b.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),chapter.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.settings.layout?(a(),void 0):(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a(),void 0)},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e=b.height,f=b.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),chapter.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.layoutSettings.layout?(a(),void 0):(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a(),void 0)},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
|
@ -57,7 +57,7 @@ EPUBJS.Reader = function(path, _options) {
|
||||||
reload: this.settings.reload,
|
reload: this.settings.reload,
|
||||||
contained: this.settings.contained,
|
contained: this.settings.contained,
|
||||||
bookKey: this.settings.bookKey,
|
bookKey: this.settings.bookKey,
|
||||||
styles: this.settings.styles
|
styles: this.settings.styles,
|
||||||
});
|
});
|
||||||
|
|
||||||
if(this.settings.previousLocationCfi) {
|
if(this.settings.previousLocationCfi) {
|
||||||
|
@ -344,19 +344,20 @@ EPUBJS.reader.ControlsController = function(book) {
|
||||||
screenfull.toggle($('#container')[0]);
|
screenfull.toggle($('#container')[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener(screenfull.raw.fullscreenchange, function() {
|
if(screenfull) {
|
||||||
fullscreen = screenfull.isFullscreen;
|
document.addEventListener(screenfull.raw.fullscreenchange, function() {
|
||||||
if(fullscreen) {
|
fullscreen = screenfull.isFullscreen;
|
||||||
$fullscreen
|
if(fullscreen) {
|
||||||
.addClass("icon-resize-small")
|
$fullscreen
|
||||||
.removeClass("icon-resize-full");
|
.addClass("icon-resize-small")
|
||||||
} else {
|
.removeClass("icon-resize-full");
|
||||||
$fullscreen
|
} else {
|
||||||
.addClass("icon-resize-full")
|
$fullscreen
|
||||||
.removeClass("icon-resize-small");
|
.addClass("icon-resize-full")
|
||||||
}
|
.removeClass("icon-resize-small");
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$settings.on("click", function() {
|
$settings.on("click", function() {
|
||||||
reader.SettingsController.show();
|
reader.SettingsController.show();
|
||||||
|
|
6
demo/js/epub.min.js
vendored
6
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/hooks.min.js
vendored
2
demo/js/hooks.min.js
vendored
|
@ -1 +1 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e=b.height,f=b.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),chapter.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.settings.layout?(a(),void 0):(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a(),void 0)},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e=b.height,f=b.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),chapter.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.layoutSettings.layout?(a(),void 0):(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a(),void 0)},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
2
demo/js/reader.min.js
vendored
2
demo/js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "EpubJS",
|
"name": "EpubJS",
|
||||||
"version": "0.1.9",
|
"version": "0.2.0",
|
||||||
"repository": "https://github.com/futurepress/epub.js",
|
"repository": "https://github.com/futurepress/epub.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "~0.4.1",
|
"grunt": "~0.4.1",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var EPUBJS = EPUBJS || {};
|
var EPUBJS = EPUBJS || {};
|
||||||
EPUBJS.VERSION = "0.1.9";
|
EPUBJS.VERSION = "0.2.0";
|
||||||
|
|
||||||
EPUBJS.plugins = EPUBJS.plugins || {};
|
EPUBJS.plugins = EPUBJS.plugins || {};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ EPUBJS.Renderer = function(renderMethod) {
|
||||||
this.epubcfi = new EPUBJS.EpubCFI();
|
this.epubcfi = new EPUBJS.EpubCFI();
|
||||||
|
|
||||||
this.spreads = true;
|
this.spreads = true;
|
||||||
this.forceSingle = false;
|
this.isForcedSingle = false;
|
||||||
this.resized = _.throttle(this.onResized.bind(this), 10);
|
this.resized = _.throttle(this.onResized.bind(this), 10);
|
||||||
|
|
||||||
this.layoutSettings = {};
|
this.layoutSettings = {};
|
||||||
|
@ -116,7 +116,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
|
|
||||||
// Switch to the required layout method for the settings
|
// Switch to the required layout method for the settings
|
||||||
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
this.layout = new EPUBJS.Layout[this.layoutMethod];
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
|
|
||||||
this.visible(false);
|
this.visible(false);
|
||||||
|
|
||||||
|
@ -195,8 +195,9 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the settings to determine which Layout Method is needed
|
* Uses the settings to determine which Layout Method is needed
|
||||||
|
* Triggers events based on the method choosen
|
||||||
* Takes: Layout settings object
|
* Takes: Layout settings object
|
||||||
* Returns: EPUBJS.Layout function
|
* Returns: String of appropriate for EPUBJS.Layout function
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
||||||
// Default is layout: reflowable & spread: auto
|
// Default is layout: reflowable & spread: auto
|
||||||
|
@ -483,8 +484,8 @@ EPUBJS.Renderer.prototype.onResized = function(e){
|
||||||
if(spreads != this.spreads){
|
if(spreads != this.spreads){
|
||||||
this.spreads = spreads;
|
this.spreads = spreads;
|
||||||
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
this.layout = new EPUBJS.Layout[this.layoutMethod];
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.contents){
|
if(this.contents){
|
||||||
this.reformat();
|
this.reformat();
|
||||||
|
@ -551,7 +552,7 @@ EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
||||||
if(this.forceSingle || !cutoff || this.width < cutoff) {
|
if(this.isForcedSingle || !cutoff || this.width < cutoff) {
|
||||||
return false; //-- Single Page
|
return false; //-- Single Page
|
||||||
}else{
|
}else{
|
||||||
return true; //-- Double Page
|
return true; //-- Double Page
|
||||||
|
@ -560,10 +561,10 @@ EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.forceSingle = function(bool){
|
EPUBJS.Renderer.prototype.forceSingle = function(bool){
|
||||||
if(bool) {
|
if(bool) {
|
||||||
this.forceSingle = true;
|
this.isForcedSingle = true;
|
||||||
this.spreads = false;
|
this.spreads = false;
|
||||||
} else {
|
} else {
|
||||||
this.forceSingle = false;
|
this.isForcedSingle = false;
|
||||||
this.spreads = this.determineSpreads(width);
|
this.spreads = this.determineSpreads(width);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue