From 36576707565df21d7a823d636882ae438b990190 Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Fri, 6 Dec 2013 18:49:43 +0100 Subject: [PATCH] Add Angular UI Router definitions - Move angular-ui definitions to its own folder - Add self to readme - Add some tests for angular-ui-router --- README.md | 1 + angular-ui/angular-ui-router-tests.ts | 57 ++++++++++++++++++ angular-ui/angular-ui-router.d.ts | 83 +++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 angular-ui/angular-ui-router-tests.ts create mode 100644 angular-ui/angular-ui-router.d.ts diff --git a/README.md b/README.md index e0454a6b9..b326634e0 100755 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ List of Definitions * [Add To Home Screen] (http://cubiq.org/add-to-home-screen) (by [James Wilkins] (http://www.codeplex.com/site/users/view/jamesnw)) * [AmCharts](http://www.amcharts.com/) (by [Covobonomo](https://github.com/covobonomo/)) * [AngularJS](http://angularjs.org) (by [Diego Vilar](https://github.com/diegovilar)) ([wiki](https://github.com/borisyankov/DefinitelyTyped/wiki/AngularJS-Definitions-Usage-Notes)) +* [AngularUI](http://angular-ui.github.io/) (by [Michel Salib](https://github.com/michelsalib)) * [AppFramework](http://app-framework-software.intel.com/) (by [Kyo Ago](https://github.com/kyo-ago)) * [Arbiter](http://arbiterjs.com/) (by [Arash Shakery](https://github.com/arash16)) * [async](https://github.com/caolan/async) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/angular-ui/angular-ui-router-tests.ts b/angular-ui/angular-ui-router-tests.ts new file mode 100644 index 000000000..3d7ce3b5c --- /dev/null +++ b/angular-ui/angular-ui-router-tests.ts @@ -0,0 +1,57 @@ +/// + +var myApp = angular.module('testModule'); + + +myApp.config(( + $stateProvider: ng.ui.IStateProvider, + $urlRouterProvider: ng.ui.IUrlRouterProvider) => { + // + // For any unmatched url, redirect to /state1 + $urlRouterProvider.otherwise("/state1"); + // + // Now set up the states + $stateProvider + .state('state1', { + url: "/state1", + templateUrl: "partials/state1.html" + }) + .state('state1.list', { + url: "/list", + templateUrl: "partials/state1.list.html", + controller: function($scope) { + $scope.items = ["A", "List", "Of", "Items"]; + } + }) + .state('state2', { + url: "/state2", + templateUrl: "partials/state2.html" + }) + .state('state2.list', { + url: "/list", + templateUrl: "partials/state2.list.html", + controller: function($scope) { + $scope.things = ["A", "Set", "Of", "Things"]; + } + }).state('index', { + url: "", + views: { + "viewA": { template: "index.viewA" }, + "viewB": { template: "index.viewB" } + } + }) + .state('route1', { + url: "/route1", + views: { + "viewA": { template: "route1.viewA" }, + "viewB": { template: "route1.viewB" } + } + }) + .state('route2', { + url: "/route2", + views: { + "viewA": { template: "route2.viewA" }, + "viewB": { template: "route2.viewB" } + } + }); +}); \ No newline at end of file diff --git a/angular-ui/angular-ui-router.d.ts b/angular-ui/angular-ui-router.d.ts new file mode 100644 index 000000000..1046b1cb2 --- /dev/null +++ b/angular-ui/angular-ui-router.d.ts @@ -0,0 +1,83 @@ +// Type definitions for Angular JS 1.1.5+ (ui.router module) +// Project: https://github.com/angular-ui/ui-router +// Definitions by: Michel Salib +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module ng.ui { + + interface IState { + template?: any; + templateUrl?: any; + templateProvider?: () => string; + controller?: any; + controllerProvider?: any; + resolve?: {}; + url?: string; + params?: any[]; + views?: {}; + abstract?: boolean; + onEnter?: Function; + onExit?: Function; + data?: any; + } + + interface IStateProvider extends IServiceProvider { + state(name:string, config:IState): IStateProvider; + decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any; + } + + interface IUrlMatcher { + concat(pattern: string): IUrlMatcher; + exec(path: string, searchParams: {}): {}; + } + + interface IUrlMatcherFactory { + compile(pattern: string): IUrlMatcher; + isMatcher(o: any): boolean; + parameters(): string[]; + format(values: {}): string; + } + + interface IUrlRouterProvider extends IServiceProvider { + when(whenPath: string, toPath: string): IUrlRouterProvider; + when(whenPath: RegExp, toPath: string): IUrlRouterProvider; + when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider; + otherwise(path: string): IUrlRouterProvider; + otherwise(path: Function): IUrlRouterProvider; + rule(handler: Function): IUrlRouterProvider; + } + + interface IStateOptions { + location?: any; + inherit?: boolean; + relative?: IState; + notify?: boolean; + } + + interface IHrefOptions { + lossy?: boolean; + inherit?: boolean; + relative?: IState; + absolute?: boolean; + } + + interface IStateService { + go(to: string, params?: {}, options?: IStateOptions): void; + transitionTo(state: string, params?: {}, updateLocation?: boolean): void; + transitionTo(state: string, params?: {}, options?: IStateOptions): void; + includes(state: string, params?: {}): boolean; + is(state:string, params?: {}): boolean; + is(state: IState, params?: {}): boolean; + href(state: IState, params?: {}, options?: IHrefOptions): string; + href(state: string, params?: {}, options?: IHrefOptions): string; + get(state: string): IState; + get(): IState[]; + current: IState; + } + + interface IStateParamsService { + [key: string]: any; + } +}