diff --git a/angularjs-toaster/angularjs-toaster-tests.ts b/angularjs-toaster/angularjs-toaster-tests.ts new file mode 100644 index 0000000000..ffff321596 --- /dev/null +++ b/angularjs-toaster/angularjs-toaster-tests.ts @@ -0,0 +1,42 @@ +/// +class NgToasterTestController { + constructor(public $scope: ng.IScope, public $window: ng.IWindowService, public toaster: ngtoaster.IToasterService) { + this.bar = 'Hi'; + } + bar: string; + + pop(): void { + this.toaster.success({ title: "title", body: "text1" }); + this.toaster.error("title", "text2"); + this.toaster.pop({ type: 'wait', title: "title", body: "text" }); + this.toaster.pop('success', "title", '', 5000, 'trustedHtml'); + this.toaster.pop('error', "title", '', null, 'trustedHtml'); + this.toaster.pop('wait', "title", null, null, 'template'); + this.toaster.pop('warning', "title", "myTemplate.html", null, 'template'); + this.toaster.pop('note', "title", "text"); + this.toaster.pop('success', "title", 'Its address is https://google.com.', 5000, 'trustedHtml', (toaster: ngtoaster.IToast): boolean => { + var match = toaster.body.match(/http[s]?:\/\/[^\s]+/); + if (match) { + this.$window.open(match[0]); + } + return true; + }); + this.toaster.pop('warning', "Hi ", "{template: 'myTemplateWithData.html', data: 'MyData'}", 15000, 'templateWithData'); + } + + goToLink(toaster: ngtoaster.IToast): boolean { + var match = toaster.body.match(/http[s]?:\/\/[^\s]+/); + if (match) { + this.$window.open(match[0]); + } + return true; + } + + clear(): void { + this.toaster.clear(); + } +} + +angular + .module('main', ['ngAnimate', 'toaster']) + .controller('myController', NgToasterTestController); \ No newline at end of file diff --git a/angularjs-toaster/angularjs-toaster.d.ts b/angularjs-toaster/angularjs-toaster.d.ts new file mode 100644 index 0000000000..3987045141 --- /dev/null +++ b/angularjs-toaster/angularjs-toaster.d.ts @@ -0,0 +1,109 @@ +// Type definitions for angularjs-toaster v0.4.13 +// Project: https://github.com/jirikavi/AngularJS-Toaster +// Definitions by: Ben Tesser +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module ngtoaster { + interface IToasterService { + pop(params:IPopParams): void + /** + * @param {string} type Type of toaster -- 'error', 'info', 'wait', 'success', and 'warning' + */ + pop(type?:string, title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number, showCloseButton?:boolean): void + error(params: IPopParams): void + error(title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number): void + into(params: IPopParams): void + info(title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number): void + wait(params: IPopParams): void + wait(title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number): void + success(params: IPopParams): void + success(title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number): void + warning(params: IPopParams): void + warning(title?:string, body?:string, timeout?:number, bodyOutputType?:string, clickHandler?:EventListener, + toasterId?:number): void + clear(): void + toast:IToast; + } + + interface IToasterEventRegistry { + setup(): void + subscribeToNewToastEvent(onNewToast:IToastEventListener): void + subscribeToClearToastsEvent(onClearToasts:IToastEventListener): void + unsubscribeToNewToastEvent(onNewToast:IToastEventListener): void + unsubscribeToClearToastsEvent(onClearToasts:IToastEventListener): void + } + + interface IPopParams extends IToast{ + toasterId?: number; + } + + interface IToastEventListener { + (event:Event, toasterId: number): void; + } + + interface IToast { + /** + * Acceptable types are: + * 'error', 'info', 'wait', 'success', and 'warning' + */ + type?: string; + title?: string; + body?: string; + timeout?: number; + bodyOutputType?: string; + clickHandler?: EventListener; + showCloseButton?: boolean; + } + + interface IToasterConfig { + /** + * limits max number of toasts + */ + limit?: number; + 'tap-to-dismiss'?: boolean; + 'close-button'?: boolean; + 'newest-on-top'?: boolean; + 'time-out'?: number; + 'icon-classes'?: IIconClasses; + /** + * Options include: + * '', 'trustedHtml', 'template', 'templateWithData' + */ + 'body-output-type'?: string; + 'body-template'?: string; + 'icon-class'?: string; + /** + * Options include: + * 'toast-top-full-width', 'toast-bottom-full-width', 'toast-center', + * 'toast-top-left', 'toast-top-center', 'toast-top-rigt', + * 'toast-bottom-left', 'toast-bottom-center', 'toast-bottom-rigt', + */ + 'position-class'?: string; + 'title-class'?: string; + 'message-class'?: string; + 'prevent-duplicates'?: boolean; + /** + * stop timeout on mouseover and restart timer on mouseout + */ + 'mouseover-timer-stop'?: boolean; + } + + interface IIconClasses { + error: string; + info: string; + wait: string; + success: string; + warning: string; + } +} + +declare module "ngtoaster" { + export = ngtoaster +}