source: sandbox/2.4.2-expresso1/prototype/modules/calendar/js/desktop.notification.js @ 6768

Revision 6768, 2.2 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2951 - Implementacao da funcionalidade de alarms desktop com suporte a eventos

  • Property svn:executable set to *
Line 
1desktopNotification = {
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
47    sentNotification: function(icon, title, body){
48        this.notification[this.notification.length] = window.webkitNotifications.createNotification( icon, title, body);
49    },
50
51    showNotification: function(onClose, onClick, onDisplay, onError){
52        var length = this.notification.length -1;
53
54        this.notification[length].ondisplay = onDisplay;
55        this.notification[length].onclose = onClose;
56        this.notification[length].onclick = onClick;
57        this.notification[length].onerror = onError;
58
59        this.notification[length].show();
60    }
61}
62
63$(document).ready(function() {
64    activePage = true;
65    $(window)
66        .focus(function() {
67            activePage = true; 
68            if(!desktopNotification.verifyComplement()){
69                setTimeout(function(){             
70                    console.log(desktopNotification.notification);
71                   
72                    for(var i = 0; i < desktopNotification.notification.length; i++){
73                        desktopNotification.notification[i].cancel();
74                    }               
75                    desktopNotification.notification = [];
76
77                    console.log(desktopNotification.notification);
78                }, 60000);
79            }
80        })
81        .blur(function() {
82            activePage = false;
83        });
84
85    desktopNotification.initDesktopNotificationAddon();
86});
Note: See TracBrowser for help on using the repository browser.