From 5386cc3661743d3af989a091dc17fa3a5424e933 Mon Sep 17 00:00:00 2001 From: sagiegurari Date: Sun, 22 Jan 2017 01:20:28 +0200 Subject: [PATCH] docs --- angular-web-notification.js | 9 ++++++-- docs/api.md | 43 ++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/angular-web-notification.js b/angular-web-notification.js index 1be827f..1d7e88e 100644 --- a/angular-web-notification.js +++ b/angular-web-notification.js @@ -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.
+ * 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() { /** @@ -64,7 +65,11 @@ * }); * ``` */ + var showNotification = webNotificationAPI.showNotification; - return webNotificationAPI; + /*istanbul ignore else*/ + if (showNotification) { + return webNotificationAPI; + } }); }(window.webNotification)); diff --git a/docs/api.md b/docs/api.md index 986d823..65a9d80 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,9 +1,50 @@ ## webNotification ⇒ Object -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.
+See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details. **Kind**: global namespace **Returns**: Object - The service instance **Ngdoc**: service **Author:** Sagie Gur-Ari + + +### webNotification.showNotification([title], [options], [callback]) +Shows the notification based on the provided input.
+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] | String | | The notification title text (defaulted to empty string if null is provided) | +| [options] | Object | | Holds the notification data (web notification API spec for more info) | +| [options.icon] | String | /favicon.ico | The notification icon (defaults to the website favicon.ico) | +| [options.autoClose] | Number | | Auto closes the notification after the provided amount of millies (0 or undefined for no auto close) | +| [options.onClick] | function | | An optional onclick event handler | +| [callback] | ShowNotificationCallback | | 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); + } +}); +```