Skip to content

Commit 9cebfda

Browse files
authored
Merge pull request #263 from Stabzs/master
Added toast instance to onShow onHide callbacks
2 parents db7a39c + f73d18b commit 9cebfda

7 files changed

+60
-20
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AngularJS-Toaster
66
[![Build Status](https://travis-ci.org/jirikavi/AngularJS-Toaster.svg)](https://travis-ci.org/jirikavi/AngularJS-Toaster)
77
[![Coverage Status](https://coveralls.io/repos/jirikavi/AngularJS-Toaster/badge.svg?branch=master&service=github&bust=12)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)
88

9-
### Current Version 2.1.0
9+
### Current Version 2.2.0
1010

1111
## Angular Compatibility
1212
AngularJS-Toaster requires AngularJS v1.2.6 or higher and specifically targets AngularJS, not Angular 2, although it could be used via ngUpgrade.
@@ -263,13 +263,13 @@ All four options can be configured either globally for all toasts or individuall
263263
```
264264

265265
### On Show Callback
266-
An onShow callback function can be attached to each toast instance. The callback will be invoked upon toast add.
266+
An onShow callback function can be attached to each toast instance, with the toast passed as a parameter when invoked. The callback will be invoked upon toast add.
267267

268268
```js
269269
toaster.pop({
270270
title: 'A toast',
271271
body: 'with an onShow callback',
272-
onShowCallback: function () {
272+
onShowCallback: function (toast) {
273273
toaster.pop({
274274
title: 'A toast',
275275
body: 'invoked as an onShow callback'
@@ -279,13 +279,13 @@ toaster.pop({
279279
```
280280

281281
### On Hide Callback
282-
An onHide callback function can be attached to each toast instance. The callback will be invoked upon toast removal. This can be used to chain toast calls.
282+
An onHide callback function can be attached to each toast instance, with the toast passed as a parameter when invoked. The callback will be invoked upon toast removal. This can be used to chain toast calls.
283283

284284
```js
285285
toaster.pop({
286286
title: 'A toast',
287287
body: 'with an onHide callback',
288-
onHideCallback: function () {
288+
onHideCallback: function (toast) {
289289
toaster.pop({
290290
title: 'A toast',
291291
body: 'invoked as an onHide callback'

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AngularJS-Toaster",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"main": [
55
"toaster.js",
66
"toaster.css",

karma.coverage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = function(config) {
1111
config.coverageReporter = {
1212
dir: 'coverage/',
1313
reporters: [
14-
{ type: 'html', subdir: 'html-report' }
14+
{ type: 'html', subdir: 'html-report' },
15+
{ type: 'text-summary' }
1516
]
1617
};
1718

package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-toaster",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"main": "toaster.js",
55
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
66
"author": "Jiri Kavulak",
@@ -9,17 +9,22 @@
99
"type": "git",
1010
"url": "https://github.com/jirikavi/AngularJS-Toaster.git"
1111
},
12+
"scripts": {
13+
"test": "karma start",
14+
"coverage": "karma start karma.coverage.js"
15+
},
1216
"dependencies": {},
1317
"devDependencies": {
1418
"angular": ">1.2.6",
1519
"angular-animate": "~1.2.8",
1620
"angular-mocks": "^1.4.7",
21+
"coveralls": "2.13.1",
1722
"jasmine-core": "^2.3.4",
18-
"karma": "^0.13.21",
19-
"karma-chrome-launcher": "^0.2.2",
20-
"karma-coverage": "^0.5.3",
21-
"karma-jasmine": "^0.3.7",
22-
"coveralls": "^2.11.6"
23+
"karma": "1.7.0",
24+
"karma-cli": "1.0.1",
25+
"karma-chrome-launcher": "^2.2.0",
26+
"karma-coverage": "^1.1.1",
27+
"karma-jasmine": "^1.1.0"
2328
},
2429
"jspm": {
2530
"main": "toaster",

test/toasterContainerSpec.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ describe('toasterContainer', function () {
406406
expect(scope.toasters[1].body).toBe('third');
407407
});
408408

409-
it('should invoke onShowCallback if it exists when toast is added', function () {
409+
it('should invoke onShowCallback if it exists when toast is added', function () {
410410
compileContainer();
411411
var mock = {
412412
callback : function () { }
@@ -421,7 +421,7 @@ describe('toasterContainer', function () {
421421
expect(mock.callback).toHaveBeenCalled();
422422
});
423423

424-
it('should not invoke onShowCallback if it does not exist when toast is added', function () {
424+
it('should not invoke onShowCallback if it does not exist when toast is added', function () {
425425
compileContainer();
426426
var mock = {
427427
callback : function () { }
@@ -435,6 +435,21 @@ describe('toasterContainer', function () {
435435

436436
expect(mock.callback).not.toHaveBeenCalled();
437437
});
438+
439+
it('should invoke pass toast instance to onShowCallback', function () {
440+
compileContainer();
441+
var toastSetByCallback = null;
442+
443+
function callback(t) {
444+
toastSetByCallback = t;
445+
}
446+
447+
toaster.pop({ type: 'info', body: 'toast 1', onShowCallback: callback });
448+
449+
rootScope.$digest();
450+
451+
expect(toastSetByCallback).not.toBeNull();
452+
});
438453
});
439454

440455

@@ -477,6 +492,25 @@ describe('toasterContainer', function () {
477492

478493
expect(mock.callback).toHaveBeenCalled();
479494
});
495+
496+
it('should invoke pass toast instance to onHideCallback', function () {
497+
var container = compileContainer();
498+
var scope = container.scope();
499+
500+
var toastSetByCallback = null;
501+
502+
function callback(t) {
503+
toastSetByCallback = t;
504+
}
505+
506+
var toast = toaster.pop({ type: 'info', body: 'toast 1', onHideCallback: callback });
507+
508+
rootScope.$digest();
509+
scope.removeToast(toast.toastId);
510+
rootScope.$digest();
511+
512+
expect(toastSetByCallback).not.toBeNull();
513+
});
480514
});
481515

482516

toaster.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* AngularJS Toaster
7-
* Version: 2.1.0
7+
* Version: 2.2.0
88
*
99
* Copyright 2013-2016 Jiri Kavulak.
1010
* All Rights Reserved.
@@ -396,7 +396,7 @@
396396
}
397397

398398
if (angular.isFunction(toast.onShowCallback)) {
399-
toast.onShowCallback();
399+
toast.onShowCallback(toast);
400400
}
401401
}
402402

@@ -420,7 +420,7 @@
420420
scope.toasters.splice(toastIndex, 1);
421421

422422
if (angular.isFunction(toast.onHideCallback)) {
423-
toast.onHideCallback();
423+
toast.onHideCallback(toast);
424424
}
425425
}
426426

toaster.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)