From cf19cfd7e07729859c03baf5e5d5a8898001e37d Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Tue, 4 Apr 2017 16:49:57 -0700 Subject: [PATCH 1/3] add option initialIndex Allow the slider to start at any slide when it is first initialized. Previously, it would always start at slide index 0. --- src/defaults.js | 6 ++++++ src/lory.js | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/defaults.js b/src/defaults.js index 9973bc0..5615b6e 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -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} diff --git a/src/lory.js b/src/lory.js index fc2b361..91ca0e2 100644 --- a/src/lory.js +++ b/src/lory.js @@ -219,9 +219,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]; @@ -266,7 +268,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; @@ -280,7 +282,7 @@ export function lory (slider, opts) { } if (rewindOnResize) { - index = 0; + index = initialIndex; } else { ease = null; rewindSpeed = 0; From a7de09439ed0394f5189fb06e0a2877b12ec705b Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Tue, 4 Apr 2017 17:09:15 -0700 Subject: [PATCH 2/3] initialIndex: update documentation --- README.md | 5 +++++ index.html | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 2c50abe..518ad2d 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,11 @@ li { cubic bezier easing functions: http://easings.net/de default: 'ease' + + initialIndex + the slide index to show when the slider is initialized + default: 0 + classNameFrame class name for slider frame diff --git a/index.html b/index.html index c4f1f0b..e81795c 100644 --- a/index.html +++ b/index.html @@ -698,6 +698,11 @@

Options

time for the snapBack of the slider if the slide attempt was not valid default: 200 + + initialIndex + the slide index to show when the slider is initialized + default: 0 + ease cubic bezier easing functions: http://easings.net/de From af72422c9538e1b795ae617557688fbe8be47d9c Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Tue, 4 Apr 2017 17:32:05 -0700 Subject: [PATCH 3/3] initialIndex: add test --- test/lory.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/lory.test.js b/test/lory.test.js index ab86d70..99547df 100644 --- a/test/lory.test.js +++ b/test/lory.test.js @@ -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 () {