[6774] | 1 | desktopNotification = { |
---|
| 2 | |
---|
| 3 | notification: [], |
---|
| 4 | |
---|
| 5 | initDesktopNotificationAddon: function(){ |
---|
| 6 | if(useDesktopNotification()){ |
---|
[8181] | 7 | if ($.cookie('no-notification') == 'true'){ |
---|
| 8 | return false; |
---|
| 9 | } |
---|
[6774] | 10 | if (!window.webkitNotifications && $.browser.mozilla) |
---|
| 11 | this.installDektopNotificationAddon(); |
---|
| 12 | |
---|
[6788] | 13 | if(window.webkitNotifications && window.webkitNotifications.checkPermission()){ |
---|
[8181] | 14 | if($.browser.safari){ |
---|
[6788] | 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 | }); |
---|
[6774] | 21 | |
---|
[6788] | 22 | $('div.ZebraDialog.request-notification-permission a').click(function() { |
---|
[8181] | 23 | if($(this).html() == 'Sim'){ |
---|
[6788] | 24 | window.webkitNotifications.requestPermission(); |
---|
[8181] | 25 | }else if ($(this).html() == 'Não'){ |
---|
| 26 | $.cookie('no-notification','true'); |
---|
| 27 | } |
---|
[6788] | 28 | }); |
---|
| 29 | }else |
---|
| 30 | window.webkitNotifications.requestPermission(); |
---|
| 31 | } |
---|
[8181] | 32 | }else{ |
---|
| 33 | $.cookie('no-notification',null); |
---|
[6774] | 34 | } |
---|
| 35 | }, |
---|
| 36 | |
---|
| 37 | installDektopNotificationAddon: function(){ |
---|
| 38 | |
---|
[6788] | 39 | var params = { |
---|
[7693] | 40 | "Foo": { |
---|
| 41 | URL: '../prototype/plugins/desktop.notification/html_desktop_notifications.xpi' , |
---|
[6788] | 42 | IconURL:'../prototype/plugins/desktop.notification/desktop-notification.png', |
---|
| 43 | //Hash:'sha1:28857e60d043447c5f4550853f2d40770b326a13', |
---|
| 44 | toString: function () { |
---|
| 45 | return this.URL; |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | }; |
---|
[8181] | 49 | ; |
---|
[6788] | 50 | InstallTrigger.install(params); |
---|
| 51 | return false; |
---|
[6774] | 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; |
---|
[6788] | 94 | if(desktopNotification.verifyComplement()){ |
---|
[6774] | 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(); |
---|
[6768] | 110 | }); |
---|