From 24e9266e49a6957cc61230ce4558b8bc965ef9fc Mon Sep 17 00:00:00 2001 From: Sam Herrmann Date: Sat, 3 Jan 2015 22:09:58 -0500 Subject: [PATCH] Add angular-scroll definitions --- angular-scroll/angular-scroll-tests.ts | 64 ++++++++++++++++++++++++++ angular-scroll/angular-scroll.d.ts | 44 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 angular-scroll/angular-scroll-tests.ts create mode 100644 angular-scroll/angular-scroll.d.ts diff --git a/angular-scroll/angular-scroll-tests.ts b/angular-scroll/angular-scroll-tests.ts new file mode 100644 index 0000000000..cd4a4fbca1 --- /dev/null +++ b/angular-scroll/angular-scroll-tests.ts @@ -0,0 +1,64 @@ +/// + +module TestApp { + + class TestController { + + constructor($scope: ng.IScope, $document: duScroll.IDocumentService) { + var positionFromTop = 400; + var positionFromLeft = 200; + var offsetInPixels = 100; + var durationInMillis = 2000; + var someElement: ng.IAugmentedJQuery; + + $document.duScrollTo(positionFromLeft, positionFromTop); + $document.duScrollTo(positionFromLeft, positionFromTop, durationInMillis).then(this.onScrollCompleted); + $document.duScrollTo(positionFromLeft, positionFromTop, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollTo(someElement); + $document.duScrollTo(someElement, offsetInPixels); + $document.duScrollTo(someElement, offsetInPixels, durationInMillis).then(this.onScrollCompleted); + $document.duScrollTo(someElement, offsetInPixels, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollToElement(someElement); + $document.duScrollToElement(someElement, offsetInPixels); + $document.duScrollToElement(someElement, offsetInPixels, durationInMillis).then(this.onScrollCompleted); + $document.duScrollToElement(someElement, offsetInPixels, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollToElementAnimated(someElement).then(this.onScrollCompleted); + $document.duScrollToElementAnimated(someElement, offsetInPixels).then(this.onScrollCompleted); + $document.duScrollToElementAnimated(someElement, offsetInPixels, durationInMillis).then(this.onScrollCompleted); + $document.duScrollToElementAnimated(someElement, offsetInPixels, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollTop(positionFromTop); + $document.duScrollTop(positionFromTop, durationInMillis).then(this.onScrollCompleted); + $document.duScrollTop(positionFromTop, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollTopAnimated(positionFromTop).then(this.onScrollCompleted); + $document.duScrollTopAnimated(positionFromTop, durationInMillis).then(this.onScrollCompleted); + $document.duScrollTopAnimated(positionFromTop, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollLeft(positionFromLeft); + $document.duScrollLeft(positionFromLeft, durationInMillis).then(this.onScrollCompleted); + $document.duScrollLeft(positionFromLeft, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + $document.duScrollLeftAnimated(positionFromLeft).then(this.onScrollCompleted); + $document.duScrollLeftAnimated(positionFromLeft, durationInMillis).then(this.onScrollCompleted); + $document.duScrollLeftAnimated(positionFromLeft, durationInMillis, this.invertedEasingFn).then(this.onScrollCompleted); + + var verticalPosition: number = $document.duScrollTop(); + var horixontalPosition: number = $document.duScrollLeft(); + } + + private invertedEasingFn = (x: number): number => { + return 1 - x; + } + + private onScrollCompleted = (): void => { + console.log('Done scrolling'); + } + } + + angular.module('testApp', ['duScroll']) + .controller('testController', TestController); +} \ No newline at end of file diff --git a/angular-scroll/angular-scroll.d.ts b/angular-scroll/angular-scroll.d.ts new file mode 100644 index 0000000000..354ecf3d1a --- /dev/null +++ b/angular-scroll/angular-scroll.d.ts @@ -0,0 +1,44 @@ +// Type definitions for angular-scroll +// Project: https://github.com/oblador/angular-scroll +// Definitions by: Sam Herrmann +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +/// + +declare module duScroll { + + /** + * Extends the angular.element object returned by the $document sercive with a few jQuery like functions. + * see https://github.com/oblador/angular-scroll#angularelement-scroll-api + */ + interface IDocumentService extends ng.IDocumentService { + + duScrollTo(left: number, top: number): void; + duScrollTo(left: number, top: number, duration: number, easing?: Function): ng.IPromise; + + duScrollTo(element: ng.IAugmentedJQuery, offset?: number): void; + duScrollTo(element: ng.IAugmentedJQuery, offset: number, duration: number, easing?: Function): ng.IPromise; + + duScrollToElement(element: ng.IAugmentedJQuery, offset?: number): void; + duScrollToElement(element: ng.IAugmentedJQuery, offset: number, duration: number, easing?: Function): ng.IPromise; + + duScrollToElementAnimated(element: ng.IAugmentedJQuery, offset?: number): ng.IPromise; + duScrollToElementAnimated(element: ng.IAugmentedJQuery, offset: number, duration: number, easing?: Function): ng.IPromise; + + duScrollTop(top: number): void; + duScrollTop(top: number, duration: number, easing?: Function): ng.IPromise; + + duScrollTopAnimated(top: number): ng.IPromise; + duScrollTopAnimated(top: number, duration: number, easing?: Function): ng.IPromise; + + duScrollLeft(left: number): void; + duScrollLeft(left: number, duration: number, easing?: Function): ng.IPromise; + + duScrollLeftAnimated(left: number): ng.IPromise; + duScrollLeftAnimated(left: number, duration: number, easing?: Function): ng.IPromise; + + duScrollTop(): number; + duScrollLeft(): number; + } +} \ No newline at end of file