From 2df64a97328bf1d6e15aa97616bdbb47c0adec73 Mon Sep 17 00:00:00 2001 From: kubosho Date: Fri, 10 Apr 2015 20:55:10 +0900 Subject: [PATCH 1/5] Add lory definition file --- lory/lory.d.ts | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lory/lory.d.ts diff --git a/lory/lory.d.ts b/lory/lory.d.ts new file mode 100644 index 000000000..deee77f46 --- /dev/null +++ b/lory/lory.d.ts @@ -0,0 +1,68 @@ +// Type definitions for lory 0.4.3 +// Project: https://github.com/meandmax/lory/ +// Definitions by: kubosho +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var lory: LoryStatic; + +interface LoryStatic { + (element: Element, options?: LoryOptions): LoryStatic; + + /** + * slides to the previous slide. + */ + prev(): void; + + /** + * slides to the next slide. + */ + next(): void; + + /** + * slides to the index given as an argument + * @param {number} index + */ + slideTo(index: number): void; + + /** + * binds eventlisteners, merging default and user options, setup the slides based on DOM (called once during initialisation). Call setup if DOM or user options have changed or eventlisteners needs to be rebinded. + */ + setup(): void; + + /** + * sets the slider back to the starting position and resets the current index (called on resize event) + */ + reset(): void; +} + +interface LoryOptions { + /** + * slides scrolled at once (default: 1) + */ + slidesToScroll?: number; + + /** + * 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) + */ + rewindSpeed?: number; + + /** + * 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)') + */ + ease?: string; + + /** + * if slider reached the last slide, with next click the slider goes back to the startindex (default: false) + */ + rewind?: boolean; +} From 4cbff38fab64847b13f6329ac5927dc4d1a87e0d Mon Sep 17 00:00:00 2001 From: kubosho Date: Mon, 13 Apr 2015 12:39:03 +0900 Subject: [PATCH 2/5] 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; } From f0182837ce59520f051049f6f4b6bd5d335cf346 Mon Sep 17 00:00:00 2001 From: kubosho Date: Tue, 14 Apr 2015 10:07:45 +0900 Subject: [PATCH 3/5] Rename files (lory -> lory.js) --- lory/{lory-tests.ts => lory.js-tests.ts} | 0 lory/{lory.d.ts => lory.js.d.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename lory/{lory-tests.ts => lory.js-tests.ts} (100%) rename lory/{lory.d.ts => lory.js.d.ts} (100%) diff --git a/lory/lory-tests.ts b/lory/lory.js-tests.ts similarity index 100% rename from lory/lory-tests.ts rename to lory/lory.js-tests.ts diff --git a/lory/lory.d.ts b/lory/lory.js.d.ts similarity index 100% rename from lory/lory.d.ts rename to lory/lory.js.d.ts From dcbe740826b2a969190ce621bf9a3ad5ece68efc Mon Sep 17 00:00:00 2001 From: kubosho Date: Tue, 14 Apr 2015 10:12:26 +0900 Subject: [PATCH 4/5] Fix correct file path --- lory/lory.js-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lory/lory.js-tests.ts b/lory/lory.js-tests.ts index cb3495a62..4247dceca 100644 --- a/lory/lory.js-tests.ts +++ b/lory/lory.js-tests.ts @@ -1,4 +1,4 @@ -/// +/// (function() { var elm = document.querySelector('.js-foo'); From 926c4e288034005ff810cf8bbc3eda76ab5646d7 Mon Sep 17 00:00:00 2001 From: kubosho Date: Tue, 14 Apr 2015 10:25:43 +0900 Subject: [PATCH 5/5] Change directory name (lory -> lory.js) --- {lory => lory.js}/lory.js-tests.ts | 0 {lory => lory.js}/lory.js.d.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {lory => lory.js}/lory.js-tests.ts (100%) rename {lory => lory.js}/lory.js.d.ts (100%) diff --git a/lory/lory.js-tests.ts b/lory.js/lory.js-tests.ts similarity index 100% rename from lory/lory.js-tests.ts rename to lory.js/lory.js-tests.ts diff --git a/lory/lory.js.d.ts b/lory.js/lory.js.d.ts similarity index 100% rename from lory/lory.js.d.ts rename to lory.js/lory.js.d.ts