From e111a97d1524dd6ca4f1af002d1b0b4da654af25 Mon Sep 17 00:00:00 2001 From: ziv Date: Tue, 5 Jul 2016 14:46:08 +0300 Subject: [PATCH] adding typing for scroll-into-view --- scroll-into-view/scroll-into-view-tests.ts | 24 +++++++++++++++ scroll-into-view/scroll-into-view.d.ts | 36 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 scroll-into-view/scroll-into-view-tests.ts create mode 100644 scroll-into-view/scroll-into-view.d.ts diff --git a/scroll-into-view/scroll-into-view-tests.ts b/scroll-into-view/scroll-into-view-tests.ts new file mode 100644 index 0000000000..b3b771835c --- /dev/null +++ b/scroll-into-view/scroll-into-view-tests.ts @@ -0,0 +1,24 @@ +/// +import * as scrollIntoView from "scroll-into-view" + +var someElement: HTMLElement +scrollIntoView(someElement); + +scrollIntoView(someElement, { + time: 500, // half a second + ease: function(value){ + return Math.pow(value,2) - value); // Do something weird. + }, + validTarget: function(target, parentsScrolled){ + return parentsScrolled < 2 && !target.matches('.dontScroll'); + }, + align:{ + top: 0, + left: 1 + } +}); + +scrollIntoView(someElement, function(type){ + // Scrolling done. + // type will be 'complete' if the scroll completed or 'canceled' if the current scroll was canceled by a new scroll +}) \ No newline at end of file diff --git a/scroll-into-view/scroll-into-view.d.ts b/scroll-into-view/scroll-into-view.d.ts new file mode 100644 index 0000000000..b587f36142 --- /dev/null +++ b/scroll-into-view/scroll-into-view.d.ts @@ -0,0 +1,36 @@ +// Type definitions for scroll-into-view 1.6.0 +// Project: https://github.com/KoryNunn/scroll-into-view +// Definitions by: zivni https://github.com/zivni +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module __ScrollIntoView { + + interface Settings { + time?: number + ease?: (value: number) => number + validTarget?: (target: HTMLElement, parentsScrolled: number) => boolean + align?: Alignment + } + + interface Alignment { + /** 0 to 1, default 0.5 (center) */ + top?: number + /** 0 to 1, default 0.5 (center) */ + left?: number + } + + /** type will be 'complete' if the scroll completed or 'canceled' if the current scroll was canceled by a new scroll */ + type callbackParamterType = "complete" | "canceled" + type Callback = (type: callbackParamterType) => void + + interface ScrollIntoView { + (target: HTMLElement, callback?: __ScrollIntoView.Callback) : void + (target: HTMLElement, settings: __ScrollIntoView.Settings, callback?: __ScrollIntoView.Callback) : void + } + +} + +declare module "scroll-into-view" { + var scrollIntoView: __ScrollIntoView.ScrollIntoView + export = scrollIntoView; +}