From 77c1d6724012d03ae4bf5df9d8aa054d1e68c5fd Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 11 Jul 2016 12:01:09 +0200 Subject: [PATCH] Add a method to egw.notification to check API availability --- api/js/jsapi/egw_notification.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/js/jsapi/egw_notification.js b/api/js/jsapi/egw_notification.js index 46cd4f15a8..dce5af7c4e 100644 --- a/api/js/jsapi/egw_notification.js +++ b/api/js/jsapi/egw_notification.js @@ -28,7 +28,7 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) // Notification permission, the default value is 'default' which is equivalent to 'denied' var permission = 'default'; - + if (typeof Notification != 'undefined') { permission = Notification.permission; @@ -89,6 +89,15 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) // Callback function dispatches on error notification.onerror = options.onerror || function (e) {egw.debug('Notification failed because of ' + e);}; + }, + + /** + * Check Notification availability by browser + * + * @returns {Boolean} true if notification is supported and permitted otherwise false + */ + checkNotification: function () { + return (Notification && Notification.requestPermission && permission == 'granted'); } };