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

Updated Expands and Layout methods

This commit is contained in:
Fred Chasen 2015-05-24 09:44:35 -04:00
parent 6b25126f00
commit b88aab25d9
14 changed files with 1116 additions and 766 deletions

View file

@ -1,76 +1,8 @@
EPUBJS.Layout = EPUBJS.Layout || {};
EPUBJS.Layout.Reflowable = function(view){
// this.documentElement = null;
this.view = view;
this.spreadWidth = null;
};
EPUBJS.Layout.Reflowable = function(_width, _height, _gap, _devisor){
EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _height, _gap){
// Get the prefixed CSS commands
var columnAxis = EPUBJS.core.prefixed('columnAxis');
var columnGap = EPUBJS.core.prefixed('columnGap');
var columnWidth = EPUBJS.core.prefixed('columnWidth');
var columnFill = EPUBJS.core.prefixed('columnFill');
//-- Check the width and create even width columns
var width = Math.floor(_width);
// var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 0; // Not needed for single
var section = Math.floor(width / 8);
var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
this.documentElement = documentElement;
//-- Single Page
this.spreadWidth = (width + gap);
documentElement.style.overflow = "hidden";
// Must be set to the new calculated width or the columns will be off
documentElement.style.width = width + "px";
//-- Adjust height
documentElement.style.height = _height + "px";
//-- Add columns
documentElement.style[columnAxis] = "horizontal";
documentElement.style[columnFill] = "auto";
documentElement.style[columnWidth] = width+"px";
documentElement.style[columnGap] = gap+"px";
this.colWidth = width;
this.gap = gap;
return {
pageWidth : this.spreadWidth,
pageHeight : _height
};
};
EPUBJS.Layout.Reflowable.prototype.calculatePages = function() {
var totalWidth, displayedPages;
this.documentElement.style.width = "auto"; //-- reset width for calculations
totalWidth = this.documentElement.scrollWidth;
displayedPages = Math.ceil(totalWidth / this.spreadWidth);
return {
displayedPages : displayedPages,
pageCount : displayedPages
};
};
EPUBJS.Layout.ReflowableSpreads = function(view){
this.view = view;
this.documentElement = view.document.documentElement;
this.spreadWidth = null;
};
EPUBJS.Layout.ReflowableSpreads.prototype.format = function(_width, _height, _gap){
var columnAxis = EPUBJS.core.prefixed('columnAxis');
var columnGap = EPUBJS.core.prefixed('columnGap');
var columnWidth = EPUBJS.core.prefixed('columnWidth');
var columnFill = EPUBJS.core.prefixed('columnFill');
var divisor = 2,
cutoff = 800;
var divisor = _devisor || 1;
//-- Check the width and create even width columns
var fullWidth = Math.floor(_width);
@ -79,70 +11,86 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(_width, _height, _ga
var section = Math.floor(width / 8);
var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
var colWidth;
var spreadWidth;
//-- Double Page
var colWidth = Math.floor((width - gap) / divisor);
if(divisor > 1) {
colWidth = Math.floor((width - gap) / divisor);
} else {
colWidth = width;
}
this.spreadWidth = (colWidth + gap) * divisor;
spreadWidth = (colWidth + gap) * divisor;
this.view.document.documentElement.style.overflow = "hidden";
this.columnAxis = EPUBJS.core.prefixed('columnAxis');
this.columnGap = EPUBJS.core.prefixed('columnGap');
this.columnWidth = EPUBJS.core.prefixed('columnWidth');
this.columnFill = EPUBJS.core.prefixed('columnFill');
this.width = width;
this.height = _height;
this.spread = spreadWidth;
this.column = colWidth;
this.gap = gap;
this.divisor = divisor;
return this;
};
EPUBJS.Layout.Reflowable.prototype.format = function(view){
var $doc = view.document.documentElement;
var $body = view.document.body;//view.document.querySelector("body");
$doc.style.overflow = "hidden";
// Must be set to the new calculated width or the columns will be off
this.view.document.body.style.width = width + "px";
$body.style.width = this.width + "px";
//-- Adjust height
this.view.document.body.style.height = _height + "px";
$body.style.height = this.height + "px";
//-- Add columns
this.view.document.body.style[columnAxis] = "horizontal";
this.view.document.body.style[columnFill] = "auto";
this.view.document.body.style[columnGap] = gap+"px";
this.view.document.body.style[columnWidth] = colWidth+"px";
$body.style[this.columnAxis] = "horizontal";
$body.style[this.columnFill] = "auto";
$body.style[this.columnGap] = this.gap+"px";
$body.style[this.columnWidth] = this.column+"px";
this.colWidth = colWidth;
this.gap = gap;
// Add extra padding for the gap between this and the next view
view.iframe.style.marginRight = this.gap+"px";
// this.view.document.body.style.paddingRight = gap + "px";
// view.iframe.style.width = this.spreadWidth+"px";
// this.view.element.style.paddingRight = gap+"px";
// view.iframe.style.paddingLeft = gap+"px";
};
EPUBJS.Layout.Reflowable.prototype.count = function(view) {
var totalWidth = view.documentElement.scrollWidth;
var spreads = Math.ceil(totalWidth / this.spreadWidth);
return {
pageWidth : this.spreadWidth,
pageHeight : _height
spreads : spreads,
pages : spreads * this.divisor
};
};
EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function(view) {
var totalWidth = this.documentElement.scrollWidth;
var displayedPages = Math.ceil(totalWidth / this.spreadWidth);
EPUBJS.Layout.Fixed = function(_width, _height){
//-- Add a page to the width of the document to account an for odd number of pages
// this.documentElement.style.width = totalWidth + this.spreadWidth + "px";
return {
displayedPages : displayedPages,
pageCount : displayedPages * 2
};
};
EPUBJS.Layout.Fixed = function(){
this.documentElement = null;
};
EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
var columnWidth = EPUBJS.core.prefixed('columnWidth');
var viewport = documentElement.querySelector("[name=viewport");
var content;
var contents;
EPUBJS.Layout.Fixed.prototype.format = function(view){
var width, height;
this.documentElement = documentElement;
var $doc = view.document.documentElement;
var $viewport = documentElement.querySelector("[name=viewport");
/**
* check for the viewport size
* <meta name="viewport" content="width=1024,height=697" />
*/
if(viewport && viewport.hasAttribute("content")) {
content = viewport.getAttribute("content");
if($viewport && $viewport.hasAttribute("content")) {
content = $viewport.getAttribute("content");
contents = content.split(',');
if(contents[0]){
width = contents[0].replace("width=", '');
@ -153,28 +101,38 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
}
//-- Adjust width and height
documentElement.style.width = width + "px" || "auto";
documentElement.style.height = height + "px" || "auto";
//-- Remove columns
documentElement.style[columnWidth] = "auto";
// $doc.style.width = width + "px" || "auto";
// $doc.style.height = height + "px" || "auto";
view.resize(width, height);
//-- Scroll
documentElement.style.overflow = "auto";
this.colWidth = width;
this.gap = 0;
return {
pageWidth : width,
pageHeight : height
};
$doc.style.overflow = "auto";
};
EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
EPUBJS.Layout.Fixed.prototype.count = function(){
return {
displayedPages : 1,
pageCount : 1
spreads : 1,
pages : 1
};
};
EPUBJS.Layout.Scroll = function(){
};
EPUBJS.Layout.Scroll.prototype.format = function(view){
var $doc = view.document.documentElement;
$doc.style.width = "auto";
$doc.style.height = "auto";
};
EPUBJS.Layout.Scroll.prototype.count = function(){
return {
spreads : 1,
pages : 1
};
};