1 | desktopNotification = { |
---|
2 | |
---|
3 | notification: [], |
---|
4 | |
---|
5 | initDesktopNotificationAddon: function(){ |
---|
6 | if(useDesktopNotification()){ |
---|
7 | |
---|
8 | if (!window.webkitNotifications && $.browser.mozilla) |
---|
9 | this.installDektopNotificationAddon(); |
---|
10 | |
---|
11 | if(window.webkitNotifications && window.webkitNotifications.checkPermission()) |
---|
12 | window.webkitNotifications.requestPermission(); |
---|
13 | |
---|
14 | } |
---|
15 | }, |
---|
16 | |
---|
17 | installDektopNotificationAddon: function(){ |
---|
18 | |
---|
19 | var params = { |
---|
20 | "Foo": { |
---|
21 | URL: '../prototype/plugins/desktop.notification/html_desktop_notifications-1.0.7-fx.xpi' , |
---|
22 | IconURL:'../prototype/plugins/desktop.notification/desktop-notification.png', |
---|
23 | //Hash:'sha1:28857e60d043447c5f4550853f2d40770b326a13', |
---|
24 | toString: function () { |
---|
25 | return this.URL; |
---|
26 | } |
---|
27 | } |
---|
28 | }; |
---|
29 | |
---|
30 | InstallTrigger.install(params); |
---|
31 | |
---|
32 | return false; |
---|
33 | }, |
---|
34 | |
---|
35 | verifyComplement: function(){ |
---|
36 | |
---|
37 | if(!window.webkitNotifications) |
---|
38 | return false; |
---|
39 | |
---|
40 | if(window.webkitNotifications.checkPermission()) |
---|
41 | return false; |
---|
42 | |
---|
43 | return true; |
---|
44 | }, |
---|
45 | |
---|
46 | sentNotification: function(icon, title, body){ |
---|
47 | var reference = this.notification.length; |
---|
48 | this.notification[reference] = window.webkitNotifications.createNotification( icon, title, body); |
---|
49 | return reference; |
---|
50 | }, |
---|
51 | |
---|
52 | cancelByReference: function(index){ |
---|
53 | if(this.notification[index]) |
---|
54 | this.notification[index].cancel(); |
---|
55 | }, |
---|
56 | |
---|
57 | |
---|
58 | showNotification: function(onClose, onClick, onDisplay, onError){ |
---|
59 | var length = this.notification.length -1; |
---|
60 | |
---|
61 | this.notification[length].ondisplay = onDisplay; |
---|
62 | this.notification[length].onclose = onClose; |
---|
63 | this.notification[length].onclick = onClick; |
---|
64 | this.notification[length].onerror = onError; |
---|
65 | |
---|
66 | this.notification[length].show(); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | $(document).ready(function() { |
---|
71 | activePage = true; |
---|
72 | $(window) |
---|
73 | .focus(function() { |
---|
74 | activePage = true; |
---|
75 | if(!desktopNotification.verifyComplement()){ |
---|
76 | setTimeout(function(){ |
---|
77 | |
---|
78 | for(var i = 0; i < desktopNotification.notification.length; i++){ |
---|
79 | desktopNotification.notification[i].cancel(); |
---|
80 | } |
---|
81 | desktopNotification.notification = []; |
---|
82 | |
---|
83 | }, 60000); |
---|
84 | } |
---|
85 | }) |
---|
86 | .blur(function() { |
---|
87 | activePage = false; |
---|
88 | }); |
---|
89 | |
---|
90 | desktopNotification.initDesktopNotificationAddon(); |
---|
91 | }); |
---|