From c7f1b568bdda4df1cd2070f8d60db89b5396defd Mon Sep 17 00:00:00 2001 From: Paul Lessing Date: Thu, 12 Nov 2015 22:54:36 +0000 Subject: [PATCH] Add angular-modal.d.ts Valid for https://github.com/btford/angular-modal v0.5.0 --- angular-modal/angular-modal-tests.ts | 104 +++++++++++++++++++++++++++ angular-modal/angular-modal.d.ts | 38 ++++++++++ 2 files changed, 142 insertions(+) create mode 100644 angular-modal/angular-modal-tests.ts create mode 100644 angular-modal/angular-modal.d.ts diff --git a/angular-modal/angular-modal-tests.ts b/angular-modal/angular-modal-tests.ts new file mode 100644 index 00000000000000..cbb090cee90ee3 --- /dev/null +++ b/angular-modal/angular-modal-tests.ts @@ -0,0 +1,104 @@ +/// +/// +/// + +var btfModal: angularModal.AngularModalFactory; + +// Using template URL +function withTemplateUrl() { + btfModal({ + controller: 'SomeController', + controllerAs: 'vm', + templateUrl: 'some-template.html' + }); +} + +// Using template +function withTemplate() { + btfModal({ + controller: 'SomeController', + controllerAs: 'vm', + template: '
' + }); +} + +// Using controller function +function withControllerAsFunction() { + btfModal({ + controller: function () {}, + template: '
' + }) +} + +// Using constructor function +function withControllerClass() { + class TestController { + constructor(dependency1:any, dependency2:any) {} + } + btfModal({ + controller: TestController, + template: '
' + }); +} + +// With container as selector +function withContainerAsString() { + btfModal({ + template: '
', + container: '.container' + }); +} + +// With container as jQuery element +function withContainerAsJquery() { + var container: JQuery = $('body'); + btfModal({ + template: '
', + container: container + }); +} + +// With container as DOM Element +function withContainerAsDom() { + var container: Element = document.getElementById('container'); + btfModal({ + template: '
', + container: container + }); +} + +// With container as DOM Element Array +function withContainerAsDomArray() { + var container: Element[] = [document.getElementById('container'), document.getElementById('container2')]; + btfModal({ + template: '
', + container: container + }); +} + +// With container as function +function withContainerAsFunction() { + btfModal({ + template: '
', + container: function() {} + }); +} + +// With container as array +function withContainerAsArray() { + btfModal({ + template: '
', + container: ['1', 2] + }); +} + +// Calling return values +function callingValues() { + var modal: angularModal.AngularModal = btfModal({ + template: '
' + }); + modal.activate().then(() => {}, () => {}); + modal.deactivate().then(() => {}, () => {}); + var isActive: boolean = modal.active(); +} + diff --git a/angular-modal/angular-modal.d.ts b/angular-modal/angular-modal.d.ts new file mode 100644 index 00000000000000..0effea95ccf578 --- /dev/null +++ b/angular-modal/angular-modal.d.ts @@ -0,0 +1,38 @@ +// Type definitions for angular-modal 0.5.0 +// Project: https://github.com/btford/angular-modal +// Definitions by: Paul Lessing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module angularModal { + + type AngularModalControllerDefinition = (new (...args: any[]) => any) | Function | string; // Possible arguments to IControllerService + + type AngularModalJQuerySelector = string | Element | Element[] | JQuery | Function | any[] | {}; // Possible arguments to IAugmentedJQueryStatic + + interface AngularModalSettings { + controller?: AngularModalControllerDefinition; + controllerAs?: string; + container?: AngularModalJQuerySelector; + } + + export interface AngularModalSettingsWithTemplate extends AngularModalSettings { + template: any; + } + + export interface AngularModalSettingsWithTemplateUrl extends AngularModalSettings { + templateUrl: string; + } + + export interface AngularModal { + activate(): angular.IPromise; + deactivate(): angular.IPromise; + active(): boolean; + } + + export interface AngularModalFactory { + (settings: AngularModalSettingsWithTemplate | AngularModalSettingsWithTemplateUrl): AngularModal; + } +}