debian-mirror-gitlab/app/assets/javascripts/lib/utils/notify.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-09-13 17:45:13 +05:30
(function() {
(function(w) {
var notificationGranted, notifyMe, notifyPermissions;
notificationGranted = function(message, opts, onclick) {
var notification;
notification = new Notification(message, opts);
setTimeout(function() {
return notification.close();
2016-09-29 09:46:39 +05:30
// Hide the notification after X amount of seconds
2016-09-13 17:45:13 +05:30
}, 8000);
if (onclick) {
return notification.onclick = onclick;
}
};
notifyPermissions = function() {
if ('Notification' in window) {
return Notification.requestPermission();
}
};
notifyMe = function(message, body, icon, onclick) {
var opts;
opts = {
body: body,
icon: icon
};
2016-09-29 09:46:39 +05:30
// Let's check if the browser supports notifications
2016-09-13 17:45:13 +05:30
if (!('Notification' in window)) {
2016-09-29 09:46:39 +05:30
// do nothing
2016-09-13 17:45:13 +05:30
} else if (Notification.permission === 'granted') {
2016-09-29 09:46:39 +05:30
// If it's okay let's create a notification
2016-09-13 17:45:13 +05:30
return notificationGranted(message, opts, onclick);
} else if (Notification.permission !== 'denied') {
return Notification.requestPermission(function(permission) {
2016-09-29 09:46:39 +05:30
// If the user accepts, let's create a notification
2016-09-13 17:45:13 +05:30
if (permission === 'granted') {
return notificationGranted(message, opts, onclick);
}
});
}
};
w.notify = notifyMe;
return w.notifyPermissions = notifyPermissions;
})(window);
}).call(this);