2 * L.Mixin.Events adds custom events functionality to Leaflet classes
8 addEventListener: function(/*String*/ type
, /*Function*/ fn
, /*(optional) Object*/ context
) {
9 var events
= this._leaflet_events
= this._leaflet_events
|| {};
10 events
[type
] = events
[type
] || [];
18 hasEventListeners: function(/*String*/ type
) /*-> Boolean*/ {
19 var k
= '_leaflet_events';
20 return (k
in this) && (type
in this[k
]) && (this[k
][type
].length
> 0);
23 removeEventListener: function(/*String*/ type
, /*Function*/ fn
, /*(optional) Object*/ context
) {
24 if (!this.hasEventListeners(type
)) { return this; }
26 for (var i
= 0, events
= this._leaflet_events
, len
= events
[type
].length
; i
< len
; i
++) {
28 (events
[type
][i
].action
=== fn
) &&
29 (!context
|| (events
[type
][i
].context
=== context
))
31 events
[type
].splice(i
, 1);
38 fireEvent: function(/*String*/ type
, /*(optional) Object*/ data
) {
39 if (!this.hasEventListeners(type
)) { return; }
41 var event
= L
.Util
.extend({
46 var listeners
= this._leaflet_events
[type
].slice();
48 for (var i
= 0, len
= listeners
.length
; i
< len
; i
++) {
49 listeners
[i
].action
.call(listeners
[i
].context
|| this, event
);
56 L
.Mixin
.Events
.on
= L
.Mixin
.Events
.addEventListener
;
57 L
.Mixin
.Events
.off
= L
.Mixin
.Events
.removeEventListener
;
58 L
.Mixin
.Events
.fire
= L
.Mixin
.Events
.fireEvent
;