From 3c1c9028de455909f3053174ae4eba29ebda3a9c Mon Sep 17 00:00:00 2001 From: york yao Date: Wed, 13 Sep 2017 17:03:56 +0800 Subject: [PATCH] add types of lozad --- types/lozad/index.d.ts | 25 +++++++++++++++++++++++++ types/lozad/lozad-tests.ts | 13 +++++++++++++ types/lozad/tsconfig.json | 23 +++++++++++++++++++++++ types/lozad/tslint.json | 3 +++ 4 files changed, 64 insertions(+) create mode 100644 types/lozad/index.d.ts create mode 100644 types/lozad/lozad-tests.ts create mode 100644 types/lozad/tsconfig.json create mode 100644 types/lozad/tslint.json diff --git a/types/lozad/index.d.ts b/types/lozad/index.d.ts new file mode 100644 index 0000000000..eb0213f6c3 --- /dev/null +++ b/types/lozad/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for lozad 1.0 +// Project: https://github.com/ApoorvSaxena/lozad.js +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Option { + rootMargin?: string; + threshold?: number; + load?(element: HTMLElement | HTMLCanvasElement): void; +} + +interface Observer { + observe(): void; +} + +declare function lozad(selector?: string, options?: Option): Observer; + +declare namespace lozad { + const prototype: { + }; +} + +export as namespace lozad; + +export = lozad; diff --git a/types/lozad/lozad-tests.ts b/types/lozad/lozad-tests.ts new file mode 100644 index 0000000000..ad3ff13eea --- /dev/null +++ b/types/lozad/lozad-tests.ts @@ -0,0 +1,13 @@ +import lozad = require('lozad'); + +const observer = lozad('.lozad', { + rootMargin: '10px 0px', // syntax similar to that of CSS Margin + threshold: 0.1, // ratio of element convergence + load(el) { + console.log('loading element'); + + // Custom implementation to load an element + // e.g. el.src = el.dataset.src; + } +}); +observer.observe(); diff --git a/types/lozad/tsconfig.json b/types/lozad/tsconfig.json new file mode 100644 index 0000000000..a6f9e7d96c --- /dev/null +++ b/types/lozad/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "lozad-tests.ts" + ] +} \ No newline at end of file diff --git a/types/lozad/tslint.json b/types/lozad/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/lozad/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file