Skip to content

Commit 5386cc3

Browse files
committed
docs
1 parent 604ce27 commit 5386cc3

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

angular-web-notification.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
* @returns {Object} The service instance
2424
*
2525
* @description
26-
* The web notification service wraps the HTML 5 Web Notifications API as an angular service.
26+
* The web notification service wraps the HTML 5 Web Notifications API as an angular service.<br>
27+
* See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details.
2728
*/
2829
webNotification.factory('webNotification', function onCreateService() {
2930
/**
@@ -64,7 +65,11 @@
6465
* });
6566
* ```
6667
*/
68+
var showNotification = webNotificationAPI.showNotification;
6769

68-
return webNotificationAPI;
70+
/*istanbul ignore else*/
71+
if (showNotification) {
72+
return webNotificationAPI;
73+
}
6974
});
7075
}(window.webNotification));

docs/api.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
<a name="webNotification"></a>
22

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

67
**Kind**: global namespace
78
**Returns**: <code>Object</code> - The service instance
89
**Ngdoc**: service
910
**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

Comments
 (0)