mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add callbacks in definition file & Add tests
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/// <reference path="./lory.d.ts" />
|
||||
|
||||
(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);
|
||||
}());
|
||||
Vendored
+51
-9
@@ -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>() => T;
|
||||
|
||||
/**
|
||||
* executed after initialisation (end of setup function)
|
||||
*/
|
||||
afterInit?: <T>() => T;
|
||||
|
||||
/**
|
||||
* executed on click of prev controls (prev function)
|
||||
*/
|
||||
beforePrev?: <T>() => T;
|
||||
|
||||
/**
|
||||
* executed on click of next controls (next function)
|
||||
*/
|
||||
beforeNext?: <T>() => T;
|
||||
|
||||
/**
|
||||
* executed on touch attempt (touchstart)
|
||||
*/
|
||||
beforeTouch?: <T>() => T;
|
||||
|
||||
/**
|
||||
* executed on every resize event
|
||||
*/
|
||||
beforeResize?: <T>() => T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user