Add callbacks in definition file & Add tests

This commit is contained in:
kubosho
2015-04-13 12:39:03 +09:00
parent 2df64a9732
commit 4cbff38fab
2 changed files with 113 additions and 9 deletions
+62
View File
@@ -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);
}());
+51 -9
View File
@@ -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;
}