Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spineItem inherits rendition properties from package #29

Merged
merged 2 commits into from
Jun 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ ReadiumSDK.Helpers.deduceSyntheticSpread = function($viewport, spineItem, settin
return false;
}

if(spineItem && spineItem.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_NONE) {
var rendition_spread = spineItem ? spineItem.getRenditionSpread() : undefined;

if(rendition_spread === ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_NONE) {
return false;
}

Expand All @@ -226,21 +228,21 @@ ReadiumSDK.Helpers.deduceSyntheticSpread = function($viewport, spineItem, settin
return false;
}

if(spineItem.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_BOTH) {
if(rendition_spread === ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_BOTH) {
return true;
}

var orientation = ReadiumSDK.Helpers.getOrientation($viewport);

if(spineItem.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_LANDSCAPE) {
if(rendition_spread === ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_LANDSCAPE) {
return orientation === ReadiumSDK.Views.ORIENTATION_LANDSCAPE;
}

if(spineItem.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_PORTRAIT) {
if(rendition_spread === ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_PORTRAIT) {
return orientation === ReadiumSDK.Views.ORIENTATION_PORTRAIT;
}

if(!spineItem.rendition_spread || spineItem.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_AUTO) {
if(!rendition_spread || rendition_spread === ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_AUTO) {
// if no spread set in document and user didn't set in in setting we will do double for landscape
return orientation === ReadiumSDK.Views.ORIENTATION_LANDSCAPE;
}
Expand Down Expand Up @@ -324,12 +326,14 @@ ReadiumSDK.Helpers.getOrientation = function($viewport) {

ReadiumSDK.Helpers.isRenditionSpreadPermittedForItem = function(item, orientation) {

return !item.rendition_spread
|| item.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_BOTH
|| item.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_AUTO
|| (item.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_LANDSCAPE
var rendition_spread = item.getRenditionSpread();

return !rendition_spread
|| rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_BOTH
|| rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_AUTO
|| (rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_LANDSCAPE
&& orientation == ReadiumSDK.Views.ORIENTATION_LANDSCAPE)
|| (item.rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_PORTRAIT
|| (rendition_spread == ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_PORTRAIT
&& orientation == ReadiumSDK.Views.ORIENTATION_PORTRAIT );
};

Expand Down
12 changes: 0 additions & 12 deletions js/models/spine.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,6 @@ ReadiumSDK.Models.Spine = function(epubPackage, spineDTO) {
var length = spineDTO.items.length;
for(var i = 0; i < length; i++) {
var item = new ReadiumSDK.Models.SpineItem(spineDTO.items[i], i, this);
if (!item.rendition_spread)
{
item.rendition_spread = epubPackage.rendition_spread;
}
if (!item.rendition_layout)
{
item.rendition_layout = epubPackage.rendition_layout;
}
if (!item.rendition_orientation)
{
item.rendition_orientation = epubPackage.rendition_orientation;
}
this.items.push(item);
}

Expand Down
41 changes: 33 additions & 8 deletions js/models/spine_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ ReadiumSDK.Models.SpineItem = function(itemData, index, spine){
};

this.isRenditionSpreadAllowed = function() {
return !self.rendition_spread || self.rendition_spread != ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_NONE;

var rendition_spread = self.getRenditionSpread();
return !rendition_spread || rendition_spread != ReadiumSDK.Models.SpineItem.RENDITION_SPREAD_NONE;
};

function validateSpread() {
Expand Down Expand Up @@ -106,15 +108,11 @@ ReadiumSDK.Models.SpineItem = function(itemData, index, spine){
return !self.isFixedLayout();
};

this.isLayoutSetExplicitly = function() {
return self.rendition_layout;
};

this.isFixedLayout = function() {

// cannot use isPropertyValueSetForItemOrPackage() here!

var isLayoutExplicitlyDefined = self.rendition_layout || self.spine.package.rendition_layout;
var isLayoutExplicitlyDefined = self.getRenditionLayout();

if(isLayoutExplicitlyDefined) {

Expand All @@ -135,10 +133,37 @@ ReadiumSDK.Models.SpineItem = function(itemData, index, spine){
this.getRenditionFlow = function() {

if(self.rendition_flow) {
return self.rendition_flow;
return self.spine.rendition_flow;
}

return self.spine.package.rendition_flow;
};

this.getRenditionSpread = function() {

if(self.rendition_spread) {
return self.spine.rendition_spread;
}

return self.spine.package.rendition_spread;
};

this.getRenditionOrientation = function() {

if(self.rendition_orientation) {
return self.spine.rendition_orientation;
}

return self.spine.package.rendition_orientation;
};

this.getRenditionLayout = function() {

if(self.rendition_layout) {
return self.spine.rendition_layout;
}

return self.package.rendition_flow;
return self.spine.package.rendition_layout;
};

function isPropertyValueSetForItemOrPackage(propName, propValue) {
Expand Down