Skip to content

Commit

Permalink
Merge pull request #100 from readium/feature/prev-next-button-visibil…
Browse files Browse the repository at this point in the history
…ity-lars

Split apart @larsvoigt's work that adds support for next/previous button...
  • Loading branch information
ryanackley committed Aug 27, 2014
2 parents a592f34 + efe8414 commit f7eace5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
42 changes: 38 additions & 4 deletions js/models/current_pages_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ Used to report pagination state back to the host application
@constructor
@param {Number} spineItemCount Number of spine items
@param {ReadiumSDK.Models.Spine} spine
@param {boolean} isFixedLayout is fixed or reflowable spine item
@param {string} pageProgressionDirection ltr | rtl
*/

ReadiumSDK.Models.CurrentPagesInfo = function(spineItemCount, isFixedLayout, pageProgressionDirection) {

This comment has been minimized.

Copy link
@danielweck

danielweck Sep 1, 2014

Member

Forgot to update scroll view!
e7d384f

ReadiumSDK.Models.CurrentPagesInfo = function(spine, isFixedLayout) {


this.pageProgressionDirection = pageProgressionDirection;
this.isRightToLeft = spine.direction == "rtl";

This comment has been minimized.

Copy link
@danielweck

danielweck Sep 1, 2014

Member

Minor improvements here:
a42358c

this.isFixedLayout = isFixedLayout;
this.spineItemCount = spineItemCount;
this.spineItemCount = spine.items.length
this.openPages = [];

this.addOpenPage = function(spineItemPageIndex, spineItemPageCount, idref, spineItemIndex) {
Expand All @@ -49,6 +49,40 @@ ReadiumSDK.Models.CurrentPagesInfo = function(spineItemCount, isFixedLayout, pag
this.sort();
};

this.canGoLeft = function () {
return this.isRightToLeft ? this.canGoNext() : this.canGoPrev();
};

this.canGoRight = function () {
return this.isRightToLeft ? this.canGoPrev() : this.canGoNext();
};

this.canGoNext = function() {

if(this.openPages.length == 0)
return false;

var lastOpenPage = this.openPages[this.openPages.length - 1];

if(!spine.isValidLinearItem(lastOpenPage.spineItemIndex))
return false;

return lastOpenPage.spineItemIndex < spine.last().index || lastOpenPage.spineItemPageIndex < lastOpenPage.spineItemPageCount - 1;
};

this.canGoPrev = function() {

if(this.openPages.length == 0)
return false;

var firstOpenPage = this.openPages[0];

if(!spine.isValidLinearItem(firstOpenPage.spineItemIndex))
return false;

return spine.first().index < firstOpenPage.spineItemIndex || 0 < firstOpenPage.spineItemPageIndex;
};

this.sort = function() {

this.openPages.sort(function(a, b) {
Expand Down
5 changes: 5 additions & 0 deletions js/models/spine.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ ReadiumSDK.Models.Spine = function(epubPackage, spineDTO) {
return !_handleLinear || item.linear !== "no";
}


this.isValidLinearItem = function(index) {
return isValidLinearItem(this.item(index));
};

this.prevItem = function(item) {

return lookForPrevValidItem(item.index - 1);
Expand Down
2 changes: 1 addition & 1 deletion js/views/fixed_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ ReadiumSDK.Views.FixedView = function(options, reader){

this.getPaginationInfo = function() {

var paginationInfo = new ReadiumSDK.Models.CurrentPagesInfo(_spine.items.length, true, _spine.direction);
var paginationInfo = new ReadiumSDK.Models.CurrentPagesInfo(_spine, true);

var spreadItems = [_spread.leftItem, _spread.rightItem, _spread.centerItem];

Expand Down
2 changes: 1 addition & 1 deletion js/views/reflowable_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ ReadiumSDK.Views.ReflowableView = function(options, reader){

this.getPaginationInfo = function() {

var paginationInfo = new ReadiumSDK.Models.CurrentPagesInfo(_spine.items.length, false, _spine.direction);
var paginationInfo = new ReadiumSDK.Models.CurrentPagesInfo(_spine, false);

if(!_currentSpineItem) {
return paginationInfo;
Expand Down

0 comments on commit f7eace5

Please sign in to comment.