1 Module('CustomEventSupport')({
5 bind : function(type
, eventHandler
) {
6 var found
, i
, listeners
;
8 if(!this.eventListeners
) {
9 this.eventListeners
= {};
12 if(!this.eventListeners
[type
]) {
13 this.eventListeners
[type
] = [];
18 listeners
= this.eventListeners
[type
];
19 for (i
= 0; i
< listeners
.length
; i
++) {
20 if (listeners
[i
] === eventHandler
) {
27 this.eventListeners
[type
].push(eventHandler
);
33 unbind : function(type
, eventHandler
) {
34 var i
, found
, listeners
;
38 if(!this.eventListeners
) {
39 this.eventListeners
= {};
42 if(typeof eventHandler
== 'undefined') {
43 this.eventListeners
[type
] = [];
46 listeners
= this.eventListeners
[type
];
47 for (i
= 0; i
< listeners
.length
; i
++) {
48 if(listeners
[i
] === eventHandler
) {
55 this.eventListeners
[type
].splice(i
, 1);
61 dispatch : function(type
, data
) {
62 var event
, listeners
, instance
, i
;
64 if (this.eventListeners
=== null) {
65 this.eventListeners
= {};
68 if (typeof data
=== 'undefined') {
72 if (data
.hasOwnProperty('target') === false) {
76 event
= new CustomEvent(type
, data
);
77 listeners
= this.eventListeners
[type
] || [];
80 for (i
= 0; i
< listeners
.length
; i
= i
+ 1) {
81 listeners
[i
].call(instance
, event
);
82 if (event
.areImmediateHandlersPrevented
=== true) {
92 eventListeners : null,
94 bind : function(type
, eventHandler
) {
95 var found
, i
, listeners
;
97 if(!this.eventListeners
) {
98 this.eventListeners
= {};
101 if(!this.eventListeners
[type
]) {
102 this.eventListeners
[type
] = [];
107 listeners
= this.eventListeners
[type
];
108 for (i
= 0; i
< listeners
.length
; i
++) {
109 if(listeners
[i
] === eventHandler
) {
116 this.eventListeners
[type
].push(eventHandler
);
122 unbind : function(type
, eventHandler
) {
123 var i
, found
, listeners
;
128 if(!this.eventListeners
) {
129 this.eventListeners
= {};
132 if(typeof eventHandler
== 'undefined') {
133 this.eventListeners
[type
] = [];
136 listeners
= this.eventListeners
[type
];
137 for (i
= 0; i
< listeners
.length
; i
++) {
138 if(listeners
[i
] == eventHandler
) {
145 this.eventListeners
[type
].splice(i
, 1);
151 dispatch : function(type
, data
) {
152 var event
, listeners
, instance
, i
;
154 if (this.eventListeners
=== null) {
155 this.eventListeners
= {};
158 if (typeof data
=== 'undefined') {
162 if (data
.hasOwnProperty('target') === false) {
166 event
= new CustomEvent(type
, data
);
167 listeners
= this.eventListeners
[type
] || [];
170 for (i
= 0; i
< listeners
.length
; i
= i
+ 1) {
171 listeners
[i
].call(instance
, event
);
172 if (event
.areImmediateHandlersPrevented
=== true) {