Create blazy 1.5.2 definition file

- Add blazy definition file
- Add test file for blazy definitions

Definition format inspired by tinycolor: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/tinycolor
This commit is contained in:
Julien P
2016-01-25 20:20:26 +01:00
parent a3d3291370
commit ea18400bca
2 changed files with 115 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
/// <reference path="blazy.d.ts" />
/* Constructor test */
var tester: IBlazyInstance = new Blazy({
breakpoints: [
{
width: 420,
src: 'data-src-small'
},
{
width: 768,
src: 'data-src-medium'
}
],
container: '#scrolling-container',
error: function(ele: HTMLElement, msg: string) {
if (msg === 'missing') {
console.log('missing');
}
else if (msg === 'invalid') {
console.log('invalid');
}
},
errorClass: 'b-error',
loadInvisible: false,
offset: 100,
saveViewportOffsetDelay: 50,
selector: '.b-lazy',
separator: '|',
src: 'data-src',
success: function(ele: HTMLElement) {
console.log('success');
},
successClass: 'b-loaded',
validateDelay: 25
});
/* Functions tests */
tester.revalidate();
var elements = <NodeList>document.getElementsByTagName('img');
tester.load(elements, true);
tester.destroy();
+71
View File
@@ -1 +1,72 @@
// Type definitions for bLazy v1.5.2
// Project: https://github.com/dinbror/blazy
// Definitions by: Julien Paroche <https://github.com/julienpa>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/blazy
// Definitions based on: http://dinbror.dk/blog/blazy
declare var Blazy: Blazy;
interface Blazy {
new (options: IBlazyOptions): IBlazyInstance;
}
interface IBlazyOptions {
breakpoints: IBreakpoint[];
container: string;
error: (ele: Element|HTMLElement, msg: string) => void;
errorClass: string;
loadInvisible: boolean;
offset: number;
saveViewportOffsetDelay: number;
selector: string;
separator: string;
src: string;
success: (ele: Element|HTMLElement|NodeList) => void;
successClass: string;
validateDelay: number;
}
interface IBlazyInstance {
/**
* Revalidates document for visible images. Useful if you add images with scripting or ajax.
*/
revalidate(): void;
/**
* Forces the given element(s) to load if not collapsed. If you also want to load a collapsed/hidden elements you can add true as the second parameter.
* You can pass a single element or a list of elements. Tested with getElementById, getElementsByClassName, querySelectorAll, querySelector and jQuery selector.
*/
load(elements: Element|Element[]|HTMLElement|HTMLElement[]|NodeList, force: boolean): void;
/**
* Unbind events and resets image array.
*/
destroy(): void;
}
interface IBreakpoint {
width: number;
src: string;
}
declare module 'Blazy' {
export = Blazy;
}