-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheasyNotify.js
60 lines (46 loc) · 1.39 KB
/
easyNotify.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function($) {
$.fn.easyNotify = function(options) {
var settings = $.extend({
title: "Notification",
options: {
body: "",
icon: "",
lang: 'pt-BR',
onClose: "",
onClick: "",
onError: ""
}
}, options);
this.init = function() {
var notify = this;
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
var notification = new Notification(settings.title, settings.options);
notification.onclose = function() {
if (typeof settings.options.onClose == 'function') {
settings.options.onClose();
}
};
notification.onclick = function(){
if (typeof settings.options.onClick == 'function') {
settings.options.onClick();
}
};
notification.onerror = function(){
if (typeof settings.options.onError == 'function') {
settings.options.onError();
}
};
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
if (permission === "granted") {
notify.init();
}
});
}
};
this.init();
return this;
};
}(jQuery));