change id validation rule on register
[namibia] / public / js / app / event.js
1 ;(function(){
2
3         _App.Event = function()
4         {
5                 this.initialize();
6         };
7
8         _App.Event.prototype =
9         {
10
11                 listenerStore : {},
12
13                 initialize : function()
14                 {
15                                 this.listenerStore = {};
16                 },
17
18                 /**
19                  * Register an Event Listener.
20                  * @param id
21                  * @param event
22                  * @param callback
23                  * @param type
24                  */
25                 listen : function(id, event, callback, type)
26                 {
27                         if (!this.listenerStore[event])
28                         {
29                                 this.listenerStore[event] = {};
30                         }
31                         this.listenerStore[event][id] = {
32                                         "callback": callback,
33                                         "type": (type ? type : "UseOnce")
34                         };
35                 },
36
37                 /**
38                  * Remove a registered Event Listener.
39                  * @param id
40                  * @param event
41                  */
42                 removeListener : function(id, event)
43                 {
44                         if (this.listenerStore[event] && this.listenerStore[event][id])
45                         {
46                                 delete this.listenerStore[event][id];
47                         }
48                 },
49
50                 /**
51                  * Trigger an event.
52                  * @param event
53                  * @param data
54                  */
55                 trigger : function(event, data)
56                 {
57                         if (this.listenerStore[event])
58                         {
59                                 for (var id in this.listenerStore[event])
60                                 {
61                                         this.listenerStore[event][id]["callback"](event, data);
62                                         if ("UseOnce" == this.listenerStore[event][id]["type"])
63                                         {
64                                                 delete this.listenerStore[event][id];
65                                         }
66                                 }
67                         }
68                 }
69
70         };
71
72 })();