From 4cbff38fab64847b13f6329ac5927dc4d1a87e0d Mon Sep 17 00:00:00 2001 From: kubosho Date: Mon, 13 Apr 2015 12:39:03 +0900 Subject: [PATCH] Add callbacks in definition file & Add tests --- lory/lory-tests.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++++ lory/lory.d.ts | 60 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 lory/lory-tests.ts diff --git a/lory/lory-tests.ts b/lory/lory-tests.ts new file mode 100644 index 000000000..cb3495a62 --- /dev/null +++ b/lory/lory-tests.ts @@ -0,0 +1,62 @@ +/// + +(function() { + var elm = document.querySelector('.js-foo'); + var elm2 = document.querySelector('.js-bar'); + var elm3 = document.querySelector('.js-baz'); + var elm4 = document.querySelector('.js-foobar'); + + ////////////////////////////////////////////////// + // Init + ////////////////////////////////////////////////// + + lory(elm); + + // with options + lory(elm2, { + slidesToScroll: 1, + slideSpeed: 300, + rewindSpeed: 600, + snapBackSpeed: 200, + ease: 'ease', + rewind: true, + infinite: false + }); + + // with callbacks + lory(elm3, { + beforeInit: () => { }, + afterInit: () => { }, + beforePrev: () => { return 1; }, + beforeNext: () => { return false; }, + beforeTouch: () => { return ''; }, + beforeResize: () => { } + }); + + // with options & callbacks + lory(elm4, { + slidesToScroll: 1, + slideSpeed: 300, + rewindSpeed: 600, + snapBackSpeed: 200, + ease: 'ease', + rewind: true, + infinite: 4, + beforeInit: () => { return function() { console.log('foo') }; }, + afterInit: () => { return [0, 1]; }, + beforePrev: () => { }, + beforeNext: () => { }, + beforeTouch: () => { }, + beforeResize: () => { return {}; } + }); + + ////////////////////////////////////////////////// + // Public API + ////////////////////////////////////////////////// + + lory.setup(); + lory.prev(); + lory.next(); + lory.reset(); + lory.slideTo(1); +}()); diff --git a/lory/lory.d.ts b/lory/lory.d.ts index deee77f46..4dc7860d8 100644 --- a/lory/lory.d.ts +++ b/lory/lory.d.ts @@ -19,8 +19,7 @@ interface LoryStatic { next(): void; /** - * slides to the index given as an argument - * @param {number} index + * slides to the index given as an argument. */ slideTo(index: number): void; @@ -30,39 +29,82 @@ interface LoryStatic { setup(): void; /** - * sets the slider back to the starting position and resets the current index (called on resize event) + * sets the slider back to the starting position and resets the current index (called on resize event). */ reset(): void; } interface LoryOptions { + ////////////////////////////////////////////////// + // Options + ////////////////////////////////////////////////// + /** - * slides scrolled at once (default: 1) + * slides scrolled at once (default: 1). */ slidesToScroll?: number; /** - * time in milliseconds for the animation of a valid slide attempt (default: 300) + * time in milliseconds for the animation of a valid slide attempt (default: 300). */ slideSpeed?: number; /** - * time in milliseconds for the animation of the rewind after the last slide (default: 600) + * time in milliseconds for the animation of the rewind after the last slide (default: 600). */ rewindSpeed?: number; /** - * time for the snapBack of the slider if the slide attempt was not valid (default: 200) + * time for the snapBack of the slider if the slide attempt was not valid (default: 200). */ snapBackSpeed?: number; /** - * cubic bezier easing functions: http://easings.net/de (default: 'cubic-bezier(0.455, 0.03, 0.515, 0.955)') + * cubic bezier easing functions: http://easings.net/de (default: 'cubic-bezier(0.455, 0.03, 0.515, 0.955)'). */ ease?: string; /** - * if slider reached the last slide, with next click the slider goes back to the startindex (default: false) + * if slider reached the last slide, with next click the slider goes back to the startindex (default: false). */ rewind?: boolean; + + /** + * like carousel, works with multiple slides (default: false). (do not combine with rewind) + */ + infinite?: boolean | number; + + ////////////////////////////////////////////////// + // Callbacks + ////////////////////////////////////////////////// + + /** + * executed before initialisation (first in setup function) + */ + beforeInit?: () => T; + + /** + * executed after initialisation (end of setup function) + */ + afterInit?: () => T; + + /** + * executed on click of prev controls (prev function) + */ + beforePrev?: () => T; + + /** + * executed on click of next controls (next function) + */ + beforeNext?: () => T; + + /** + * executed on touch attempt (touchstart) + */ + beforeTouch?: () => T; + + /** + * executed on every resize event + */ + beforeResize?: () => T; }