mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Added type definitions for layzr.js (#29372)
This commit is contained in:
committed by
Wesley Wigham
parent
0378d4e1ac
commit
b2c9fc89f9
82
types/layzr.js/index.d.ts
vendored
Normal file
82
types/layzr.js/index.d.ts
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
// Type definitions for layzr.js 2.2
|
||||
// Project: https://github.com/callmecavs/layzr.js
|
||||
// Definitions by: Rostislav Shermenyov <https://github.com/shermendev>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace Layzr {
|
||||
type LayzrEvents = "src:before" | "src:after";
|
||||
|
||||
interface LayzrInstance {
|
||||
/**
|
||||
* Manually check if elements are in the viewport. This method is called while the window is scrolled or resized.
|
||||
*/
|
||||
check(): LayzrInstance;
|
||||
/**
|
||||
* Emit an event, firing all of its handlers.
|
||||
* @param name Event name
|
||||
* @param args Arguments that will be passed to each handler
|
||||
*/
|
||||
emit(name: LayzrEvents, ...args: any[]): LayzrInstance;
|
||||
/**
|
||||
* Add or remove the scroll and resize event handlers.
|
||||
* @param flag
|
||||
*/
|
||||
handlers(flag: boolean): LayzrInstance;
|
||||
/**
|
||||
* Remove a specific handler from an event.
|
||||
* @param name Event name
|
||||
* @param handler Event handler
|
||||
*/
|
||||
off(name: LayzrEvents, handler?: () => {}): LayzrInstance;
|
||||
/**
|
||||
* This event is emitted immediately before/after an image source is set. The image node is passed to the event handler.
|
||||
* @param name Event name
|
||||
* @param handler Event handler
|
||||
*/
|
||||
on(
|
||||
name: LayzrEvents,
|
||||
handler: (element: HTMLElement) => void
|
||||
): LayzrInstance;
|
||||
/**
|
||||
* This event is emitted immediately before/after an image source is set. The image node is passed to the event handler. Fires once.
|
||||
* @param name Event name
|
||||
* @param handler Event handler
|
||||
*/
|
||||
once(
|
||||
name: LayzrEvents,
|
||||
handler: (element: HTMLElement) => void
|
||||
): LayzrInstance;
|
||||
/**
|
||||
* Update the elements Layzr is checking.
|
||||
*/
|
||||
update(): LayzrInstance;
|
||||
}
|
||||
|
||||
interface LayzrOptions {
|
||||
/**
|
||||
* Customize the attribute the normal resolution source is taken from.
|
||||
*/
|
||||
normal?: string;
|
||||
/**
|
||||
* Customize the attribute the retina/high resolution source is taken from.
|
||||
*/
|
||||
retina?: string;
|
||||
/**
|
||||
* Customize the attribute the source set is taken from.
|
||||
*/
|
||||
srcset?: string;
|
||||
/**
|
||||
* Adjust when images load, relative to the viewport. Positive values make images load sooner, negative values make images load later.
|
||||
*
|
||||
* Threshold is a percentage of the viewport height, identical to the CSS vh unit.
|
||||
*/
|
||||
threshold?: number;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param options Options
|
||||
*/
|
||||
declare function Layzr(options?: Layzr.LayzrOptions): Layzr.LayzrInstance;
|
||||
|
||||
export = Layzr;
|
||||
export as namespace Layzr;
|
||||
32
types/layzr.js/layzr.js-tests.ts
Normal file
32
types/layzr.js/layzr.js-tests.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as Layzr from "layzr.js";
|
||||
|
||||
const options: Layzr.LayzrOptions = {
|
||||
normal: "data-normal",
|
||||
retina: "data-retina",
|
||||
srcset: "data-srcset",
|
||||
threshold: 0
|
||||
};
|
||||
|
||||
const instance = Layzr();
|
||||
const instance2 = Layzr(options);
|
||||
|
||||
instance.emit("src:before", 4, "yg", () => {});
|
||||
|
||||
instance
|
||||
.on("src:before", element => {
|
||||
console.log(element);
|
||||
})
|
||||
.once("src:before", element => {
|
||||
console.log(element);
|
||||
})
|
||||
.on("src:after", element => {
|
||||
console.log(element);
|
||||
})
|
||||
.once("src:after", element => {
|
||||
console.log(element);
|
||||
})
|
||||
.handlers(true)
|
||||
.check()
|
||||
.update()
|
||||
.emit("src:before")
|
||||
.off("src:after");
|
||||
24
types/layzr.js/tsconfig.json
Normal file
24
types/layzr.js/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"layzr.js-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/layzr.js/tslint.json
Normal file
3
types/layzr.js/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user