From a9c8071440873aeea554f8e19196b73187e24db0 Mon Sep 17 00:00:00 2001 From: Julien Paroche Date: Mon, 25 Jan 2016 19:08:52 +0100 Subject: [PATCH 1/3] Create blazy.d.ts --- blazy/blazy.d.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 blazy/blazy.d.ts diff --git a/blazy/blazy.d.ts b/blazy/blazy.d.ts new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/blazy/blazy.d.ts @@ -0,0 +1 @@ + From ea18400bca3149fdaab716fc642536923d51987f Mon Sep 17 00:00:00 2001 From: Julien P Date: Mon, 25 Jan 2016 20:20:26 +0100 Subject: [PATCH 2/3] 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 000000000..700860d87 --- /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 8b1378917..49434d3b4 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; +} From 63032e4a21c1fc189688e11c465132ee356dd172 Mon Sep 17 00:00:00 2001 From: Julien P Date: Tue, 26 Jan 2016 14:24:06 +0100 Subject: [PATCH 3/3] Update after PR review, fix function parameter - Remove prefix `I` for interfaces as suggested by reviewer - Remove NodeList type for success function parameter since it's not relevant --- blazy/blazy-tests.ts | 2 +- blazy/blazy.d.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/blazy/blazy-tests.ts b/blazy/blazy-tests.ts index 700860d87..6e95801e9 100644 --- a/blazy/blazy-tests.ts +++ b/blazy/blazy-tests.ts @@ -1,7 +1,7 @@ /// /* Constructor test */ -var tester: IBlazyInstance = new Blazy({ +var tester: BlazyInstance = new Blazy({ breakpoints: [ { width: 420, diff --git a/blazy/blazy.d.ts b/blazy/blazy.d.ts index 49434d3b4..cb4747d6f 100644 --- a/blazy/blazy.d.ts +++ b/blazy/blazy.d.ts @@ -8,13 +8,13 @@ declare var Blazy: Blazy; interface Blazy { - new (options: IBlazyOptions): IBlazyInstance; + new (options: BlazyOptions): BlazyInstance; } -interface IBlazyOptions { +interface BlazyOptions { - breakpoints: IBreakpoint[]; + breakpoints: Breakpoint[]; container: string; @@ -34,7 +34,7 @@ interface IBlazyOptions { src: string; - success: (ele: Element|HTMLElement|NodeList) => void; + success: (ele: Element|HTMLElement) => void; successClass: string; @@ -42,7 +42,7 @@ interface IBlazyOptions { } -interface IBlazyInstance { +interface BlazyInstance { /** * Revalidates document for visible images. Useful if you add images with scripting or ajax. @@ -62,7 +62,7 @@ interface IBlazyInstance { } -interface IBreakpoint { +interface Breakpoint { width: number; src: string; }