-
Notifications
You must be signed in to change notification settings - Fork 0
/
noty2.js
39 lines (36 loc) · 1.18 KB
/
noty2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* _noty2 -- (c) 2013-2015 Davor Babic <[email protected]>
* A drop-in replacement for the rutorrent plugin _noty.
*
* Licensed under the MIT licenses:
* http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
if ('Notification' in window) {
$.noty = function(options) {
function showNotification() {
var notification = new Notification('rutorrent', options);
// Close the notification in Chrome after 3s
setTimeout(function() {
notification.close();
}, 3000);
}
options.icon = 'favicon.ico';
options.body = options.text ? options.text : options;
if (Notification.permission === 'granted' ||
(('webkitNotifications' in window &&
window.webkitNotifications.checkPermission() === 0))) {
showNotification();
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
if (!('permission' in Notification)) { // for Chrome
Notification.permission = permission;
}
if (permission === 'granted') {
showNotification();
}
});
}
};
}
})(jQuery);