Skip to content

Commit

Permalink
Added option Index to open the book at a given index
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminlong committed Dec 7, 2016
1 parent ec07dce commit 12801e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions js/demo/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var book1 = new Heidelberg($('#Heidelberg-example-1'), {
previousButton: $('#previous'),
nextButton: $('#next'),
hasSpreads: true,
index: 6,
onPageTurn: function(el, els) {
console.log('Page turned');
},
Expand All @@ -17,7 +18,8 @@ $('#jump').on('click', function() {
var book2 = new Heidelberg($('#Heidelberg-example-2'), {
canClose: true,
arrowKeys: false,
concurrentAnimations: 5
concurrentAnimations: 5,
index: 0,
});

$('#first').on('click', function() {
Expand All @@ -26,4 +28,4 @@ $('#first').on('click', function() {

$('#last').on('click', function() {
book2.turnPage(14);
});
});
15 changes: 12 additions & 3 deletions js/heidelberg/heidelberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
arrowKeys: true,
concurrentAnimations: null,
limitPageTurns: true,
index: 0,
onPageTurn: function() {},
onSpreadSetup: function() {}
};
Expand All @@ -57,7 +58,6 @@
}

Heidelberg.prototype.init = function() {

var el = this.el;
var els = {};
var options = this.options;
Expand All @@ -81,10 +81,19 @@
var coverEl = $('<div />').addClass('Heidelberg-HiddenCover');
el.prepend(coverEl.clone());
el.append(coverEl.clone());
els.pages.eq(0).add(els.pages.eq(1)).addClass('is-active');

// if index is odd, we substract one.
var index = options.index&1 ? options.index-1: options.index;
els.pages.eq(index).add(els.pages.eq(index+1)).addClass('is-active');
}
else {
els.pages.eq(0).addClass('is-active');
if (options.index !== 0) {
// if index is odd, we substract one.
var index = options.index&1 ? options.index-1: options.index;
els.pages.eq(index).add(els.pages.eq(index+1)).addClass('is-active');
} else {
els.pages.eq(0).addClass('is-active');
}
}

els.previousTrigger = els.pagesLeft.add(options.previousButton);
Expand Down

0 comments on commit 12801e8

Please sign in to comment.