From e7058eda4bf174b45a4cc821c3940ccfc45152e5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 16 Dec 2016 00:47:00 -0800 Subject: [PATCH] Added declarations and tests for 'pulltorefeshjs'. --- pulltorefreshjs/index.d.ts | 117 +++++++++++++++++++++++ pulltorefreshjs/pulltorefreshjs-tests.ts | 19 ++++ pulltorefreshjs/tsconfig.json | 19 ++++ pulltorefreshjs/tslint.json | 1 + 4 files changed, 156 insertions(+) create mode 100644 pulltorefreshjs/index.d.ts create mode 100644 pulltorefreshjs/pulltorefreshjs-tests.ts create mode 100644 pulltorefreshjs/tsconfig.json create mode 100644 pulltorefreshjs/tslint.json diff --git a/pulltorefreshjs/index.d.ts b/pulltorefreshjs/index.d.ts new file mode 100644 index 0000000000..e26af8e54c --- /dev/null +++ b/pulltorefreshjs/index.d.ts @@ -0,0 +1,117 @@ +// Type definitions for pulltorefreshjs 0.1 +// Project: https://github.com/BoxFactura/pulltorefresh.js +// Definitions by: Daniel Rosenwasser +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function init(options?: Options): void; + +export interface Options { + /** + * Minimum distance required to trigger the refresh. + * (default: `60`) + */ + distThreshold?: number; + + /** + * Maximum distance possible for the element. + * (default: `80`) + */ + distMax?: number; + + /** + * After the `distThreshold` is reached and released, the element will have this height. + * (default: `50`) + */ + distReload?: number; + + /** + * Before which element the pull to refresh elements will be? + * (default: `body`) + */ + mainElement?: string; + + /** + * Which element should trigger the pull to refresh? + * (default: `body`) + */ + triggerElement?: string; + + /** + * What class will the main element have? + * (default: `.ptr`) + */ + ptrElement?: string; + + /** + * What class prefix for the elements? + * (default: `ptr--`) + */ + classPrefix?: string; + + /** + * What property will be used to calculate the element's proportions? + * (default: `min-height`) + */ + cssProp?: string; + + /** + * The icon for both `instructionsPullToRefresh` and `instructionsReleaseToRefresh` + * (default: `⇣`) + */ + iconArrow?: string; + + /** + * The icon when the refresh is in progress. + * (default: `…`) + */ + iconRefreshing?: string; + + /** + * The initial instructions string. + * (default: `Pull down to refresh`) + */ + instructionsPullToRefresh?: string; + + /** + * The instructions string when the `distThreshold` has been reached. + * (default: `Release to refresh`) + */ + instructionsReleaseToRefresh?: string; + + /** + * The refreshing text. + * (default: `Refreshing`) + */ + instructionsRefreshing?: string; + + /** + * The delay, in milliseconds before the `onRefresh` is triggered. + * (default: `500`) + */ + refreshTimeout?: number; + + /** + * The initialize function. + */ + onInit?: () => void; + + /** + * What will the pull to refresh trigger? You can return a promise. + * + * Defaults to `window.location.reload()` + */ + onRefresh?: (() => PromiseLike) | (() => void); + + + /** + * The resistance function, accepts one parameter, must return a number, capping at 1. + * + * Defaults to `t => Math.min(1, t / 2.5)` + */ + resistanceFunction?: (input: number) => number; +} + +/** + * If no loader is present, this module is available as a global. + */ +export as namespace PullToRefresh; \ No newline at end of file diff --git a/pulltorefreshjs/pulltorefreshjs-tests.ts b/pulltorefreshjs/pulltorefreshjs-tests.ts new file mode 100644 index 0000000000..b971e7a92d --- /dev/null +++ b/pulltorefreshjs/pulltorefreshjs-tests.ts @@ -0,0 +1,19 @@ +import * as PullToRefresh from "pulltorefreshjs"; + +PullToRefresh.init(); + +PullToRefresh.init({}); + +PullToRefresh.init({ + mainElement: "body", + onRefresh: () => { window.location.reload(); }, +}); + +PullToRefresh.init({ + resistanceFunction: x => Math.sqrt(x), +}); + +PullToRefresh.init({ + mainElement: "body", + onRefresh: () => Promise.resolve(), +}); \ No newline at end of file diff --git a/pulltorefreshjs/tsconfig.json b/pulltorefreshjs/tsconfig.json new file mode 100644 index 0000000000..199c61cf0e --- /dev/null +++ b/pulltorefreshjs/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pulltorefreshjs-tests.ts" + ] +} diff --git a/pulltorefreshjs/tslint.json b/pulltorefreshjs/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/pulltorefreshjs/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }