1 | desktopNotification = { |
---|
2 | |
---|
3 | notification: [], |
---|
4 | |
---|
5 | initDesktopNotificationAddon: function(){ |
---|
6 | if(useDesktopNotification()){ |
---|
7 | if ($.cookie('no-notification') == 'true'){ |
---|
8 | return false; |
---|
9 | } |
---|
10 | if (!window.webkitNotifications && $.browser.mozilla) |
---|
11 | this.installDektopNotificationAddon(); |
---|
12 | |
---|
13 | if(window.webkitNotifications && window.webkitNotifications.checkPermission()){ |
---|
14 | if($.browser.safari){ |
---|
15 | $.Zebra_Dialog('Deseja instalar o plugin de notificação desktop?', { |
---|
16 | 'custom_class': 'request-notification-permission', |
---|
17 | 'type': 'question', |
---|
18 | 'overlay_opacity': '0.5', |
---|
19 | 'buttons': ['Não', 'Sim'] |
---|
20 | }); |
---|
21 | |
---|
22 | $('div.ZebraDialog.request-notification-permission a').click(function() { |
---|
23 | if($(this).html() == 'Sim'){ |
---|
24 | window.webkitNotifications.requestPermission(); |
---|
25 | }else if ($(this).html() == 'Não'){ |
---|
26 | $.cookie('no-notification','true'); |
---|
27 | } |
---|
28 | }); |
---|
29 | }else |
---|
30 | window.webkitNotifications.requestPermission(); |
---|
31 | } |
---|
32 | }else{ |
---|
33 | $.cookie('no-notification',null); |
---|
34 | } |
---|
35 | }, |
---|
36 | |
---|
37 | installDektopNotificationAddon: function(){ |
---|
38 | |
---|
39 | var params = { |
---|
40 | "Foo": { |
---|
41 | URL: '../prototype/plugins/desktop.notification/html_desktop_notifications.xpi' , |
---|
42 | IconURL:'../prototype/plugins/desktop.notification/desktop-notification.png', |
---|
43 | //Hash:'sha1:28857e60d043447c5f4550853f2d40770b326a13', |
---|
44 | toString: function () { |
---|
45 | return this.URL; |
---|
46 | } |
---|
47 | } |
---|
48 | }; |
---|
49 | ; |
---|
50 | InstallTrigger.install(params); |
---|
51 | return false; |
---|
52 | }, |
---|
53 | |
---|
54 | verifyComplement: function(){ |
---|
55 | |
---|
56 | if(!window.webkitNotifications) |
---|
57 | return false; |
---|
58 | |
---|
59 | if(window.webkitNotifications.checkPermission()) |
---|
60 | return false; |
---|
61 | |
---|
62 | return true; |
---|
63 | }, |
---|
64 | |
---|
65 | sentNotification: function(icon, title, body){ |
---|
66 | var reference = this.notification.length; |
---|
67 | this.notification[reference] = window.webkitNotifications.createNotification( icon, title, body); |
---|
68 | return reference; |
---|
69 | }, |
---|
70 | |
---|
71 | cancelByReference: function(index){ |
---|
72 | if(this.notification[index]) |
---|
73 | this.notification[index].cancel(); |
---|
74 | }, |
---|
75 | |
---|
76 | |
---|
77 | showNotification: function(onClose, onClick, onDisplay, onError){ |
---|
78 | var length = this.notification.length -1; |
---|
79 | |
---|
80 | this.notification[length].ondisplay = onDisplay; |
---|
81 | this.notification[length].onclose = onClose; |
---|
82 | this.notification[length].onclick = onClick; |
---|
83 | this.notification[length].onerror = onError; |
---|
84 | |
---|
85 | this.notification[length].show(); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | $(document).ready(function() { |
---|
90 | activePage = true; |
---|
91 | $(window) |
---|
92 | .focus(function() { |
---|
93 | activePage = true; |
---|
94 | if(desktopNotification.verifyComplement()){ |
---|
95 | setTimeout(function(){ |
---|
96 | |
---|
97 | for(var i = 0; i < desktopNotification.notification.length; i++){ |
---|
98 | desktopNotification.notification[i].cancel(); |
---|
99 | } |
---|
100 | desktopNotification.notification = []; |
---|
101 | |
---|
102 | }, 60000); |
---|
103 | } |
---|
104 | }) |
---|
105 | .blur(function() { |
---|
106 | activePage = false; |
---|
107 | }); |
---|
108 | |
---|
109 | desktopNotification.initDesktopNotificationAddon(); |
---|
110 | }); |
---|