Skip to content

Commit

Permalink
Merge pull request #717 from meandmax/iFixit-add-option-for-initial-i…
Browse files Browse the repository at this point in the history
…ndex

Add initial index
  • Loading branch information
meandmax authored Feb 20, 2018
2 parents 7f4d03c + 8190ffd commit 0671e10
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 13 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
15 changes: 12 additions & 3 deletions dist/jquery.lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ function lory(slider, opts) {
classNamePrevCtrl = _options4.classNamePrevCtrl,
classNameNextCtrl = _options4.classNameNextCtrl,
enableMouseEvents = _options4.enableMouseEvents,
classNameActiveSlide = _options4.classNameActiveSlide;
classNameActiveSlide = _options4.classNameActiveSlide,
initialIndex = _options4.initialIndex;


index = initialIndex;
frame = slider.getElementsByClassName(classNameFrame)[0];
slideContainer = frame.getElementsByClassName(classNameSlideContainer)[0];
prevCtrl = slider.getElementsByClassName(classNamePrevCtrl)[0];
Expand Down Expand Up @@ -437,7 +439,8 @@ function lory(slider, opts) {
ease = _options5.ease,
rewindSpeed = _options5.rewindSpeed,
rewindOnResize = _options5.rewindOnResize,
classNameActiveSlide = _options5.classNameActiveSlide;
classNameActiveSlide = _options5.classNameActiveSlide,
initialIndex = _options5.initialIndex;


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

if (rewindOnResize) {
index = 0;
index = initialIndex;
} else {
ease = null;
rewindSpeed = 0;
Expand Down Expand Up @@ -758,6 +761,12 @@ exports.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
2 changes: 1 addition & 1 deletion dist/jquery.lory.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.lory.min.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions dist/lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ function lory(slider, opts) {
classNamePrevCtrl = _options4.classNamePrevCtrl,
classNameNextCtrl = _options4.classNameNextCtrl,
enableMouseEvents = _options4.enableMouseEvents,
classNameActiveSlide = _options4.classNameActiveSlide;
classNameActiveSlide = _options4.classNameActiveSlide,
initialIndex = _options4.initialIndex;


index = initialIndex;
frame = slider.getElementsByClassName(classNameFrame)[0];
slideContainer = frame.getElementsByClassName(classNameSlideContainer)[0];
prevCtrl = slider.getElementsByClassName(classNamePrevCtrl)[0];
Expand Down Expand Up @@ -437,7 +439,8 @@ function lory(slider, opts) {
ease = _options5.ease,
rewindSpeed = _options5.rewindSpeed,
rewindOnResize = _options5.rewindOnResize,
classNameActiveSlide = _options5.classNameActiveSlide;
classNameActiveSlide = _options5.classNameActiveSlide,
initialIndex = _options5.initialIndex;


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

if (rewindOnResize) {
index = 0;
index = initialIndex;
} else {
ease = null;
rewindSpeed = 0;
Expand Down Expand Up @@ -758,6 +761,12 @@ exports.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
2 changes: 1 addition & 1 deletion dist/lory.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lory.min.js.map

Large diffs are not rendered by default.

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 0671e10

Please sign in to comment.