ng2-toasty
Advanced tools
Comparing version 2.3.1 to 2.4.0
{ | ||
"name": "ng2-toasty", | ||
"description": "Angular2 Toasty component shows growl-style alerts and messages for your web app", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"scripts": { | ||
@@ -33,12 +33,12 @@ "test": "karma start", | ||
"peerDependencies": { | ||
"@angular/core": "^2.4.4" | ||
"@angular/core": "^2.4.7" | ||
}, | ||
"devDependencies": { | ||
"@angular/common": "^2.4.4", | ||
"@angular/compiler": "^2.4.4", | ||
"@angular/compiler-cli": "^2.4.4", | ||
"@angular/core": "^2.4.4", | ||
"@angular/platform-browser": "^2.4.4", | ||
"@angular/platform-browser-dynamic": "^2.4.4", | ||
"@angular/platform-server": "^2.4.4", | ||
"@angular/common": "^2.4.7", | ||
"@angular/compiler": "^2.4.7", | ||
"@angular/compiler-cli": "^2.4.7", | ||
"@angular/core": "^2.4.7", | ||
"@angular/platform-browser": "^2.4.7", | ||
"@angular/platform-browser-dynamic": "^2.4.7", | ||
"@angular/platform-server": "^2.4.7", | ||
"@types/hammerjs": "2.0.33", | ||
@@ -65,3 +65,3 @@ "@types/jasmine": "2.5.37", | ||
"loader-utils": "~0.2.16", | ||
"reflect-metadata": "0.1.8", | ||
"reflect-metadata": "^0.1.8", | ||
"rxjs": "^5.0.3", | ||
@@ -68,0 +68,0 @@ "semantic-release": "4.3.5", |
@@ -29,2 +29,6 @@ import { OnInit } from '@angular/core'; | ||
/** | ||
* Add new Toast | ||
*/ | ||
add(toast: ToastData): void; | ||
/** | ||
* Clear individual toast by id | ||
@@ -31,0 +35,0 @@ * @param id is unique identifier of Toast |
@@ -6,3 +6,3 @@ // Copyright (C) 2016 Sergey Akopkokhyants | ||
import { isFunction } from './toasty.utils'; | ||
import { ToastyService, ToastyConfig } from './toasty.service'; | ||
import { ToastyService, ToastyConfig, ToastyEventType } from './toasty.service'; | ||
/** | ||
@@ -62,24 +62,15 @@ * Toasty is container for Toast components | ||
var _this = this; | ||
// We listen our service to recieve new toasts from it | ||
this.toastyService.getToasts().subscribe(function (toast) { | ||
// If we've gone over our limit, remove the earliest | ||
// one from the array | ||
if (_this.toasts.length >= _this.config.limit) { | ||
_this.toasts.shift(); | ||
// We listen events from our service | ||
this.toastyService.events.subscribe(function (event) { | ||
if (event.type === ToastyEventType.ADD) { | ||
// Add the new one | ||
var toast = event.value; | ||
_this.add(toast); | ||
} | ||
// Add toasty to array | ||
_this.toasts.push(toast); | ||
// | ||
// If there's a timeout individually or globally, | ||
// set the toast to timeout | ||
if (toast.timeout) { | ||
_this._setTimeout(toast); | ||
} | ||
}); | ||
// We listen clear all comes from service here. | ||
this.toastyService.getClear().subscribe(function (id) { | ||
if (id) { | ||
else if (event.type === ToastyEventType.CLEAR) { | ||
// Clear the one by number | ||
var id = event.value; | ||
_this.clear(id); | ||
} | ||
else { | ||
else if (event.type === ToastyEventType.CLEAR_ALL) { | ||
// Lets clear all toasts | ||
@@ -98,2 +89,20 @@ _this.clearAll(); | ||
/** | ||
* Add new Toast | ||
*/ | ||
ToastyComponent.prototype.add = function (toast) { | ||
// If we've gone over our limit, remove the earliest | ||
// one from the array | ||
if (this.toasts.length >= this.config.limit) { | ||
this.toasts.shift(); | ||
} | ||
// Add toasty to array | ||
this.toasts.push(toast); | ||
// | ||
// If there's a timeout individually or globally, | ||
// set the toast to timeout | ||
if (toast.timeout) { | ||
this._setTimeout(toast); | ||
} | ||
}; | ||
/** | ||
* Clear individual toast by id | ||
@@ -100,0 +109,0 @@ * @param id is unique identifier of Toast |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"ToastyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2-toasty","template":"\n <div id=\"toasty\" [ngClass]=\"[position]\">\n <ng2-toast *ngFor=\"let toast of toasts\" [toast]=\"toast\" (closeToast)=\"closeToast(toast)\"></ng2-toast>\n </div>"}]}],"members":{"position":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./toasty.service","name":"ToastyConfig"},{"__symbolic":"reference","module":"./toasty.service","name":"ToastyService"}]}],"ngOnInit":[{"__symbolic":"method"}],"closeToast":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"_setTimeout":[{"__symbolic":"method"}]},"statics":{"POSITIONS":["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center","center-center"]}}}},{"__symbolic":"module","version":1,"metadata":{"ToastyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2-toasty","template":"\n <div id=\"toasty\" [ngClass]=\"[position]\">\n <ng2-toast *ngFor=\"let toast of toasts\" [toast]=\"toast\" (closeToast)=\"closeToast(toast)\"></ng2-toast>\n </div>"}]}],"members":{"position":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./toasty.service","name":"ToastyConfig"},{"__symbolic":"reference","module":"./toasty.service","name":"ToastyService"}]}],"ngOnInit":[{"__symbolic":"method"}],"closeToast":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"_setTimeout":[{"__symbolic":"method"}]},"statics":{"POSITIONS":["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center","center-center"]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"ToastyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2-toasty","template":"\n <div id=\"toasty\" [ngClass]=\"[position]\">\n <ng2-toast *ngFor=\"let toast of toasts\" [toast]=\"toast\" (closeToast)=\"closeToast(toast)\"></ng2-toast>\n </div>"}]}],"members":{"position":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./toasty.service","name":"ToastyConfig"},{"__symbolic":"reference","module":"./toasty.service","name":"ToastyService"}]}],"ngOnInit":[{"__symbolic":"method"}],"closeToast":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"_setTimeout":[{"__symbolic":"method"}]},"statics":{"POSITIONS":["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center","center-center"]}}}},{"__symbolic":"module","version":1,"metadata":{"ToastyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ng2-toasty","template":"\n <div id=\"toasty\" [ngClass]=\"[position]\">\n <ng2-toast *ngFor=\"let toast of toasts\" [toast]=\"toast\" (closeToast)=\"closeToast(toast)\"></ng2-toast>\n </div>"}]}],"members":{"position":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./toasty.service","name":"ToastyConfig"},{"__symbolic":"reference","module":"./toasty.service","name":"ToastyService"}]}],"ngOnInit":[{"__symbolic":"method"}],"closeToast":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"_setTimeout":[{"__symbolic":"method"}]},"statics":{"POSITIONS":["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center","center-center"]}}}}] |
@@ -35,6 +35,16 @@ import { Observable } from 'rxjs/Observable'; | ||
showClose: boolean; | ||
position: string; | ||
position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'top-center' | 'bottom-center' | 'center-center'; | ||
timeout: number; | ||
theme: string; | ||
theme: 'default' | 'material' | 'bootstrap'; | ||
} | ||
export declare enum ToastyEventType { | ||
ADD = 0, | ||
CLEAR = 1, | ||
CLEAR_ALL = 2, | ||
} | ||
export declare class ToastyEvent { | ||
type: ToastyEventType; | ||
value: any; | ||
constructor(type: ToastyEventType, value?: any); | ||
} | ||
export declare function toastyServiceFactory(config: ToastyConfig): ToastyService; | ||
@@ -48,4 +58,4 @@ /** | ||
uniqueCounter: number; | ||
private toastsEmitter; | ||
private clearEmitter; | ||
private eventSource; | ||
events: Observable<ToastyEvent>; | ||
constructor(config: ToastyConfig); | ||
@@ -55,4 +65,2 @@ /** | ||
*/ | ||
getToasts(): Observable<ToastData>; | ||
getClear(): Observable<number>; | ||
/** | ||
@@ -91,2 +99,3 @@ * Create Toast of a default type | ||
private _checkConfigItem(config, options, property); | ||
private emitEvent(event); | ||
} |
// Copyright (C) 2016 Sergey Akopkokhyants | ||
// This project is licensed under the terms of the MIT license. | ||
// https://github.com/akserg/ng2-toasty | ||
import { Injectable, EventEmitter } from '@angular/core'; | ||
import { Injectable } from '@angular/core'; | ||
import { isString, isNumber, isFunction } from './toasty.utils'; | ||
import { Subject } from 'rxjs/Subject'; | ||
/** | ||
@@ -41,9 +42,7 @@ * Options to configure specific Toast | ||
this.showClose = true; | ||
// The window position where the toast pops up. Possible values | ||
// bottom-right, bottom-left, top-right, top-left, top-center, bottom-center, center-center | ||
// The window position where the toast pops up | ||
this.position = 'bottom-right'; | ||
// How long (in miliseconds) the toasty shows before it's removed. Set to null/0 to turn off. | ||
this.timeout = 5000; | ||
// What theme to use. Possible values: | ||
// default, material or bootstrap | ||
// What theme to use | ||
this.theme = 'default'; | ||
@@ -58,2 +57,15 @@ } | ||
}()); | ||
export var ToastyEventType; | ||
(function (ToastyEventType) { | ||
ToastyEventType[ToastyEventType["ADD"] = 0] = "ADD"; | ||
ToastyEventType[ToastyEventType["CLEAR"] = 1] = "CLEAR"; | ||
ToastyEventType[ToastyEventType["CLEAR_ALL"] = 2] = "CLEAR_ALL"; | ||
})(ToastyEventType || (ToastyEventType = {})); | ||
export var ToastyEvent = (function () { | ||
function ToastyEvent(type, value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
return ToastyEvent; | ||
}()); | ||
export function toastyServiceFactory(config) { | ||
@@ -71,5 +83,7 @@ return new ToastyService(config); | ||
// ToastData event emitter | ||
this.toastsEmitter = new EventEmitter(); | ||
// private toastsEmitter: EventEmitter<ToastData> = new EventEmitter<ToastData>(); | ||
// Clear event emitter | ||
this.clearEmitter = new EventEmitter(); | ||
// private clearEmitter: EventEmitter<number> = new EventEmitter<number>(); | ||
this.eventSource = new Subject(); | ||
this.events = this.eventSource.asObservable(); | ||
} | ||
@@ -79,8 +93,8 @@ /** | ||
*/ | ||
ToastyService.prototype.getToasts = function () { | ||
return this.toastsEmitter.asObservable(); | ||
}; | ||
ToastyService.prototype.getClear = function () { | ||
return this.clearEmitter.asObservable(); | ||
}; | ||
// getToasts(): Observable<ToastData> { | ||
// return this.toastsEmitter.asObservable(); | ||
// } | ||
// getClear(): Observable<number> { | ||
// return this.clearEmitter.asObservable(); | ||
// } | ||
/** | ||
@@ -169,3 +183,4 @@ * Create Toast of a default type | ||
// this.toastsSubscriber.next(toast); | ||
this.toastsEmitter.next(toast); | ||
// this.toastsEmitter.next(toast); | ||
this.emitEvent(new ToastyEvent(ToastyEventType.ADD, toast)); | ||
// If we have a onAdd function, call it here | ||
@@ -178,7 +193,9 @@ if (toastyOptions.onAdd && isFunction(toastyOptions.onAdd)) { | ||
ToastyService.prototype.clearAll = function () { | ||
this.clearEmitter.next(null); | ||
// this.clearEmitter.next(null); | ||
this.emitEvent(new ToastyEvent(ToastyEventType.CLEAR_ALL)); | ||
}; | ||
// Clear the specific one | ||
ToastyService.prototype.clear = function (id) { | ||
this.clearEmitter.next(id); | ||
// this.clearEmitter.next(id); | ||
this.emitEvent(new ToastyEvent(ToastyEventType.CLEAR, id)); | ||
}; | ||
@@ -198,2 +215,8 @@ // Checks whether the local option is set, if not, | ||
}; | ||
ToastyService.prototype.emitEvent = function (event) { | ||
if (this.eventSource) { | ||
// Push up a new event | ||
this.eventSource.next(event); | ||
} | ||
}; | ||
// Allowed THEMES | ||
@@ -200,0 +223,0 @@ ToastyService.THEMES = ['default', 'material', 'bootstrap']; |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"ToastOptions":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastData":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyConfig":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"toastyServiceFactory":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"ToastyService"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"ToastyService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ToastyConfig"}]}],"getToasts":[{"__symbolic":"method"}],"getClear":[{"__symbolic":"method"}],"default":[{"__symbolic":"method"}],"info":[{"__symbolic":"method"}],"success":[{"__symbolic":"method"}],"wait":[{"__symbolic":"method"}],"error":[{"__symbolic":"method"}],"warning":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"_checkConfigItem":[{"__symbolic":"method"}]},"statics":{"THEMES":["default","material","bootstrap"]}}}},{"__symbolic":"module","version":1,"metadata":{"ToastOptions":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastData":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyConfig":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"toastyServiceFactory":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"ToastyService"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"ToastyService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ToastyConfig"}]}],"getToasts":[{"__symbolic":"method"}],"getClear":[{"__symbolic":"method"}],"default":[{"__symbolic":"method"}],"info":[{"__symbolic":"method"}],"success":[{"__symbolic":"method"}],"wait":[{"__symbolic":"method"}],"error":[{"__symbolic":"method"}],"warning":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"_checkConfigItem":[{"__symbolic":"method"}]},"statics":{"THEMES":["default","material","bootstrap"]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"ToastOptions":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastData":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyConfig":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyEventType":{"ADD":0,"CLEAR":1,"CLEAR_ALL":2},"ToastyEvent":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"error","message":"Could not resolve type","line":70,"character":28,"context":{"typeName":"ToastyEventType"}},{"__symbolic":"reference","name":"any"}]}]}},"toastyServiceFactory":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"ToastyService"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"ToastyService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ToastyConfig"}]}],"default":[{"__symbolic":"method"}],"info":[{"__symbolic":"method"}],"success":[{"__symbolic":"method"}],"wait":[{"__symbolic":"method"}],"error":[{"__symbolic":"method"}],"warning":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"_checkConfigItem":[{"__symbolic":"method"}],"emitEvent":[{"__symbolic":"method"}]},"statics":{"THEMES":["default","material","bootstrap"]}}}},{"__symbolic":"module","version":1,"metadata":{"ToastOptions":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastData":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyConfig":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"ToastyEventType":{"ADD":0,"CLEAR":1,"CLEAR_ALL":2},"ToastyEvent":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"error","message":"Could not resolve type","line":70,"character":28,"context":{"typeName":"ToastyEventType"}},{"__symbolic":"reference","name":"any"}]}]}},"toastyServiceFactory":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"ToastyService"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"ToastyService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ToastyConfig"}]}],"default":[{"__symbolic":"method"}],"info":[{"__symbolic":"method"}],"success":[{"__symbolic":"method"}],"wait":[{"__symbolic":"method"}],"error":[{"__symbolic":"method"}],"warning":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"clearAll":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"_checkConfigItem":[{"__symbolic":"method"}],"emitEvent":[{"__symbolic":"method"}]},"statics":{"THEMES":["default","material","bootstrap"]}}}}] |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
975633
5790