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