Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jan 21, 2017
1 parent 604ce27 commit 5386cc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
9 changes: 7 additions & 2 deletions angular-web-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @returns {Object} The service instance
*
* @description
* The web notification service wraps the HTML 5 Web Notifications API as an angular service.
* The web notification service wraps the HTML 5 Web Notifications API as an angular service.<br>
* See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details.
*/
webNotification.factory('webNotification', function onCreateService() {
/**
Expand Down Expand Up @@ -64,7 +65,11 @@
* });
* ```
*/
var showNotification = webNotificationAPI.showNotification;

return webNotificationAPI;
/*istanbul ignore else*/
if (showNotification) {
return webNotificationAPI;
}
});
}(window.webNotification));
43 changes: 42 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
<a name="webNotification"></a>

## webNotification ⇒ <code>Object</code>
The web notification service wraps the HTML 5 Web Notifications API as an angular service.
The web notification service wraps the HTML 5 Web Notifications API as an angular service.<br>
See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details.

**Kind**: global namespace
**Returns**: <code>Object</code> - The service instance
**Ngdoc**: service
**Author:** Sagie Gur-Ari
<a name="webNotification.showNotification"></a>

### 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.

**Access:** public

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [title] | <code>String</code> | | The notification title text (defaulted to empty string if null is provided) |
| [options] | <code>Object</code> | | Holds the notification data (web notification API spec for more info) |
| [options.icon] | <code>String</code> | <code>/favicon.ico</code> | The notification icon (defaults to the website favicon.ico) |
| [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</code> | | Called after the show is handled. |

**Example**
```js
webNotification.showNotification('Example Notification', {
body: 'Notification Text...',
icon: 'my-icon.ico',
onClick: function onNotificationClicked() {
console.log('Notification clicked.');
},
autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
}, function onShow(error, hide) {
if (error) {
window.alert('Unable to show notification: ' + error.message);
} else {
console.log('Notification Shown.');

setTimeout(function hideNotification() {
console.log('Hiding notification....');
hide(); //manually close the notification (you can skip this if you use the autoClose option)
}, 5000);
}
});
```

0 comments on commit 5386cc3

Please sign in to comment.