gitlab-org--gitlab-foss/app/assets/javascripts/lib/utils/notify.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

/* eslint-disable func-names, no-var, consistent-return, prefer-arrow-callback, no-return-assign, object-shorthand */
2017-05-26 14:26:06 +00:00
function notificationGranted(message, opts, onclick) {
var notification;
notification = new Notification(message, opts);
setTimeout(function() {
// Hide the notification after X amount of seconds
return notification.close();
}, 8000);
2018-10-10 06:25:43 +00:00
return (notification.onclick = onclick || notification.close);
2017-05-26 14:26:06 +00:00
}
2016-07-24 20:45:11 +00:00
2017-05-26 14:26:06 +00:00
function notifyPermissions() {
if ('Notification' in window) {
return Notification.requestPermission();
}
}
function notifyMe(message, body, icon, onclick) {
var opts;
opts = {
body: body,
2018-10-10 06:25:43 +00:00
icon: icon,
2017-05-26 14:26:06 +00:00
};
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
// do nothing
} else if (Notification.permission === 'granted') {
// If it's okay let's create a notification
return notificationGranted(message, opts, onclick);
} else if (Notification.permission !== 'denied') {
return Notification.requestPermission(function(permission) {
// If the user accepts, let's create a notification
if (permission === 'granted') {
2016-07-24 20:45:11 +00:00
return notificationGranted(message, opts, onclick);
}
2017-05-26 14:26:06 +00:00
});
}
}
const notify = {
notificationGranted,
notifyPermissions,
notifyMe,
};
export default notify;