Skip to content

Commit

Permalink
Merge pull request #190 from Stabzs/master
Browse files Browse the repository at this point in the history
Added onShow callback
  • Loading branch information
Stabzs committed Feb 6, 2016
2 parents c469a03 + 4d99736 commit aaf8f2e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 17 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
before_script:
- npm install gulp
- npm install karma
- npm install karma-jasmine
- npm install karma-chrome-launcher
Expand Down
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ AngularJS-Toaster
**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.

[![Build Status](https://travis-ci.org/jirikavi/AngularJS-Toaster.svg)](https://travis-ci.org/jirikavi/AngularJS-Toaster)
[![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)
[![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)

### Current Version 1.0.0
### Current Version 1.0.1

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

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

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

### On Show Callback
An onShow callback function can be attached to each toast instance. The callback will be invoked upon toast add.

```js
toaster.pop({
title: 'A toast',
body: 'with an onShow callback',
onShowCallback: function () {
toaster.pop({
title: 'A toast',
body: 'invoked as an onShow callback'
});
}
});
```

### On Hide Callback
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.
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.

```js
toaster.pop({
title: 'A toast',
body: 'with a callback',
body: 'with an onHide callback',
onHideCallback: function () {
toaster.pop({
title: 'A toast',
body: 'invoked as a callback'
body: 'invoked as an onHide callback'
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AngularJS-Toaster",
"version": "1.0.0",
"version": "1.0.1",
"main": [
"toaster.js",
"toaster.css"
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"name": "angularjs-toaster",
"version": "1.0.0",
"version": "1.0.1",
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
"scripts": {
"test": "gulp test"
},
"author": "Jiri Kavulak",
"license": "MIT",
"repository": {
Expand All @@ -16,7 +13,6 @@
"angular": ">1.2.6",
"angular-animate": "~1.2.8",
"angular-mocks": "^1.4.7",
"gulp": "^3.9.0",
"jasmine-core": "^2.3.4",
"karma": "^0.13.14",
"karma-chrome-launcher": "^0.2.1",
Expand Down
30 changes: 30 additions & 0 deletions test/toasterContainerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,36 @@ describe('toasterContainer', function () {
expect(scope.toasters[0].body).toBe('second');
expect(scope.toasters[1].body).toBe('third');
});

it('should invoke onShowCallback if it exists when toast is added', function () {
compileContainer();
var mock = {
callback : function () { }
};

spyOn(mock, 'callback');

toaster.pop({ type: 'info', body: 'toast 1', onShowCallback: mock.callback });

rootScope.$digest();

expect(mock.callback).toHaveBeenCalled();
});

it('should not invoke onShowCallback if it does not exist when toast is added', function () {
compileContainer();
var mock = {
callback : function () { }
};

spyOn(mock, 'callback');

toaster.pop({ type: 'info', body: 'toast 1' });

rootScope.$digest();

expect(mock.callback).not.toHaveBeenCalled();
});
});


Expand Down
7 changes: 6 additions & 1 deletion toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
* AngularJS Toaster
* Version: 1.0.0
* Version: 1.0.1
*
* Copyright 2013-2016 Jiri Kavulak.
* All Rights Reserved.
Expand Down Expand Up @@ -72,6 +72,7 @@
showCloseButton: params.showCloseButton,
closeHtml: params.closeHtml,
uid: params.toastId,
onShowCallback: params.onShowCallback,
onHideCallback: params.onHideCallback,
directiveData: params.directiveData
};
Expand Down Expand Up @@ -353,6 +354,10 @@
scope.toasters.shift();
}
}

if (angular.isFunction(toast.onShowCallback)) {
toast.onShowCallback();
}
}

scope.removeToast = function (id) {
Expand Down
Loading

0 comments on commit aaf8f2e

Please sign in to comment.