diff --git a/types/ngtoaster/index.d.ts b/types/ngtoaster/index.d.ts index caf9bd0539..092e1a7b0e 100644 --- a/types/ngtoaster/index.d.ts +++ b/types/ngtoaster/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for angularjs-toaster v0.4.13 +// Type definitions for angularjs-toaster 2.2 // Project: https://github.com/jirikavi/AngularJS-Toaster // Definitions by: Ben Tesser // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -10,100 +10,126 @@ export = ngtoaster; export as namespace toaster; declare namespace 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 - info(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 IToasterService { + pop(params: IPopParams): void; + /** + * @param 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, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + error(params: IPopParams): void; + error(title?: string, body?: string, timeout?: number, bodyOutputType?: string, clickHandler?: EventListener, + toasterId?: number, showCloseButton?: boolean, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + info(params: IPopParams): void; + info(title?: string, body?: string, timeout?: number, bodyOutputType?: string, clickHandler?: EventListener, + toasterId?: number, showCloseButton?: boolean, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + wait(params: IPopParams): void; + wait(title?: string, body?: string, timeout?: number, bodyOutputType?: string, clickHandler?: EventListener, + toasterId?: number, showCloseButton?: boolean, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + success(params: IPopParams): void; + success(title?: string, body?: string, timeout?: number, bodyOutputType?: string, clickHandler?: EventListener, + toasterId?: number, showCloseButton?: boolean, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + warning(params: IPopParams): void; + warning(title?: string, body?: string, timeout?: number, bodyOutputType?: string, clickHandler?: EventListener, + toasterId?: number, showCloseButton?: boolean, toastId?: string|number, + onHideCallback?: IToastCallback): IPopReturn; + clear(toasterId?: number, toastId?: string|number): void; + toast: IToast; + } - interface IToasterEventRegistry { - setup(): void - subscribeToNewToastEvent(onNewToast:IToastEventListener): void - subscribeToClearToastsEvent(onClearToasts:IToastEventListener): void - unsubscribeToNewToastEvent(onNewToast:IToastEventListener): void - unsubscribeToClearToastsEvent(onClearToasts:IToastEventListener): void - } + 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 IPopParams extends IToast { + toasterId?: number; + } - interface IToastEventListener { - (event:Event, toasterId: number): void; - } + interface IPopReturn { + toasterId: number; + toastId: string|number; + } - 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; - } + type IToastCallback = (toast: IToast) => void; - 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; - } + type IToastEventListener = (event: Event, toasterId: number, toastId: string|number) => void; - interface IIconClasses { - error: string; - info: string; - wait: string; - success: string; - warning: string; - } + 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; + closeHtml?: string; + toastId?: string|number; + /** + * Called when the toast has been displayed. + * @param toast the displayed toast + */ + onShowCallback?: IToastCallback; + /** + * Called when the toast has been removed. + * @param toast the displayed toast + */ + onHideCallback?: IToastCallback; + directiveData?: any; + tapToDismiss?: boolean; + } + + interface IToasterConfig { + /** + * limits max number of toasts + */ + limit?: number; + 'tap-to-dismiss'?: boolean; + 'close-button'?: boolean; + 'close-html'?: string; + '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; + } } diff --git a/types/ngtoaster/ngtoaster-tests.ts b/types/ngtoaster/ngtoaster-tests.ts index eb30c181d4..0640ba2191 100644 --- a/types/ngtoaster/ngtoaster-tests.ts +++ b/types/ngtoaster/ngtoaster-tests.ts @@ -1,45 +1,57 @@ -import ngtoaster = require("ngtoaster"); -import * as ng from 'angular'; +import ngtoaster = require('ngtoaster'); import * as angular from 'angular'; 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]); + constructor( + public $scope: angular.IScope, + public $window: angular.IWindowService, + public toaster: ngtoaster.IToasterService + ) { + this.bar = 'Hi'; } - return true; - } + bar: string; - clear(): void { - this.toaster.clear(); - } + pop(): void { + this.toaster.success({ title: 'title', body: 'text1' }); + this.toaster.error('title', 'text2'); + this.toaster.pop({ + type: 'wait', + title: 'title', + body: 'text', + onShowCallback: (toast) => { + this.toaster.clear(null, toast.toastId); + } + }); + 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 => { + const 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 { + const match = toaster.body.match(/http[s]?:\/\/[^\s]+/); + if (match) { + this.$window.open(match[0]); + } + return true; + } + + clear(): void { + this.toaster.clear(); + this.toaster.clear(1); + this.toaster.clear(null, 'mytoast'); + } } angular - .module('main', ['ngAnimate', 'toaster']) - .controller('myController', NgToasterTestController); \ No newline at end of file + .module('main', ['ngAnimate', 'toaster']) + .controller('myController', NgToasterTestController); diff --git a/types/ngtoaster/tslint.json b/types/ngtoaster/tslint.json index a41bf5d19a..eaaf55d976 100644 --- a/types/ngtoaster/tslint.json +++ b/types/ngtoaster/tslint.json @@ -1,79 +1,7 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "interface-name": false } }