@@ -81,6 +81,48 @@ return {
8181}]);
8282```
8383
84+ In case you wish to use service worker web notifications, you must provide the serviceWorkerRegistration in the options as follows:
85+
86+ ```` js
87+ // Get the service worker registeration object at the startup of the application.
88+ // This is an aysnc operation so you should not try to use it before the promise is finished.
89+ var serviceWorkerRegistration;
90+ navigator .serviceWorker .register (' service-worker.js' ).then (function (registration ) {
91+ serviceWorkerRegistration = registration;
92+ });
93+
94+ // when setting on even handlers in different areas of the application, use that registration object instance (must be done after the registration is available)
95+ element .on (' click' , function onClick () {
96+ webNotification .showNotification (' Example Notification' , {
97+ serviceWorkerRegistration: serviceWorkerRegistration,
98+ body: ' Notification Text...' ,
99+ icon: ' my-icon.ico' ,
100+ actions: [
101+ {
102+ action: ' Start' ,
103+ title: ' Start'
104+ },
105+ {
106+ action: ' Stop' ,
107+ title: ' Stop'
108+ }
109+ ],
110+ autoClose: 4000 // auto close the notification after 4 seconds (you can manually close it via hide function)
111+ }, function onShow (error , hide ) {
112+ if (error) {
113+ window .alert (' Unable to show notification: ' + error .message );
114+ } else {
115+ console .log (' Notification Shown.' );
116+
117+ setTimeout (function hideNotification () {
118+ console .log (' Hiding notification....' );
119+ hide (); // manually close the notification (you can skip this if you use the autoClose option)
120+ }, 5000 );
121+ }
122+ });
123+ });
124+ ````
125+
84126<a name =" installation " ></a >
85127## Installation
86128Run bower install in your project as follows:
@@ -112,7 +154,7 @@ See [contributing guide](.github/CONTRIBUTING.md)
112154
113155| Date | Version | Description |
114156| ----------- | ------- | ----------- |
115- | 2017-06-26 | v1.2.23 | Maintenance |
157+ | 2017-08-25 | v1.2.24 | Document support of service worker web notifications |
116158| 2017-01-22 | v1.2.0 | Split the internal web notification API into a new project: simple-web-notification |
117159| 2017-01-13 | v1.0.26 | Maintenance |
118160| 2016-11-23 | v1.0.19 | Use forked version of html5-desktop-notifications in order to resolve few issues |
0 commit comments