1/** 2 * @ngdoc method 3 * @function 4 * @memberof! webNotification 5 * @alias webNotification.initWebNotification 6 * @private 7 * 8 * @description 9 * Initializes the angular web notification service. 10 * 11 * @param {Object} webNotificationAPI - The simplified web notification API 12 */ 13 14(function initWebNotification(webNotificationAPI) { 15 'use strict'; 16 17 const webNotification = angular.module('angular-web-notification', []); 18 19 /** 20 * @ngdoc service 21 * @name webNotification 22 * @namespace webNotification 23 * @author Sagie Gur-Ari 24 * @returns {Object} The service instance 25 * 26 * @description 27 * The web notification service wraps the HTML 5 Web Notifications API as an angular service.<br> 28 * See [simple-web-notification](https://github.com/sagiegurari/simple-web-notification/blob/master/docs/api.md) for more API details. 29 */ 30 webNotification.factory('webNotification', function onCreateService() { 31 /** 32 * Shows the notification based on the provided input.<br> 33 * The callback invoked will get an error object (in case of an error, null in 34 * case of no errors) and a 'hide' function which can be used to hide the notification. 35 * 36 * @function 37 * @memberof! webNotification 38 * @alias webNotification.showNotification 39 * @public 40 * @param {String} [title] - The notification title text (defaulted to empty string if null is provided) 41 * @param {Object} [options] - Holds the notification data (web notification API spec for more info) 42 * @param {String} [options.icon=/favicon.ico] - The notification icon (defaults to the website favicon.ico) 43 * @param {Number} [options.autoClose] - Auto closes the notification after the provided amount of millies (0 or undefined for no auto close) 44 * @param {function} [options.onClick] - An optional onclick event handler 45 * @param {ShowNotificationCallback} [callback] - Called after the show is handled. 46 * @example 47 * ```js 48 * //show web notification when button is clicked 49 * webNotification.showNotification('Example Notification', { 50 * body: 'Notification Text...', 51 * icon: 'my-icon.ico', 52 * onClick: function onNotificationClicked() { 53 * console.log('Notification clicked.'); 54 * }, 55 * autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function) 56 * }, function onShow(error, hide) { 57 * if (error) { 58 * window.alert('Unable to show notification: ' + error.message); 59 * } else { 60 * console.log('Notification Shown.'); 61 * 62 * setTimeout(function hideNotification() { 63 * console.log('Hiding notification....'); 64 * hide(); //manually close the notification (you can skip this if you use the autoClose option) 65 * }, 5000); 66 * } 67 * }); 68 * 69 * //service worker example 70 * navigator.serviceWorker.register('service-worker.js').then(function(registration) { 71 * webNotification.showNotification('Example Notification', { 72 * serviceWorkerRegistration: registration, 73 * body: 'Notification Text...', 74 * icon: 'my-icon.ico', 75 * actions: [ 76 * { 77 * action: 'Start', 78 * title: 'Start' 79 * }, 80 * { 81 * action: 'Stop', 82 * title: 'Stop' 83 * } 84 * ], 85 * autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function) 86 * }, function onShow(error, hide) { 87 * if (error) { 88 * window.alert('Unable to show notification: ' + error.message); 89 * } else { 90 * console.log('Notification Shown.'); 91 * 92 * setTimeout(function hideNotification() { 93 * console.log('Hiding notification....'); 94 * hide(); //manually close the notification (you can skip this if you use the autoClose option) 95 * }, 5000); 96 * } 97 * }); 98 * }); 99 * ``` 100 */ 101 const showNotification = webNotificationAPI.showNotification; 102 103 if (showNotification) { 104 return webNotificationAPI; 105 } 106 }); 107 108}(window.webNotification)); 109 110
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.