Skip to content

Commit

Permalink
Merge pull request #263 from Stabzs/master
Browse files Browse the repository at this point in the history
Added toast instance to onShow onHide callbacks
  • Loading branch information
Stabzs authored Aug 20, 2017
2 parents db7a39c + f73d18b commit 9cebfda
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AngularJS-Toaster
[![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&bust=12)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)

### Current Version 2.1.0
### Current Version 2.2.0

## Angular Compatibility
AngularJS-Toaster requires AngularJS v1.2.6 or higher and specifically targets AngularJS, not Angular 2, although it could be used via ngUpgrade.
Expand Down Expand Up @@ -263,13 +263,13 @@ 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.
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.

```js
toaster.pop({
title: 'A toast',
body: 'with an onShow callback',
onShowCallback: function () {
onShowCallback: function (toast) {
toaster.pop({
title: 'A toast',
body: 'invoked as an onShow callback'
Expand All @@ -279,13 +279,13 @@ toaster.pop({
```

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

```js
toaster.pop({
title: 'A toast',
body: 'with an onHide callback',
onHideCallback: function () {
onHideCallback: function (toast) {
toaster.pop({
title: 'A toast',
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": "2.1.0",
"version": "2.2.0",
"main": [
"toaster.js",
"toaster.css",
Expand Down
3 changes: 2 additions & 1 deletion karma.coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = function(config) {
config.coverageReporter = {
dir: 'coverage/',
reporters: [
{ type: 'html', subdir: 'html-report' }
{ type: 'html', subdir: 'html-report' },
{ type: 'text-summary' }
]
};

Expand Down
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-toaster",
"version": "2.1.0",
"version": "2.2.0",
"main": "toaster.js",
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
"author": "Jiri Kavulak",
Expand All @@ -9,17 +9,22 @@
"type": "git",
"url": "https://github.com/jirikavi/AngularJS-Toaster.git"
},
"scripts": {
"test": "karma start",
"coverage": "karma start karma.coverage.js"
},
"dependencies": {},
"devDependencies": {
"angular": ">1.2.6",
"angular-animate": "~1.2.8",
"angular-mocks": "^1.4.7",
"coveralls": "2.13.1",
"jasmine-core": "^2.3.4",
"karma": "^0.13.21",
"karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.7",
"coveralls": "^2.11.6"
"karma": "1.7.0",
"karma-cli": "1.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0"
},
"jspm": {
"main": "toaster",
Expand Down
38 changes: 36 additions & 2 deletions test/toasterContainerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ describe('toasterContainer', function () {
expect(scope.toasters[1].body).toBe('third');
});

it('should invoke onShowCallback if it exists when toast is added', function () {
it('should invoke onShowCallback if it exists when toast is added', function () {
compileContainer();
var mock = {
callback : function () { }
Expand All @@ -421,7 +421,7 @@ describe('toasterContainer', function () {
expect(mock.callback).toHaveBeenCalled();
});

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

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

it('should invoke pass toast instance to onShowCallback', function () {
compileContainer();
var toastSetByCallback = null;

function callback(t) {
toastSetByCallback = t;
}

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

rootScope.$digest();

expect(toastSetByCallback).not.toBeNull();
});
});


Expand Down Expand Up @@ -477,6 +492,25 @@ describe('toasterContainer', function () {

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

it('should invoke pass toast instance to onHideCallback', function () {
var container = compileContainer();
var scope = container.scope();

var toastSetByCallback = null;

function callback(t) {
toastSetByCallback = t;
}

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

rootScope.$digest();
scope.removeToast(toast.toastId);
rootScope.$digest();

expect(toastSetByCallback).not.toBeNull();
});
});


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

/*
* AngularJS Toaster
* Version: 2.1.0
* Version: 2.2.0
*
* Copyright 2013-2016 Jiri Kavulak.
* All Rights Reserved.
Expand Down Expand Up @@ -396,7 +396,7 @@
}

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

Expand All @@ -420,7 +420,7 @@
scope.toasters.splice(toastIndex, 1);

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

Expand Down
4 changes: 2 additions & 2 deletions toaster.min.js

Large diffs are not rendered by default.

0 comments on commit 9cebfda

Please sign in to comment.