Skip to content

Commit b3df8c8

Browse files
committed
Merge pull request DefinitelyTyped#7788 from julienpa/blazy
Create blazy 1.5.2 definition file
2 parents 89a0417 + 63032e4 commit b3df8c8

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

blazy/blazy-tests.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference path="blazy.d.ts" />
2+
3+
/* Constructor test */
4+
var tester: BlazyInstance = new Blazy({
5+
breakpoints: [
6+
{
7+
width: 420,
8+
src: 'data-src-small'
9+
},
10+
{
11+
width: 768,
12+
src: 'data-src-medium'
13+
}
14+
],
15+
container: '#scrolling-container',
16+
error: function(ele: HTMLElement, msg: string) {
17+
if (msg === 'missing') {
18+
console.log('missing');
19+
}
20+
else if (msg === 'invalid') {
21+
console.log('invalid');
22+
}
23+
},
24+
errorClass: 'b-error',
25+
loadInvisible: false,
26+
offset: 100,
27+
saveViewportOffsetDelay: 50,
28+
selector: '.b-lazy',
29+
separator: '|',
30+
src: 'data-src',
31+
success: function(ele: HTMLElement) {
32+
console.log('success');
33+
},
34+
successClass: 'b-loaded',
35+
validateDelay: 25
36+
});
37+
38+
/* Functions tests */
39+
tester.revalidate();
40+
41+
var elements = <NodeList>document.getElementsByTagName('img');
42+
tester.load(elements, true);
43+
44+
tester.destroy();

blazy/blazy.d.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Type definitions for bLazy v1.5.2
2+
// Project: https://github.com/dinbror/blazy
3+
// Definitions by: Julien Paroche <https://github.com/julienpa>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/blazy
5+
// Definitions based on: http://dinbror.dk/blog/blazy
6+
7+
declare var Blazy: Blazy;
8+
9+
interface Blazy {
10+
11+
new (options: BlazyOptions): BlazyInstance;
12+
13+
}
14+
15+
interface BlazyOptions {
16+
17+
breakpoints: Breakpoint[];
18+
19+
container: string;
20+
21+
error: (ele: Element|HTMLElement, msg: string) => void;
22+
23+
errorClass: string;
24+
25+
loadInvisible: boolean;
26+
27+
offset: number;
28+
29+
saveViewportOffsetDelay: number;
30+
31+
selector: string;
32+
33+
separator: string;
34+
35+
src: string;
36+
37+
success: (ele: Element|HTMLElement) => void;
38+
39+
successClass: string;
40+
41+
validateDelay: number;
42+
43+
}
44+
45+
interface BlazyInstance {
46+
47+
/**
48+
* Revalidates document for visible images. Useful if you add images with scripting or ajax.
49+
*/
50+
revalidate(): void;
51+
52+
/**
53+
* 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.
54+
* You can pass a single element or a list of elements. Tested with getElementById, getElementsByClassName, querySelectorAll, querySelector and jQuery selector.
55+
*/
56+
load(elements: Element|Element[]|HTMLElement|HTMLElement[]|NodeList, force: boolean): void;
57+
58+
/**
59+
* Unbind events and resets image array.
60+
*/
61+
destroy(): void;
62+
63+
}
64+
65+
interface Breakpoint {
66+
width: number;
67+
src: string;
68+
}
69+
70+
declare module 'Blazy' {
71+
export = Blazy;
72+
}

0 commit comments

Comments
 (0)