Skip to content

Commit

Permalink
Merge branch 'add-option-for-initial-index' of https://github.com/iFi…
Browse files Browse the repository at this point in the history
…xit/lory into iFixit-add-option-for-initial-index
  • Loading branch information
Maximilian Heinz committed Feb 20, 2018
2 parents 265b2c8 + af72422 commit e1c38d6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ li {
<td>cubic bezier easing functions: http://easings.net/de</td>
<td>default: 'ease'</td>
</tr>
<tr>
<td>initialIndex</td>
<td>the slide index to show when the slider is initialized</td>
<td>default: 0</td>
</tr>
<tr>
<td>classNameFrame</td>
<td>class name for slider frame</td>
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ <h2>Options</h2>
<td>time for the snapBack of the slider if the slide attempt was not valid</td>
<td>default: 200</td>
</tr>
<tr>
<td>initialIndex</td>
<td>the slide index to show when the slider is initialized</td>
<td>default: 0</td>
</tr>
<tr>
<th>ease</th>
<td>cubic bezier easing functions: http://easings.net/de</td>
Expand Down
6 changes: 6 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export default {
*/
infinite: false,

/**
* the slide index to show when the slider is initialized.
* @initialIndex {number}
*/
initialIndex: 0,

/**
* class name for slider frame
* @classNameFrame {string}
Expand Down
8 changes: 5 additions & 3 deletions src/lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ export function lory (slider, opts) {
classNamePrevCtrl,
classNameNextCtrl,
enableMouseEvents,
classNameActiveSlide
classNameActiveSlide,
initialIndex
} = options;

index = initialIndex;
frame = slider.getElementsByClassName(classNameFrame)[0];
slideContainer = frame.getElementsByClassName(classNameSlideContainer)[0];
prevCtrl = slider.getElementsByClassName(classNamePrevCtrl)[0];
Expand Down Expand Up @@ -298,7 +300,7 @@ export function lory (slider, opts) {
* reset function: called on resize
*/
function reset () {
var {infinite, ease, rewindSpeed, rewindOnResize, classNameActiveSlide} = options;
var {infinite, ease, rewindSpeed, rewindOnResize, classNameActiveSlide, initialIndex} = options;

slidesWidth = slideContainer.getBoundingClientRect()
.width || slideContainer.offsetWidth;
Expand All @@ -312,7 +314,7 @@ export function lory (slider, opts) {
}

if (rewindOnResize) {
index = 0;
index = initialIndex;
} else {
ease = null;
rewindSpeed = 0;
Expand Down
20 changes: 20 additions & 0 deletions test/lory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,26 @@ describe('lory()', function () {
});
});
});

describe('with initialIndex', function () {
beforeEach(function () {
instance = lory(element, {
initialIndex: 3
});
});

describe('called once', function() {
var expectedIndex = 2;

beforeEach(function () {
instance.prev();
});

it('index has to be 2 (one less than initialIndex)', function() {
assert.equal(instance.returnIndex(), expectedIndex);
});
});
});
});

describe('.destroy()', function () {
Expand Down

0 comments on commit e1c38d6

Please sign in to comment.