|
1 | 1 | <a name="webNotification"></a>
|
2 | 2 |
|
3 | 3 | ## webNotification ⇒ <code>Object</code>
|
4 |
| -The web notification service wraps the HTML 5 Web Notifications API as an angular service. |
| 4 | +The web notification service wraps the HTML 5 Web Notifications API as an angular service.<br> |
| 5 | +See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details. |
5 | 6 |
|
6 | 7 | **Kind**: global namespace
|
7 | 8 | **Returns**: <code>Object</code> - The service instance
|
8 | 9 | **Ngdoc**: service
|
9 | 10 | **Author:** Sagie Gur-Ari
|
| 11 | +<a name="webNotification.showNotification"></a> |
| 12 | + |
| 13 | +### webNotification.showNotification([title], [options], [callback]) |
| 14 | +Shows the notification based on the provided input.<br> |
| 15 | +The callback invoked will get an error object (in case of an error, null in |
| 16 | +case of no errors) and a 'hide' function which can be used to hide the notification. |
| 17 | + |
| 18 | +**Access:** public |
| 19 | + |
| 20 | +| Param | Type | Default | Description | |
| 21 | +| --- | --- | --- | --- | |
| 22 | +| [title] | <code>String</code> | | The notification title text (defaulted to empty string if null is provided) | |
| 23 | +| [options] | <code>Object</code> | | Holds the notification data (web notification API spec for more info) | |
| 24 | +| [options.icon] | <code>String</code> | <code>/favicon.ico</code> | The notification icon (defaults to the website favicon.ico) | |
| 25 | +| [options.autoClose] | <code>Number</code> | | Auto closes the notification after the provided amount of millies (0 or undefined for no auto close) | |
| 26 | +| [options.onClick] | <code>function</code> | | An optional onclick event handler | |
| 27 | +| [callback] | <code>ShowNotificationCallback</code> | | Called after the show is handled. | |
| 28 | + |
| 29 | +**Example** |
| 30 | +```js |
| 31 | +webNotification.showNotification('Example Notification', { |
| 32 | + body: 'Notification Text...', |
| 33 | + icon: 'my-icon.ico', |
| 34 | + onClick: function onNotificationClicked() { |
| 35 | + console.log('Notification clicked.'); |
| 36 | + }, |
| 37 | + autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function) |
| 38 | +}, function onShow(error, hide) { |
| 39 | + if (error) { |
| 40 | + window.alert('Unable to show notification: ' + error.message); |
| 41 | + } else { |
| 42 | + console.log('Notification Shown.'); |
| 43 | + |
| 44 | + setTimeout(function hideNotification() { |
| 45 | + console.log('Hiding notification....'); |
| 46 | + hide(); //manually close the notification (you can skip this if you use the autoClose option) |
| 47 | + }, 5000); |
| 48 | + } |
| 49 | +}); |
| 50 | +``` |
0 commit comments