Skip to content

Commit

Permalink
Callbackis now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Sep 7, 2016
1 parent 01f900d commit f577f63
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2016-09-07 | v1.0.4 | Callback is now optional |
| 2016-09-07 | v1.0.3 | Maintenance |
| 2016-06-14 | v0.0.78 | Published via NPM (in addition to bower) |
| 2016-06-14 | v0.0.77 | Maintenance |
Expand Down
23 changes: 21 additions & 2 deletions angular-web-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@
}
});

/**
* @ngdoc method
* @function
* @memberof! webNotification
* @alias webNotification.noop
* @private
*
* @description
* Empty function
*
* @returns {undefined} Undefined
*/
var noop = function () {
return undefined;
};

/**
* @ngdoc method
* @function
Expand Down Expand Up @@ -147,7 +163,10 @@
*/
var parseInput = function (argumentsArray) {
//callback is always the last argument
var callback = argumentsArray.pop();
var callback = noop;
if (argumentsArray.length && (typeof argumentsArray[argumentsArray.length - 1] === 'function')) {
callback = argumentsArray.pop();
}

var title = null;
var options = null;
Expand Down Expand Up @@ -189,7 +208,7 @@
* @param {object} [options] - Holds the notification data (web notification API spec for more info)
* @param {number} [options.autoClose] - Auto closes the notification after the provided amount of millies (0 or undefined for no auto close)
* @param {function} [options.onClick] - An optional onclick event handler
* @param {ShowNotificationCallback} callback - Called after the show is handled.
* @param {ShowNotificationCallback} [callback] - Called after the show is handled.
* @example
* ```js
* webNotification.showNotification('Example Notification', {
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": "angular-web-notification",
"version": "1.0.3",
"version": "1.0.4",
"description": "AngularJS service for displaying web notifications.",
"authors": [
"Sagie Gur-Ari <sagiegurari@gmail.com>"
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2016-09-07 | v1.0.4 | Callback is now optional |
| 2016-09-07 | v1.0.3 | Maintenance |
| 2016-06-14 | v0.0.78 | Published via NPM (in addition to bower) |
| 2016-06-14 | v0.0.77 | Maintenance |
Expand Down
6 changes: 3 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The web notification service wraps the HTML 5 Web Notifications API as an angula
* [webNotification](#webNotification) ⇒ <code>object</code>
* [.allowRequest](#webNotification.allowRequest)
* [.permissionGranted](#webNotification.permissionGranted)
* [.showNotification([title], [options], callback)](#webNotification.showNotification)
* [.showNotification([title], [options], [callback])](#webNotification.showNotification)

<a name="webNotification.allowRequest"></a>

Expand All @@ -43,7 +43,7 @@ True if permission is granted, else false.
**Access:** public
<a name="webNotification.showNotification"></a>

### webNotification.showNotification([title], [options], callback)
### webNotification.showNotification([title], [options], [callback])
Shows the notification based on the provided input.<br>
The callback invoked will get an error object (in case of an error, null in
case of no errors) and a 'hide' function which can be used to hide the notification.
Expand All @@ -56,7 +56,7 @@ case of no errors) and a 'hide' function which can be used to hide the notificat
| [options] | <code>object</code> | Holds the notification data (web notification API spec for more info) |
| [options.autoClose] | <code>number</code> | Auto closes the notification after the provided amount of millies (0 or undefined for no auto close) |
| [options.onClick] | <code>function</code> | An optional onclick event handler |
| callback | <code>[ShowNotificationCallback](#ShowNotificationCallback)</code> | Called after the show is handled. |
| [callback] | <code>[ShowNotificationCallback](#ShowNotificationCallback)</code> | Called after the show is handled. |

**Example**
```js
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-web-notification",
"version": "1.0.3",
"version": "1.0.4",
"description": "AngularJS service for displaying web notifications.",
"author": {
"name": "Sagie Gur-Ari",
Expand Down
19 changes: 19 additions & 0 deletions test/spec/angular-web-notification-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ describe('angular-web-notification', function () {
});
});

it('showNotification no callback test', function (done) {
inject(function (webNotification) {
window.notify.setAllowed(function (title, options) {
assert.equal(title, 'Example Notification');
assert.deepEqual(options, {
body: 'Notification Text...',
icon: 'my-icon.ico'
});
});

webNotification.showNotification('Example Notification', {
body: 'Notification Text...',
icon: 'my-icon.ico'
});

setTimeout(done, 50);
});
});

it('showNotification no title test', function (done) {
inject(function (webNotification) {
window.notify.setAllowed(function (title, options) {
Expand Down

0 comments on commit f577f63

Please sign in to comment.