decidim 0.26.9 → 0.26.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/decidim/version.rb +1 -1
- data/package-lock.json +7 -7
- data/packages/browserslist-config/package.json +1 -1
- data/packages/core/node_modules/leaflet/CHANGELOG.md +2191 -0
- data/packages/core/node_modules/leaflet/LICENSE +26 -0
- data/packages/core/node_modules/leaflet/README.md +55 -0
- data/packages/core/node_modules/leaflet/dist/images/layers-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/layers.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-shadow.png +0 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js +14419 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js +14512 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.css +661 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js +6 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js.map +1 -0
- data/packages/core/node_modules/leaflet/package.json +149 -0
- data/packages/core/node_modules/leaflet/src/Leaflet.js +24 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Attribution.js +148 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Layers.js +443 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Scale.js +132 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Zoom.js +146 -0
- data/packages/core/node_modules/leaflet/src/control/Control.js +174 -0
- data/packages/core/node_modules/leaflet/src/control/index.js +17 -0
- data/packages/core/node_modules/leaflet/src/core/Browser.js +220 -0
- data/packages/core/node_modules/leaflet/src/core/Class.js +135 -0
- data/packages/core/node_modules/leaflet/src/core/Class.leafdoc +197 -0
- data/packages/core/node_modules/leaflet/src/core/Events.js +344 -0
- data/packages/core/node_modules/leaflet/src/core/Events.leafdoc +143 -0
- data/packages/core/node_modules/leaflet/src/core/Handler.js +57 -0
- data/packages/core/node_modules/leaflet/src/core/Util.js +241 -0
- data/packages/core/node_modules/leaflet/src/core/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.DoubleTap.js +91 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.Pointer.js +97 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.js +315 -0
- data/packages/core/node_modules/leaflet/src/dom/DomUtil.js +349 -0
- data/packages/core/node_modules/leaflet/src/dom/Draggable.js +220 -0
- data/packages/core/node_modules/leaflet/src/dom/PosAnimation.js +113 -0
- data/packages/core/node_modules/leaflet/src/dom/index.js +9 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLng.js +137 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLngBounds.js +251 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3395.js +20 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3857.js +27 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG4326.js +23 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Earth.js +33 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Simple.js +36 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.js +139 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/geo/index.js +7 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.LonLat.js +28 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.Mercator.js +49 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.SphericalMercator.js +44 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/index.js +26 -0
- data/packages/core/node_modules/leaflet/src/geometry/Bounds.js +219 -0
- data/packages/core/node_modules/leaflet/src/geometry/LineUtil.js +306 -0
- data/packages/core/node_modules/leaflet/src/geometry/Point.js +222 -0
- data/packages/core/node_modules/leaflet/src/geometry/PolyUtil.js +129 -0
- data/packages/core/node_modules/leaflet/src/geometry/Transformation.js +79 -0
- data/packages/core/node_modules/leaflet/src/geometry/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/images/layers.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/logo.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/marker.svg +1 -0
- data/packages/core/node_modules/leaflet/src/layer/DivOverlay.js +348 -0
- data/packages/core/node_modules/leaflet/src/layer/FeatureGroup.js +94 -0
- data/packages/core/node_modules/leaflet/src/layer/GeoJSON.js +452 -0
- data/packages/core/node_modules/leaflet/src/layer/ImageOverlay.js +270 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.Interactive.leafdoc +39 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.js +275 -0
- data/packages/core/node_modules/leaflet/src/layer/LayerGroup.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/Popup.js +506 -0
- data/packages/core/node_modules/leaflet/src/layer/SVGOverlay.js +50 -0
- data/packages/core/node_modules/leaflet/src/layer/Tooltip.js +444 -0
- data/packages/core/node_modules/leaflet/src/layer/VideoOverlay.js +106 -0
- data/packages/core/node_modules/leaflet/src/layer/index.js +24 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/DivIcon.js +74 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.Default.js +66 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.js +165 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.Drag.js +161 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.js +419 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/GridLayer.js +923 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.WMS.js +137 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.js +289 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/index.js +6 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Canvas.js +492 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Circle.js +113 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/CircleMarker.js +109 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Path.js +148 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polygon.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polyline.js +307 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Rectangle.js +57 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.getRenderer.js +45 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.js +133 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.Util.js +39 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.VML.js +144 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.js +207 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/index.js +14 -0
- data/packages/core/node_modules/leaflet/src/map/Map.js +1751 -0
- data/packages/core/node_modules/leaflet/src/map/Map.methodOptions.leafdoc +112 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.BoxZoom.js +152 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.DoubleClickZoom.js +55 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Drag.js +235 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Keyboard.js +183 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.ScrollWheelZoom.js +91 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TapHold.js +102 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TouchZoom.js +130 -0
- data/packages/core/node_modules/leaflet/src/map/index.js +17 -0
- data/packages/core/package.json +1 -1
- data/packages/dev/package.json +1 -1
- data/packages/elections/package.json +1 -1
- data/packages/eslint-config/package.json +1 -1
- data/packages/stylelint-config/package.json +1 -1
- data/packages/webpacker/package.json +1 -1
- metadata +148 -42
@@ -0,0 +1,197 @@
|
|
1
|
+
|
2
|
+
@class Class
|
3
|
+
@aka L.Class
|
4
|
+
|
5
|
+
L.Class powers the OOP facilities of Leaflet and is used to create almost all of the Leaflet classes documented here.
|
6
|
+
|
7
|
+
In addition to implementing a simple classical inheritance model, it introduces several special properties for convenient code organization — options, includes and statics.
|
8
|
+
|
9
|
+
|
10
|
+
@example
|
11
|
+
|
12
|
+
```js
|
13
|
+
var MyClass = L.Class.extend({
|
14
|
+
initialize: function (greeter) {
|
15
|
+
this.greeter = greeter;
|
16
|
+
// class constructor
|
17
|
+
},
|
18
|
+
|
19
|
+
greet: function (name) {
|
20
|
+
alert(this.greeter + ', ' + name)
|
21
|
+
}
|
22
|
+
});
|
23
|
+
|
24
|
+
// create instance of MyClass, passing "Hello" to the constructor
|
25
|
+
var a = new MyClass("Hello");
|
26
|
+
|
27
|
+
// call greet method, alerting "Hello, World"
|
28
|
+
a.greet("World");
|
29
|
+
```
|
30
|
+
|
31
|
+
@section Class Factories
|
32
|
+
@example
|
33
|
+
|
34
|
+
You may have noticed that Leaflet objects are created without using
|
35
|
+
the `new` keyword. This is achieved by complementing each class with a
|
36
|
+
lowercase factory method:
|
37
|
+
|
38
|
+
```js
|
39
|
+
new L.Map('map'); // becomes:
|
40
|
+
L.map('map');
|
41
|
+
```
|
42
|
+
|
43
|
+
The factories are implemented very easily, and you can do this for your own classes:
|
44
|
+
|
45
|
+
```js
|
46
|
+
L.map = function (id, options) {
|
47
|
+
return new L.Map(id, options);
|
48
|
+
};
|
49
|
+
```
|
50
|
+
@section Inheritance
|
51
|
+
@example
|
52
|
+
|
53
|
+
You use L.Class.extend to define new classes, but you can use the same method on any class to inherit from it:
|
54
|
+
|
55
|
+
```js
|
56
|
+
var MyChildClass = MyClass.extend({
|
57
|
+
// ... new properties and methods
|
58
|
+
});
|
59
|
+
```
|
60
|
+
|
61
|
+
This will create a class that inherits all methods and properties of the parent class (through a proper prototype chain), adding or overriding the ones you pass to extend. It will also properly react to instanceof:
|
62
|
+
|
63
|
+
```js
|
64
|
+
var a = new MyChildClass();
|
65
|
+
a instanceof MyChildClass; // true
|
66
|
+
a instanceof MyClass; // true
|
67
|
+
```
|
68
|
+
|
69
|
+
You can call parent methods (including constructor) from corresponding child ones (as you do with super calls in other languages) by accessing parent class prototype and using JavaScript's call or apply:
|
70
|
+
|
71
|
+
```
|
72
|
+
var MyChildClass = MyClass.extend({
|
73
|
+
initialize: function () {
|
74
|
+
MyClass.prototype.initialize.call(this, "Yo");
|
75
|
+
},
|
76
|
+
|
77
|
+
greet: function (name) {
|
78
|
+
MyClass.prototype.greet.call(this, 'bro ' + name + '!');
|
79
|
+
}
|
80
|
+
});
|
81
|
+
|
82
|
+
var a = new MyChildClass();
|
83
|
+
a.greet('Jason'); // alerts "Yo, bro Jason!"
|
84
|
+
```
|
85
|
+
|
86
|
+
@section Options
|
87
|
+
@example
|
88
|
+
|
89
|
+
`options` is a special property that unlike other objects that you pass
|
90
|
+
to `extend` will be merged with the parent one instead of overriding it
|
91
|
+
completely, which makes managing configuration of objects and default
|
92
|
+
values convenient:
|
93
|
+
|
94
|
+
```js
|
95
|
+
var MyClass = L.Class.extend({
|
96
|
+
options: {
|
97
|
+
myOption1: 'foo',
|
98
|
+
myOption2: 'bar'
|
99
|
+
}
|
100
|
+
});
|
101
|
+
|
102
|
+
var MyChildClass = MyClass.extend({
|
103
|
+
options: {
|
104
|
+
myOption1: 'baz',
|
105
|
+
myOption3: 5
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
var a = new MyChildClass();
|
110
|
+
a.options.myOption1; // 'baz'
|
111
|
+
a.options.myOption2; // 'bar'
|
112
|
+
a.options.myOption3; // 5
|
113
|
+
```
|
114
|
+
|
115
|
+
There's also [`L.Util.setOptions`](#util-setoptions), a method for
|
116
|
+
conveniently merging options passed to constructor with the defaults
|
117
|
+
defines in the class:
|
118
|
+
|
119
|
+
```js
|
120
|
+
var MyClass = L.Class.extend({
|
121
|
+
options: {
|
122
|
+
foo: 'bar',
|
123
|
+
bla: 5
|
124
|
+
},
|
125
|
+
|
126
|
+
initialize: function (options) {
|
127
|
+
L.Util.setOptions(this, options);
|
128
|
+
...
|
129
|
+
}
|
130
|
+
});
|
131
|
+
|
132
|
+
var a = new MyClass({bla: 10});
|
133
|
+
a.options; // {foo: 'bar', bla: 10}
|
134
|
+
```
|
135
|
+
|
136
|
+
Note that the options object allows any keys, not just
|
137
|
+
the options defined by the class and its base classes.
|
138
|
+
This means you can use the options object to store
|
139
|
+
application specific information, as long as you avoid
|
140
|
+
keys that are already used by the class in question.
|
141
|
+
|
142
|
+
@section Includes
|
143
|
+
@example
|
144
|
+
|
145
|
+
`includes` is a special class property that merges all specified objects into the class (such objects are called mixins).
|
146
|
+
|
147
|
+
```js
|
148
|
+
var MyMixin = {
|
149
|
+
foo: function () { ... },
|
150
|
+
bar: 5
|
151
|
+
};
|
152
|
+
|
153
|
+
var MyClass = L.Class.extend({
|
154
|
+
includes: MyMixin
|
155
|
+
});
|
156
|
+
|
157
|
+
var a = new MyClass();
|
158
|
+
a.foo();
|
159
|
+
```
|
160
|
+
|
161
|
+
You can also do such includes in runtime with the `include` method:
|
162
|
+
|
163
|
+
```js
|
164
|
+
MyClass.include(MyMixin);
|
165
|
+
```
|
166
|
+
|
167
|
+
`statics` is just a convenience property that injects specified object properties as the static properties of the class, useful for defining constants:
|
168
|
+
|
169
|
+
```js
|
170
|
+
var MyClass = L.Class.extend({
|
171
|
+
statics: {
|
172
|
+
FOO: 'bar',
|
173
|
+
BLA: 5
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
MyClass.FOO; // 'bar'
|
178
|
+
```
|
179
|
+
|
180
|
+
|
181
|
+
@section Constructor hooks
|
182
|
+
@example
|
183
|
+
|
184
|
+
If you're a plugin developer, you often need to add additional initialization code to existing classes (e.g. editing hooks for `L.Polyline`). Leaflet comes with a way to do it easily using the `addInitHook` method:
|
185
|
+
|
186
|
+
```js
|
187
|
+
MyClass.addInitHook(function () {
|
188
|
+
// ... do something in constructor additionally
|
189
|
+
// e.g. add event listeners, set custom properties etc.
|
190
|
+
});
|
191
|
+
```
|
192
|
+
|
193
|
+
You can also use the following shortcut when you just need to make one additional method call:
|
194
|
+
|
195
|
+
```js
|
196
|
+
MyClass.addInitHook('methodName', arg1, arg2, …);
|
197
|
+
```
|
@@ -0,0 +1,344 @@
|
|
1
|
+
import {Class} from './Class';
|
2
|
+
import * as Util from './Util';
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @class Evented
|
6
|
+
* @aka L.Evented
|
7
|
+
* @inherits Class
|
8
|
+
*
|
9
|
+
* A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
*
|
13
|
+
* ```js
|
14
|
+
* map.on('click', function(e) {
|
15
|
+
* alert(e.latlng);
|
16
|
+
* } );
|
17
|
+
* ```
|
18
|
+
*
|
19
|
+
* Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:
|
20
|
+
*
|
21
|
+
* ```js
|
22
|
+
* function onClick(e) { ... }
|
23
|
+
*
|
24
|
+
* map.on('click', onClick);
|
25
|
+
* map.off('click', onClick);
|
26
|
+
* ```
|
27
|
+
*/
|
28
|
+
|
29
|
+
export var Events = {
|
30
|
+
/* @method on(type: String, fn: Function, context?: Object): this
|
31
|
+
* Adds a listener function (`fn`) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. `'click dblclick'`).
|
32
|
+
*
|
33
|
+
* @alternative
|
34
|
+
* @method on(eventMap: Object): this
|
35
|
+
* Adds a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
36
|
+
*/
|
37
|
+
on: function (types, fn, context) {
|
38
|
+
|
39
|
+
// types can be a map of types/handlers
|
40
|
+
if (typeof types === 'object') {
|
41
|
+
for (var type in types) {
|
42
|
+
// we don't process space-separated events here for performance;
|
43
|
+
// it's a hot path since Layer uses the on(obj) syntax
|
44
|
+
this._on(type, types[type], fn);
|
45
|
+
}
|
46
|
+
|
47
|
+
} else {
|
48
|
+
// types can be a string of space-separated words
|
49
|
+
types = Util.splitWords(types);
|
50
|
+
|
51
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
52
|
+
this._on(types[i], fn, context);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return this;
|
57
|
+
},
|
58
|
+
|
59
|
+
/* @method off(type: String, fn?: Function, context?: Object): this
|
60
|
+
* Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to `on`, you must pass the same context to `off` in order to remove the listener.
|
61
|
+
*
|
62
|
+
* @alternative
|
63
|
+
* @method off(eventMap: Object): this
|
64
|
+
* Removes a set of type/listener pairs.
|
65
|
+
*
|
66
|
+
* @alternative
|
67
|
+
* @method off: this
|
68
|
+
* Removes all listeners to all events on the object. This includes implicitly attached events.
|
69
|
+
*/
|
70
|
+
off: function (types, fn, context) {
|
71
|
+
|
72
|
+
if (!arguments.length) {
|
73
|
+
// clear all listeners if called without arguments
|
74
|
+
delete this._events;
|
75
|
+
|
76
|
+
} else if (typeof types === 'object') {
|
77
|
+
for (var type in types) {
|
78
|
+
this._off(type, types[type], fn);
|
79
|
+
}
|
80
|
+
|
81
|
+
} else {
|
82
|
+
types = Util.splitWords(types);
|
83
|
+
|
84
|
+
var removeAll = arguments.length === 1;
|
85
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
86
|
+
if (removeAll) {
|
87
|
+
this._off(types[i]);
|
88
|
+
} else {
|
89
|
+
this._off(types[i], fn, context);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
return this;
|
95
|
+
},
|
96
|
+
|
97
|
+
// attach listener (without syntactic sugar now)
|
98
|
+
_on: function (type, fn, context, _once) {
|
99
|
+
if (typeof fn !== 'function') {
|
100
|
+
console.warn('wrong listener type: ' + typeof fn);
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
|
104
|
+
// check if fn already there
|
105
|
+
if (this._listens(type, fn, context) !== false) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (context === this) {
|
110
|
+
// Less memory footprint.
|
111
|
+
context = undefined;
|
112
|
+
}
|
113
|
+
|
114
|
+
var newListener = {fn: fn, ctx: context};
|
115
|
+
if (_once) {
|
116
|
+
newListener.once = true;
|
117
|
+
}
|
118
|
+
|
119
|
+
this._events = this._events || {};
|
120
|
+
this._events[type] = this._events[type] || [];
|
121
|
+
this._events[type].push(newListener);
|
122
|
+
},
|
123
|
+
|
124
|
+
_off: function (type, fn, context) {
|
125
|
+
var listeners,
|
126
|
+
i,
|
127
|
+
len;
|
128
|
+
|
129
|
+
if (!this._events) {
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
|
133
|
+
listeners = this._events[type];
|
134
|
+
if (!listeners) {
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
|
138
|
+
if (arguments.length === 1) { // remove all
|
139
|
+
if (this._firingCount) {
|
140
|
+
// Set all removed listeners to noop
|
141
|
+
// so they are not called if remove happens in fire
|
142
|
+
for (i = 0, len = listeners.length; i < len; i++) {
|
143
|
+
listeners[i].fn = Util.falseFn;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
// clear all listeners for a type if function isn't specified
|
147
|
+
delete this._events[type];
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
|
151
|
+
if (typeof fn !== 'function') {
|
152
|
+
console.warn('wrong listener type: ' + typeof fn);
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
// find fn and remove it
|
157
|
+
var index = this._listens(type, fn, context);
|
158
|
+
if (index !== false) {
|
159
|
+
var listener = listeners[index];
|
160
|
+
if (this._firingCount) {
|
161
|
+
// set the removed listener to noop so that's not called if remove happens in fire
|
162
|
+
listener.fn = Util.falseFn;
|
163
|
+
|
164
|
+
/* copy array in case events are being fired */
|
165
|
+
this._events[type] = listeners = listeners.slice();
|
166
|
+
}
|
167
|
+
listeners.splice(index, 1);
|
168
|
+
}
|
169
|
+
},
|
170
|
+
|
171
|
+
// @method fire(type: String, data?: Object, propagate?: Boolean): this
|
172
|
+
// Fires an event of the specified type. You can optionally provide a data
|
173
|
+
// object — the first argument of the listener function will contain its
|
174
|
+
// properties. The event can optionally be propagated to event parents.
|
175
|
+
fire: function (type, data, propagate) {
|
176
|
+
if (!this.listens(type, propagate)) { return this; }
|
177
|
+
|
178
|
+
var event = Util.extend({}, data, {
|
179
|
+
type: type,
|
180
|
+
target: this,
|
181
|
+
sourceTarget: data && data.sourceTarget || this
|
182
|
+
});
|
183
|
+
|
184
|
+
if (this._events) {
|
185
|
+
var listeners = this._events[type];
|
186
|
+
if (listeners) {
|
187
|
+
this._firingCount = (this._firingCount + 1) || 1;
|
188
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
189
|
+
var l = listeners[i];
|
190
|
+
// off overwrites l.fn, so we need to copy fn to a var
|
191
|
+
var fn = l.fn;
|
192
|
+
if (l.once) {
|
193
|
+
this.off(type, fn, l.ctx);
|
194
|
+
}
|
195
|
+
fn.call(l.ctx || this, event);
|
196
|
+
}
|
197
|
+
|
198
|
+
this._firingCount--;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
if (propagate) {
|
203
|
+
// propagate the event to parents (set with addEventParent)
|
204
|
+
this._propagateEvent(event);
|
205
|
+
}
|
206
|
+
|
207
|
+
return this;
|
208
|
+
},
|
209
|
+
|
210
|
+
// @method listens(type: String, propagate?: Boolean): Boolean
|
211
|
+
// @method listens(type: String, fn: Function, context?: Object, propagate?: Boolean): Boolean
|
212
|
+
// Returns `true` if a particular event type has any listeners attached to it.
|
213
|
+
// The verification can optionally be propagated, it will return `true` if parents have the listener attached to it.
|
214
|
+
listens: function (type, fn, context, propagate) {
|
215
|
+
if (typeof type !== 'string') {
|
216
|
+
console.warn('"string" type argument expected');
|
217
|
+
}
|
218
|
+
|
219
|
+
// we don't overwrite the input `fn` value, because we need to use it for propagation
|
220
|
+
var _fn = fn;
|
221
|
+
if (typeof fn !== 'function') {
|
222
|
+
propagate = !!fn;
|
223
|
+
_fn = undefined;
|
224
|
+
context = undefined;
|
225
|
+
}
|
226
|
+
|
227
|
+
var listeners = this._events && this._events[type];
|
228
|
+
if (listeners && listeners.length) {
|
229
|
+
if (this._listens(type, _fn, context) !== false) {
|
230
|
+
return true;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
if (propagate) {
|
235
|
+
// also check parents for listeners if event propagates
|
236
|
+
for (var id in this._eventParents) {
|
237
|
+
if (this._eventParents[id].listens(type, fn, context, propagate)) { return true; }
|
238
|
+
}
|
239
|
+
}
|
240
|
+
return false;
|
241
|
+
},
|
242
|
+
|
243
|
+
// returns the index (number) or false
|
244
|
+
_listens: function (type, fn, context) {
|
245
|
+
if (!this._events) {
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
|
249
|
+
var listeners = this._events[type] || [];
|
250
|
+
if (!fn) {
|
251
|
+
return !!listeners.length;
|
252
|
+
}
|
253
|
+
|
254
|
+
if (context === this) {
|
255
|
+
// Less memory footprint.
|
256
|
+
context = undefined;
|
257
|
+
}
|
258
|
+
|
259
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
260
|
+
if (listeners[i].fn === fn && listeners[i].ctx === context) {
|
261
|
+
return i;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
return false;
|
265
|
+
|
266
|
+
},
|
267
|
+
|
268
|
+
// @method once(…): this
|
269
|
+
// Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.
|
270
|
+
once: function (types, fn, context) {
|
271
|
+
|
272
|
+
// types can be a map of types/handlers
|
273
|
+
if (typeof types === 'object') {
|
274
|
+
for (var type in types) {
|
275
|
+
// we don't process space-separated events here for performance;
|
276
|
+
// it's a hot path since Layer uses the on(obj) syntax
|
277
|
+
this._on(type, types[type], fn, true);
|
278
|
+
}
|
279
|
+
|
280
|
+
} else {
|
281
|
+
// types can be a string of space-separated words
|
282
|
+
types = Util.splitWords(types);
|
283
|
+
|
284
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
285
|
+
this._on(types[i], fn, context, true);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
return this;
|
290
|
+
},
|
291
|
+
|
292
|
+
// @method addEventParent(obj: Evented): this
|
293
|
+
// Adds an event parent - an `Evented` that will receive propagated events
|
294
|
+
addEventParent: function (obj) {
|
295
|
+
this._eventParents = this._eventParents || {};
|
296
|
+
this._eventParents[Util.stamp(obj)] = obj;
|
297
|
+
return this;
|
298
|
+
},
|
299
|
+
|
300
|
+
// @method removeEventParent(obj: Evented): this
|
301
|
+
// Removes an event parent, so it will stop receiving propagated events
|
302
|
+
removeEventParent: function (obj) {
|
303
|
+
if (this._eventParents) {
|
304
|
+
delete this._eventParents[Util.stamp(obj)];
|
305
|
+
}
|
306
|
+
return this;
|
307
|
+
},
|
308
|
+
|
309
|
+
_propagateEvent: function (e) {
|
310
|
+
for (var id in this._eventParents) {
|
311
|
+
this._eventParents[id].fire(e.type, Util.extend({
|
312
|
+
layer: e.target,
|
313
|
+
propagatedFrom: e.target
|
314
|
+
}, e), true);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
};
|
318
|
+
|
319
|
+
// aliases; we should ditch those eventually
|
320
|
+
|
321
|
+
// @method addEventListener(…): this
|
322
|
+
// Alias to [`on(…)`](#evented-on)
|
323
|
+
Events.addEventListener = Events.on;
|
324
|
+
|
325
|
+
// @method removeEventListener(…): this
|
326
|
+
// Alias to [`off(…)`](#evented-off)
|
327
|
+
|
328
|
+
// @method clearAllEventListeners(…): this
|
329
|
+
// Alias to [`off()`](#evented-off)
|
330
|
+
Events.removeEventListener = Events.clearAllEventListeners = Events.off;
|
331
|
+
|
332
|
+
// @method addOneTimeEventListener(…): this
|
333
|
+
// Alias to [`once(…)`](#evented-once)
|
334
|
+
Events.addOneTimeEventListener = Events.once;
|
335
|
+
|
336
|
+
// @method fireEvent(…): this
|
337
|
+
// Alias to [`fire(…)`](#evented-fire)
|
338
|
+
Events.fireEvent = Events.fire;
|
339
|
+
|
340
|
+
// @method hasEventListeners(…): Boolean
|
341
|
+
// Alias to [`listens(…)`](#evented-listens)
|
342
|
+
Events.hasEventListeners = Events.listens;
|
343
|
+
|
344
|
+
export var Evented = Class.extend(Events);
|
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
@namespace Event objects
|
3
|
+
|
4
|
+
|
5
|
+
Whenever a class inheriting from `Evented` fires an event, a listener function
|
6
|
+
will be called with an event argument, which is a plain object containing
|
7
|
+
information about the event. For example:
|
8
|
+
|
9
|
+
```js
|
10
|
+
map.on('click', function(ev) {
|
11
|
+
alert(ev.latlng); // ev is an event object (MouseEvent in this case)
|
12
|
+
});
|
13
|
+
```
|
14
|
+
|
15
|
+
The information available depends on the event type:
|
16
|
+
|
17
|
+
|
18
|
+
@miniclass Event (Event objects)
|
19
|
+
@section
|
20
|
+
The base event object. All other event objects contain these properties too.
|
21
|
+
@property type: String
|
22
|
+
The event type (e.g. `'click'`).
|
23
|
+
@property target: Object
|
24
|
+
The object that fired the event. For propagated events, the last object in
|
25
|
+
the propagation chain that fired the event.
|
26
|
+
@property sourceTarget: Object
|
27
|
+
The object that originally fired the event. For non-propagated events, this will
|
28
|
+
be the same as the `target`.
|
29
|
+
@property propagatedFrom: Object
|
30
|
+
For propagated events, the last object that propagated the event to its
|
31
|
+
event parent.
|
32
|
+
@property layer: Object
|
33
|
+
**Deprecated.** The same as `propagatedFrom`.
|
34
|
+
|
35
|
+
|
36
|
+
@miniclass KeyboardEvent (Event objects)
|
37
|
+
@inherits Event
|
38
|
+
@property originalEvent: DOMEvent
|
39
|
+
The original [DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) that triggered this Leaflet event.
|
40
|
+
|
41
|
+
@miniclass MouseEvent (Event objects)
|
42
|
+
@inherits Event
|
43
|
+
@property latlng: LatLng
|
44
|
+
The geographical point where the mouse event occurred.
|
45
|
+
@property layerPoint: Point
|
46
|
+
Pixel coordinates of the point where the mouse event occurred relative to the map layer.
|
47
|
+
@property containerPoint: Point
|
48
|
+
Pixel coordinates of the point where the mouse event occurred relative to the map сontainer.
|
49
|
+
@property originalEvent: DOMEvent
|
50
|
+
The original [DOM `MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) or [DOM `TouchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent) that triggered this Leaflet event.
|
51
|
+
|
52
|
+
@miniclass LocationEvent (Event objects)
|
53
|
+
@inherits Event
|
54
|
+
@property latlng: LatLng
|
55
|
+
Detected geographical location of the user.
|
56
|
+
@property bounds: LatLngBounds
|
57
|
+
Geographical bounds of the area user is located in (with respect to the accuracy of location).
|
58
|
+
@property accuracy: Number
|
59
|
+
Accuracy of location in meters.
|
60
|
+
@property altitude: Number
|
61
|
+
Height of the position above the WGS84 ellipsoid in meters.
|
62
|
+
@property altitudeAccuracy: Number
|
63
|
+
Accuracy of altitude in meters.
|
64
|
+
@property heading: Number
|
65
|
+
The direction of travel in degrees counting clockwise from true North.
|
66
|
+
@property speed: Number
|
67
|
+
Current velocity in meters per second.
|
68
|
+
@property timestamp: Number
|
69
|
+
The time when the position was acquired.
|
70
|
+
|
71
|
+
@miniclass ErrorEvent (Event objects)
|
72
|
+
@inherits Event
|
73
|
+
@property message: String
|
74
|
+
Error message.
|
75
|
+
@property code: Number
|
76
|
+
Error code (if applicable).
|
77
|
+
|
78
|
+
@miniclass LayerEvent (Event objects)
|
79
|
+
@inherits Event
|
80
|
+
@property layer: Layer
|
81
|
+
The layer that was added or removed.
|
82
|
+
|
83
|
+
@miniclass LayersControlEvent (Event objects)
|
84
|
+
@inherits Event
|
85
|
+
@property layer: Layer
|
86
|
+
The layer that was added or removed.
|
87
|
+
@property name: String
|
88
|
+
The name of the layer that was added or removed.
|
89
|
+
|
90
|
+
@miniclass TileEvent (Event objects)
|
91
|
+
@inherits Event
|
92
|
+
@property tile: HTMLElement
|
93
|
+
The tile element (image).
|
94
|
+
@property coords: Point
|
95
|
+
Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.
|
96
|
+
|
97
|
+
@miniclass TileErrorEvent (Event objects)
|
98
|
+
@inherits Event
|
99
|
+
@property tile: HTMLElement
|
100
|
+
The tile element (image).
|
101
|
+
@property coords: Point
|
102
|
+
Point object with the tile's `x`, `y`, and `z` (zoom level) coordinates.
|
103
|
+
@property error: *
|
104
|
+
Error passed to the tile's `done()` callback.
|
105
|
+
|
106
|
+
@miniclass ResizeEvent (Event objects)
|
107
|
+
@inherits Event
|
108
|
+
@property oldSize: Point
|
109
|
+
The old size before resize event.
|
110
|
+
@property newSize: Point
|
111
|
+
The new size after the resize event.
|
112
|
+
|
113
|
+
@miniclass GeoJSONEvent (Event objects)
|
114
|
+
@inherits Event
|
115
|
+
@property layer: Layer
|
116
|
+
The layer for the GeoJSON feature that is being added to the map.
|
117
|
+
@property properties: Object
|
118
|
+
GeoJSON properties of the feature.
|
119
|
+
@property geometryType: String
|
120
|
+
GeoJSON geometry type of the feature.
|
121
|
+
@property id: String
|
122
|
+
GeoJSON ID of the feature (if present).
|
123
|
+
|
124
|
+
@miniclass PopupEvent (Event objects)
|
125
|
+
@inherits Event
|
126
|
+
@property popup: Popup
|
127
|
+
The popup that was opened or closed.
|
128
|
+
|
129
|
+
@miniclass TooltipEvent (Event objects)
|
130
|
+
@inherits Event
|
131
|
+
@property tooltip: Tooltip
|
132
|
+
The tooltip that was opened or closed.
|
133
|
+
|
134
|
+
@miniclass DragEndEvent (Event objects)
|
135
|
+
@inherits Event
|
136
|
+
@property distance: Number
|
137
|
+
The distance in pixels the draggable element was moved by.
|
138
|
+
|
139
|
+
@miniclass ZoomAnimEvent (Event objects)
|
140
|
+
@inherits Event
|
141
|
+
@property center: LatLng; The current center of the map
|
142
|
+
@property zoom: Number; The current zoom level of the map
|
143
|
+
@property noUpdate: Boolean; Whether layers should update their contents due to this event
|