Skip to content

Commit aaf8f2e

Browse files
committed
Merge pull request #190 from Stabzs/master
Added onShow callback
2 parents c469a03 + 4d99736 commit aaf8f2e

7 files changed

Lines changed: 63 additions & 17 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ before_install:
66
- export DISPLAY=:99.0
77
- sh -e /etc/init.d/xvfb start
88
before_script:
9-
- npm install gulp
109
- npm install karma
1110
- npm install karma-jasmine
1211
- npm install karma-chrome-launcher

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ AngularJS-Toaster
44
**AngularJS Toaster** is an AngularJS port of the **toastr** non-blocking notification jQuery library. It requires AngularJS v1.2.6 or higher and angular-animate for the CSS3 transformations.
55

66
[![Build Status](https://travis-ci.org/jirikavi/AngularJS-Toaster.svg)](https://travis-ci.org/jirikavi/AngularJS-Toaster)
7-
[![Coverage Status](https://coveralls.io/repos/jirikavi/AngularJS-Toaster/badge.svg?branch=master&service=github&cachebust=1)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)
7+
[![Coverage Status](https://coveralls.io/repos/jirikavi/AngularJS-Toaster/badge.svg?branch=master&service=github&busted=1)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)
88

9-
### Current Version 1.0.0
9+
### Current Version 1.0.1
1010

1111
## Demo
1212
- Simple demo is at http://plnkr.co/edit/HKTC1a
@@ -28,10 +28,10 @@ npm install --save angularjs-toaster
2828
* Link scripts:
2929

3030
```html
31-
<link href="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/0.4.16/toaster.min.css" rel="stylesheet" />
31+
<link href="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/1.0.1/toaster.min.css" rel="stylesheet" />
3232
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js" ></script>
3333
<script src="https://code.angularjs.org/1.2.0/angular-animate.min.js" ></script>
34-
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/0.4.16/toaster.min.js"></script>
34+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/1.0.1/toaster.min.js"></script>
3535
```
3636

3737
* Add toaster container directive:
@@ -191,17 +191,33 @@ All four options can be configured either globally for all toasts or individuall
191191
});
192192
```
193193

194+
### On Show Callback
195+
An onShow callback function can be attached to each toast instance. The callback will be invoked upon toast add.
196+
197+
```js
198+
toaster.pop({
199+
title: 'A toast',
200+
body: 'with an onShow callback',
201+
onShowCallback: function () {
202+
toaster.pop({
203+
title: 'A toast',
204+
body: 'invoked as an onShow callback'
205+
});
206+
}
207+
});
208+
```
209+
194210
### On Hide Callback
195-
A 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.
211+
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.
196212

197213
```js
198214
toaster.pop({
199215
title: 'A toast',
200-
body: 'with a callback',
216+
body: 'with an onHide callback',
201217
onHideCallback: function () {
202218
toaster.pop({
203219
title: 'A toast',
204-
body: 'invoked as a callback'
220+
body: 'invoked as an onHide callback'
205221
});
206222
}
207223
});

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AngularJS-Toaster",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"main": [
55
"toaster.js",
66
"toaster.css"

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"name": "angularjs-toaster",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
5-
"scripts": {
6-
"test": "gulp test"
7-
},
85
"author": "Jiri Kavulak",
96
"license": "MIT",
107
"repository": {
@@ -16,7 +13,6 @@
1613
"angular": ">1.2.6",
1714
"angular-animate": "~1.2.8",
1815
"angular-mocks": "^1.4.7",
19-
"gulp": "^3.9.0",
2016
"jasmine-core": "^2.3.4",
2117
"karma": "^0.13.14",
2218
"karma-chrome-launcher": "^0.2.1",

test/toasterContainerSpec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,36 @@ describe('toasterContainer', function () {
382382
expect(scope.toasters[0].body).toBe('second');
383383
expect(scope.toasters[1].body).toBe('third');
384384
});
385+
386+
it('should invoke onShowCallback if it exists when toast is added', function () {
387+
compileContainer();
388+
var mock = {
389+
callback : function () { }
390+
};
391+
392+
spyOn(mock, 'callback');
393+
394+
toaster.pop({ type: 'info', body: 'toast 1', onShowCallback: mock.callback });
395+
396+
rootScope.$digest();
397+
398+
expect(mock.callback).toHaveBeenCalled();
399+
});
400+
401+
it('should not invoke onShowCallback if it does not exist when toast is added', function () {
402+
compileContainer();
403+
var mock = {
404+
callback : function () { }
405+
};
406+
407+
spyOn(mock, 'callback');
408+
409+
toaster.pop({ type: 'info', body: 'toast 1' });
410+
411+
rootScope.$digest();
412+
413+
expect(mock.callback).not.toHaveBeenCalled();
414+
});
385415
});
386416

387417

toaster.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* AngularJS Toaster
7-
* Version: 1.0.0
7+
* Version: 1.0.1
88
*
99
* Copyright 2013-2016 Jiri Kavulak.
1010
* All Rights Reserved.
@@ -72,6 +72,7 @@
7272
showCloseButton: params.showCloseButton,
7373
closeHtml: params.closeHtml,
7474
uid: params.toastId,
75+
onShowCallback: params.onShowCallback,
7576
onHideCallback: params.onHideCallback,
7677
directiveData: params.directiveData
7778
};
@@ -353,6 +354,10 @@
353354
scope.toasters.shift();
354355
}
355356
}
357+
358+
if (angular.isFunction(toast.onShowCallback)) {
359+
toast.onShowCallback();
360+
}
356361
}
357362

358363
scope.removeToast = function (id) {

0 commit comments

Comments
 (0)