Check Notification API is supported by browser before using it

This commit is contained in:
Hadi Nategh 2016-05-04 13:04:55 +00:00
parent 3191802117
commit d6d9a076ae

View File

@ -19,14 +19,20 @@
* @augments Class * @augments Class
* @param {string} _app application name object is instanciated for * @param {string} _app application name object is instanciated for
* @param {object} _wnd window object is instanciated for * @param {object} _wnd window object is instanciated for
*
* @return {object} defined functions of module
*/ */
egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd)
{ {
"use strict"; "use strict";
// Notification permission, the default value is 'default' which is equivalent to 'denied' // Notification permission, the default value is 'default' which is equivalent to 'denied'
var permission = Notification.permission || 'default'; var permission = 'default';
if (typeof Notification != 'undefined')
{
permission = Notification.permission;
}
return { return {
@ -45,10 +51,12 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd)
* onclose: // Callback function dispateches on notification close * onclose: // Callback function dispateches on notification close
* onerror: // Callback function dispatches on error, default is a egw.debug log * onerror: // Callback function dispatches on error, default is a egw.debug log
* } * }
* @return {boolean} true if the permission is granted otherwise false * @return {boolean} false if Notification is not supported by browser
*/ */
notification: function (_title, _options) notification: function (_title, _options)
{ {
// Check if the notification is supported by browser
if (typeof Notification == 'undefined') return false;
var self = this; var self = this;
// Check and ask for permission // Check and ask for permission