From ea18400bca3149fdaab716fc642536923d51987f Mon Sep 17 00:00:00 2001 From: Julien P Date: Mon, 25 Jan 2016 20:20:26 +0100 Subject: [PATCH] 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 --- blazy/blazy-tests.ts | 44 +++++++++++++++++++++++++++ blazy/blazy.d.ts | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 blazy/blazy-tests.ts diff --git a/blazy/blazy-tests.ts b/blazy/blazy-tests.ts new file mode 100644 index 0000000000..700860d87e --- /dev/null +++ b/blazy/blazy-tests.ts @@ -0,0 +1,44 @@ +/// + +/* 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 = document.getElementsByTagName('img'); +tester.load(elements, true); + +tester.destroy(); diff --git a/blazy/blazy.d.ts b/blazy/blazy.d.ts index 8b13789179..49434d3b49 100644 --- a/blazy/blazy.d.ts +++ b/blazy/blazy.d.ts @@ -1 +1,72 @@ +// Type definitions for bLazy v1.5.2 +// Project: https://github.com/dinbror/blazy +// Definitions by: Julien Paroche +// 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; +}