1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00
epub.js/lib/epubjs/layout.js
2014-07-31 17:25:56 -04:00

95 lines
No EOL
2.4 KiB
JavaScript

/**
* Reconciles the current chapters layout properies with
* the global layout properities.
* Takes: global layout settings object, chapter properties string
* Returns: Object with layout properties
*/
EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
var settings = {};
//-- Get the global defaults
for (var attr in global) {
if (global.hasOwnProperty(attr)){
settings[attr] = global[attr];
}
}
//-- Get the chapter's display type
chapter.forEach(function(prop){
var rendition = prop.replace("rendition:", '');
var split = rendition.indexOf("-");
var property, value;
if(split != -1){
property = rendition.slice(0, split);
value = rendition.slice(split+1);
settings[property] = value;
}
});
return settings;
};
/**
* Uses the settings to determine which Layout Method is needed
* Triggers events based on the method choosen
* Takes: Layout settings object
* Returns: String of appropriate for EPUBJS.Layout function
*/
EPUBJS.Renderer.prototype.determineLayout = function(settings){
// 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") {
layoutMethod = "Fixed";
scroll = true;
spreads = false;
}
if(settings.layout === "reflowable" && settings.spread === "none") {
layoutMethod = "Reflowable";
scroll = false;
spreads = false;
}
if(settings.layout === "reflowable" && settings.spread === "both") {
layoutMethod = "ReflowableSpreads";
scroll = false;
spreads = true;
}
this.spreads = spreads;
this.render.scroll(scroll);
this.trigger("renderer:spreads", spreads);
return layoutMethod;
};
//-- STYLES
EPUBJS.Renderer.prototype.applyStyles = function(styles) {
for (var style in styles) {
for (var view in this.views) {
view.setStyle(style, styles[style]);
}
}
};
EPUBJS.Renderer.prototype.setStyle = function(style, val, prefixed){
for (var view in this.views) {
view.setStyle(style, val, prefixed);
}
};
EPUBJS.Renderer.prototype.removeStyle = function(style){
for (var view in this.views) {
view.removeStyle(style);
}
};
//-- HEAD TAGS
EPUBJS.Renderer.prototype.applyHeadTags = function(headTags) {
for ( var headTag in headTags ) {
this.render.addHeadTag(headTag, headTags[headTag]);
}
};