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,315 @@
|
|
1
|
+
import {Point} from '../geometry/Point';
|
2
|
+
import * as Util from '../core/Util';
|
3
|
+
import Browser from '../core/Browser';
|
4
|
+
import {addPointerListener, removePointerListener} from './DomEvent.Pointer';
|
5
|
+
import {addDoubleTapListener, removeDoubleTapListener} from './DomEvent.DoubleTap';
|
6
|
+
import {getScale} from './DomUtil';
|
7
|
+
|
8
|
+
/*
|
9
|
+
* @namespace DomEvent
|
10
|
+
* Utility functions to work with the [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Leaflet internally.
|
11
|
+
*/
|
12
|
+
|
13
|
+
// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.
|
14
|
+
|
15
|
+
// @function on(el: HTMLElement, types: String, fn: Function, context?: Object): this
|
16
|
+
// Adds a listener function (`fn`) to a particular DOM event type of the
|
17
|
+
// element `el`. You can optionally specify the context of the listener
|
18
|
+
// (object the `this` keyword will point to). You can also pass several
|
19
|
+
// space-separated types (e.g. `'click dblclick'`).
|
20
|
+
|
21
|
+
// @alternative
|
22
|
+
// @function on(el: HTMLElement, eventMap: Object, context?: Object): this
|
23
|
+
// Adds a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
24
|
+
export function on(obj, types, fn, context) {
|
25
|
+
|
26
|
+
if (types && typeof types === 'object') {
|
27
|
+
for (var type in types) {
|
28
|
+
addOne(obj, type, types[type], fn);
|
29
|
+
}
|
30
|
+
} else {
|
31
|
+
types = Util.splitWords(types);
|
32
|
+
|
33
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
34
|
+
addOne(obj, types[i], fn, context);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
41
|
+
var eventsKey = '_leaflet_events';
|
42
|
+
|
43
|
+
// @function off(el: HTMLElement, types: String, fn: Function, context?: Object): this
|
44
|
+
// Removes a previously added listener function.
|
45
|
+
// Note that if you passed a custom context to on, you must pass the same
|
46
|
+
// context to `off` in order to remove the listener.
|
47
|
+
|
48
|
+
// @alternative
|
49
|
+
// @function off(el: HTMLElement, eventMap: Object, context?: Object): this
|
50
|
+
// Removes a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
51
|
+
|
52
|
+
// @alternative
|
53
|
+
// @function off(el: HTMLElement, types: String): this
|
54
|
+
// Removes all previously added listeners of given types.
|
55
|
+
|
56
|
+
// @alternative
|
57
|
+
// @function off(el: HTMLElement): this
|
58
|
+
// Removes all previously added listeners from given HTMLElement
|
59
|
+
export function off(obj, types, fn, context) {
|
60
|
+
|
61
|
+
if (arguments.length === 1) {
|
62
|
+
batchRemove(obj);
|
63
|
+
delete obj[eventsKey];
|
64
|
+
|
65
|
+
} else if (types && typeof types === 'object') {
|
66
|
+
for (var type in types) {
|
67
|
+
removeOne(obj, type, types[type], fn);
|
68
|
+
}
|
69
|
+
|
70
|
+
} else {
|
71
|
+
types = Util.splitWords(types);
|
72
|
+
|
73
|
+
if (arguments.length === 2) {
|
74
|
+
batchRemove(obj, function (type) {
|
75
|
+
return Util.indexOf(types, type) !== -1;
|
76
|
+
});
|
77
|
+
} else {
|
78
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
79
|
+
removeOne(obj, types[i], fn, context);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
return this;
|
85
|
+
}
|
86
|
+
|
87
|
+
function batchRemove(obj, filterFn) {
|
88
|
+
for (var id in obj[eventsKey]) {
|
89
|
+
var type = id.split(/\d/)[0];
|
90
|
+
if (!filterFn || filterFn(type)) {
|
91
|
+
removeOne(obj, type, null, null, id);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
var mouseSubst = {
|
97
|
+
mouseenter: 'mouseover',
|
98
|
+
mouseleave: 'mouseout',
|
99
|
+
wheel: !('onwheel' in window) && 'mousewheel'
|
100
|
+
};
|
101
|
+
|
102
|
+
function addOne(obj, type, fn, context) {
|
103
|
+
var id = type + Util.stamp(fn) + (context ? '_' + Util.stamp(context) : '');
|
104
|
+
|
105
|
+
if (obj[eventsKey] && obj[eventsKey][id]) { return this; }
|
106
|
+
|
107
|
+
var handler = function (e) {
|
108
|
+
return fn.call(context || obj, e || window.event);
|
109
|
+
};
|
110
|
+
|
111
|
+
var originalHandler = handler;
|
112
|
+
|
113
|
+
if (!Browser.touchNative && Browser.pointer && type.indexOf('touch') === 0) {
|
114
|
+
// Needs DomEvent.Pointer.js
|
115
|
+
handler = addPointerListener(obj, type, handler);
|
116
|
+
|
117
|
+
} else if (Browser.touch && (type === 'dblclick')) {
|
118
|
+
handler = addDoubleTapListener(obj, handler);
|
119
|
+
|
120
|
+
} else if ('addEventListener' in obj) {
|
121
|
+
|
122
|
+
if (type === 'touchstart' || type === 'touchmove' || type === 'wheel' || type === 'mousewheel') {
|
123
|
+
obj.addEventListener(mouseSubst[type] || type, handler, Browser.passiveEvents ? {passive: false} : false);
|
124
|
+
|
125
|
+
} else if (type === 'mouseenter' || type === 'mouseleave') {
|
126
|
+
handler = function (e) {
|
127
|
+
e = e || window.event;
|
128
|
+
if (isExternalTarget(obj, e)) {
|
129
|
+
originalHandler(e);
|
130
|
+
}
|
131
|
+
};
|
132
|
+
obj.addEventListener(mouseSubst[type], handler, false);
|
133
|
+
|
134
|
+
} else {
|
135
|
+
obj.addEventListener(type, originalHandler, false);
|
136
|
+
}
|
137
|
+
|
138
|
+
} else {
|
139
|
+
obj.attachEvent('on' + type, handler);
|
140
|
+
}
|
141
|
+
|
142
|
+
obj[eventsKey] = obj[eventsKey] || {};
|
143
|
+
obj[eventsKey][id] = handler;
|
144
|
+
}
|
145
|
+
|
146
|
+
function removeOne(obj, type, fn, context, id) {
|
147
|
+
id = id || type + Util.stamp(fn) + (context ? '_' + Util.stamp(context) : '');
|
148
|
+
var handler = obj[eventsKey] && obj[eventsKey][id];
|
149
|
+
|
150
|
+
if (!handler) { return this; }
|
151
|
+
|
152
|
+
if (!Browser.touchNative && Browser.pointer && type.indexOf('touch') === 0) {
|
153
|
+
removePointerListener(obj, type, handler);
|
154
|
+
|
155
|
+
} else if (Browser.touch && (type === 'dblclick')) {
|
156
|
+
removeDoubleTapListener(obj, handler);
|
157
|
+
|
158
|
+
} else if ('removeEventListener' in obj) {
|
159
|
+
|
160
|
+
obj.removeEventListener(mouseSubst[type] || type, handler, false);
|
161
|
+
|
162
|
+
} else {
|
163
|
+
obj.detachEvent('on' + type, handler);
|
164
|
+
}
|
165
|
+
|
166
|
+
obj[eventsKey][id] = null;
|
167
|
+
}
|
168
|
+
|
169
|
+
// @function stopPropagation(ev: DOMEvent): this
|
170
|
+
// Stop the given event from propagation to parent elements. Used inside the listener functions:
|
171
|
+
// ```js
|
172
|
+
// L.DomEvent.on(div, 'click', function (ev) {
|
173
|
+
// L.DomEvent.stopPropagation(ev);
|
174
|
+
// });
|
175
|
+
// ```
|
176
|
+
export function stopPropagation(e) {
|
177
|
+
|
178
|
+
if (e.stopPropagation) {
|
179
|
+
e.stopPropagation();
|
180
|
+
} else if (e.originalEvent) { // In case of Leaflet event.
|
181
|
+
e.originalEvent._stopped = true;
|
182
|
+
} else {
|
183
|
+
e.cancelBubble = true;
|
184
|
+
}
|
185
|
+
|
186
|
+
return this;
|
187
|
+
}
|
188
|
+
|
189
|
+
// @function disableScrollPropagation(el: HTMLElement): this
|
190
|
+
// Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).
|
191
|
+
export function disableScrollPropagation(el) {
|
192
|
+
addOne(el, 'wheel', stopPropagation);
|
193
|
+
return this;
|
194
|
+
}
|
195
|
+
|
196
|
+
// @function disableClickPropagation(el: HTMLElement): this
|
197
|
+
// Adds `stopPropagation` to the element's `'click'`, `'dblclick'`, `'contextmenu'`,
|
198
|
+
// `'mousedown'` and `'touchstart'` events (plus browser variants).
|
199
|
+
export function disableClickPropagation(el) {
|
200
|
+
on(el, 'mousedown touchstart dblclick contextmenu', stopPropagation);
|
201
|
+
el['_leaflet_disable_click'] = true;
|
202
|
+
return this;
|
203
|
+
}
|
204
|
+
|
205
|
+
// @function preventDefault(ev: DOMEvent): this
|
206
|
+
// Prevents the default action of the DOM Event `ev` from happening (such as
|
207
|
+
// following a link in the href of the a element, or doing a POST request
|
208
|
+
// with page reload when a `<form>` is submitted).
|
209
|
+
// Use it inside listener functions.
|
210
|
+
export function preventDefault(e) {
|
211
|
+
if (e.preventDefault) {
|
212
|
+
e.preventDefault();
|
213
|
+
} else {
|
214
|
+
e.returnValue = false;
|
215
|
+
}
|
216
|
+
return this;
|
217
|
+
}
|
218
|
+
|
219
|
+
// @function stop(ev: DOMEvent): this
|
220
|
+
// Does `stopPropagation` and `preventDefault` at the same time.
|
221
|
+
export function stop(e) {
|
222
|
+
preventDefault(e);
|
223
|
+
stopPropagation(e);
|
224
|
+
return this;
|
225
|
+
}
|
226
|
+
|
227
|
+
// @function getPropagationPath(ev: DOMEvent): Array
|
228
|
+
// Compatibility polyfill for [`Event.composedPath()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath).
|
229
|
+
// Returns an array containing the `HTMLElement`s that the given DOM event
|
230
|
+
// should propagate to (if not stopped).
|
231
|
+
export function getPropagationPath(ev) {
|
232
|
+
if (ev.composedPath) {
|
233
|
+
return ev.composedPath();
|
234
|
+
}
|
235
|
+
|
236
|
+
var path = [];
|
237
|
+
var el = ev.target;
|
238
|
+
|
239
|
+
while (el) {
|
240
|
+
path.push(el);
|
241
|
+
el = el.parentNode;
|
242
|
+
}
|
243
|
+
return path;
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
// @function getMousePosition(ev: DOMEvent, container?: HTMLElement): Point
|
248
|
+
// Gets normalized mouse position from a DOM event relative to the
|
249
|
+
// `container` (border excluded) or to the whole page if not specified.
|
250
|
+
export function getMousePosition(e, container) {
|
251
|
+
if (!container) {
|
252
|
+
return new Point(e.clientX, e.clientY);
|
253
|
+
}
|
254
|
+
|
255
|
+
var scale = getScale(container),
|
256
|
+
offset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)
|
257
|
+
|
258
|
+
return new Point(
|
259
|
+
// offset.left/top values are in page scale (like clientX/Y),
|
260
|
+
// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).
|
261
|
+
(e.clientX - offset.left) / scale.x - container.clientLeft,
|
262
|
+
(e.clientY - offset.top) / scale.y - container.clientTop
|
263
|
+
);
|
264
|
+
}
|
265
|
+
|
266
|
+
|
267
|
+
// except , Safari and
|
268
|
+
// We need double the scroll pixels (see #7403 and #4538) for all Browsers
|
269
|
+
// except OSX (Mac) -> 3x, Chrome running on Linux 1x
|
270
|
+
|
271
|
+
var wheelPxFactor =
|
272
|
+
(Browser.linux && Browser.chrome) ? window.devicePixelRatio :
|
273
|
+
Browser.mac ? window.devicePixelRatio * 3 :
|
274
|
+
window.devicePixelRatio > 0 ? 2 * window.devicePixelRatio : 1;
|
275
|
+
// @function getWheelDelta(ev: DOMEvent): Number
|
276
|
+
// Gets normalized wheel delta from a wheel DOM event, in vertical
|
277
|
+
// pixels scrolled (negative if scrolling down).
|
278
|
+
// Events from pointing devices without precise scrolling are mapped to
|
279
|
+
// a best guess of 60 pixels.
|
280
|
+
export function getWheelDelta(e) {
|
281
|
+
return (Browser.edge) ? e.wheelDeltaY / 2 : // Don't trust window-geometry-based delta
|
282
|
+
(e.deltaY && e.deltaMode === 0) ? -e.deltaY / wheelPxFactor : // Pixels
|
283
|
+
(e.deltaY && e.deltaMode === 1) ? -e.deltaY * 20 : // Lines
|
284
|
+
(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : // Pages
|
285
|
+
(e.deltaX || e.deltaZ) ? 0 : // Skip horizontal/depth wheel events
|
286
|
+
e.wheelDelta ? (e.wheelDeltaY || e.wheelDelta) / 2 : // Legacy IE pixels
|
287
|
+
(e.detail && Math.abs(e.detail) < 32765) ? -e.detail * 20 : // Legacy Moz lines
|
288
|
+
e.detail ? e.detail / -32765 * 60 : // Legacy Moz pages
|
289
|
+
0;
|
290
|
+
}
|
291
|
+
|
292
|
+
// check if element really left/entered the event target (for mouseenter/mouseleave)
|
293
|
+
export function isExternalTarget(el, e) {
|
294
|
+
|
295
|
+
var related = e.relatedTarget;
|
296
|
+
|
297
|
+
if (!related) { return true; }
|
298
|
+
|
299
|
+
try {
|
300
|
+
while (related && (related !== el)) {
|
301
|
+
related = related.parentNode;
|
302
|
+
}
|
303
|
+
} catch (err) {
|
304
|
+
return false;
|
305
|
+
}
|
306
|
+
return (related !== el);
|
307
|
+
}
|
308
|
+
|
309
|
+
// @function addListener(…): this
|
310
|
+
// Alias to [`L.DomEvent.on`](#domevent-on)
|
311
|
+
export {on as addListener};
|
312
|
+
|
313
|
+
// @function removeListener(…): this
|
314
|
+
// Alias to [`L.DomEvent.off`](#domevent-off)
|
315
|
+
export {off as removeListener};
|
@@ -0,0 +1,349 @@
|
|
1
|
+
import * as DomEvent from './DomEvent';
|
2
|
+
import * as Util from '../core/Util';
|
3
|
+
import {Point} from '../geometry/Point';
|
4
|
+
import Browser from '../core/Browser';
|
5
|
+
|
6
|
+
/*
|
7
|
+
* @namespace DomUtil
|
8
|
+
*
|
9
|
+
* Utility functions to work with the [DOM](https://developer.mozilla.org/docs/Web/API/Document_Object_Model)
|
10
|
+
* tree, used by Leaflet internally.
|
11
|
+
*
|
12
|
+
* Most functions expecting or returning a `HTMLElement` also work for
|
13
|
+
* SVG elements. The only difference is that classes refer to CSS classes
|
14
|
+
* in HTML and SVG classes in SVG.
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
// @property TRANSFORM: String
|
19
|
+
// Vendor-prefixed transform style name (e.g. `'webkitTransform'` for WebKit).
|
20
|
+
export var TRANSFORM = testProp(
|
21
|
+
['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
|
22
|
+
|
23
|
+
// webkitTransition comes first because some browser versions that drop vendor prefix don't do
|
24
|
+
// the same for the transitionend event, in particular the Android 4.1 stock browser
|
25
|
+
|
26
|
+
// @property TRANSITION: String
|
27
|
+
// Vendor-prefixed transition style name.
|
28
|
+
export var TRANSITION = testProp(
|
29
|
+
['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']);
|
30
|
+
|
31
|
+
// @property TRANSITION_END: String
|
32
|
+
// Vendor-prefixed transitionend event name.
|
33
|
+
export var TRANSITION_END =
|
34
|
+
TRANSITION === 'webkitTransition' || TRANSITION === 'OTransition' ? TRANSITION + 'End' : 'transitionend';
|
35
|
+
|
36
|
+
|
37
|
+
// @function get(id: String|HTMLElement): HTMLElement
|
38
|
+
// Returns an element given its DOM id, or returns the element itself
|
39
|
+
// if it was passed directly.
|
40
|
+
export function get(id) {
|
41
|
+
return typeof id === 'string' ? document.getElementById(id) : id;
|
42
|
+
}
|
43
|
+
|
44
|
+
// @function getStyle(el: HTMLElement, styleAttrib: String): String
|
45
|
+
// Returns the value for a certain style attribute on an element,
|
46
|
+
// including computed values or values set through CSS.
|
47
|
+
export function getStyle(el, style) {
|
48
|
+
var value = el.style[style] || (el.currentStyle && el.currentStyle[style]);
|
49
|
+
|
50
|
+
if ((!value || value === 'auto') && document.defaultView) {
|
51
|
+
var css = document.defaultView.getComputedStyle(el, null);
|
52
|
+
value = css ? css[style] : null;
|
53
|
+
}
|
54
|
+
return value === 'auto' ? null : value;
|
55
|
+
}
|
56
|
+
|
57
|
+
// @function create(tagName: String, className?: String, container?: HTMLElement): HTMLElement
|
58
|
+
// Creates an HTML element with `tagName`, sets its class to `className`, and optionally appends it to `container` element.
|
59
|
+
export function create(tagName, className, container) {
|
60
|
+
var el = document.createElement(tagName);
|
61
|
+
el.className = className || '';
|
62
|
+
|
63
|
+
if (container) {
|
64
|
+
container.appendChild(el);
|
65
|
+
}
|
66
|
+
return el;
|
67
|
+
}
|
68
|
+
|
69
|
+
// @function remove(el: HTMLElement)
|
70
|
+
// Removes `el` from its parent element
|
71
|
+
export function remove(el) {
|
72
|
+
var parent = el.parentNode;
|
73
|
+
if (parent) {
|
74
|
+
parent.removeChild(el);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
// @function empty(el: HTMLElement)
|
79
|
+
// Removes all of `el`'s children elements from `el`
|
80
|
+
export function empty(el) {
|
81
|
+
while (el.firstChild) {
|
82
|
+
el.removeChild(el.firstChild);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// @function toFront(el: HTMLElement)
|
87
|
+
// Makes `el` the last child of its parent, so it renders in front of the other children.
|
88
|
+
export function toFront(el) {
|
89
|
+
var parent = el.parentNode;
|
90
|
+
if (parent && parent.lastChild !== el) {
|
91
|
+
parent.appendChild(el);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
// @function toBack(el: HTMLElement)
|
96
|
+
// Makes `el` the first child of its parent, so it renders behind the other children.
|
97
|
+
export function toBack(el) {
|
98
|
+
var parent = el.parentNode;
|
99
|
+
if (parent && parent.firstChild !== el) {
|
100
|
+
parent.insertBefore(el, parent.firstChild);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
// @function hasClass(el: HTMLElement, name: String): Boolean
|
105
|
+
// Returns `true` if the element's class attribute contains `name`.
|
106
|
+
export function hasClass(el, name) {
|
107
|
+
if (el.classList !== undefined) {
|
108
|
+
return el.classList.contains(name);
|
109
|
+
}
|
110
|
+
var className = getClass(el);
|
111
|
+
return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
|
112
|
+
}
|
113
|
+
|
114
|
+
// @function addClass(el: HTMLElement, name: String)
|
115
|
+
// Adds `name` to the element's class attribute.
|
116
|
+
export function addClass(el, name) {
|
117
|
+
if (el.classList !== undefined) {
|
118
|
+
var classes = Util.splitWords(name);
|
119
|
+
for (var i = 0, len = classes.length; i < len; i++) {
|
120
|
+
el.classList.add(classes[i]);
|
121
|
+
}
|
122
|
+
} else if (!hasClass(el, name)) {
|
123
|
+
var className = getClass(el);
|
124
|
+
setClass(el, (className ? className + ' ' : '') + name);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
// @function removeClass(el: HTMLElement, name: String)
|
129
|
+
// Removes `name` from the element's class attribute.
|
130
|
+
export function removeClass(el, name) {
|
131
|
+
if (el.classList !== undefined) {
|
132
|
+
el.classList.remove(name);
|
133
|
+
} else {
|
134
|
+
setClass(el, Util.trim((' ' + getClass(el) + ' ').replace(' ' + name + ' ', ' ')));
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
// @function setClass(el: HTMLElement, name: String)
|
139
|
+
// Sets the element's class.
|
140
|
+
export function setClass(el, name) {
|
141
|
+
if (el.className.baseVal === undefined) {
|
142
|
+
el.className = name;
|
143
|
+
} else {
|
144
|
+
// in case of SVG element
|
145
|
+
el.className.baseVal = name;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
// @function getClass(el: HTMLElement): String
|
150
|
+
// Returns the element's class.
|
151
|
+
export function getClass(el) {
|
152
|
+
// Check if the element is an SVGElementInstance and use the correspondingElement instead
|
153
|
+
// (Required for linked SVG elements in IE11.)
|
154
|
+
if (el.correspondingElement) {
|
155
|
+
el = el.correspondingElement;
|
156
|
+
}
|
157
|
+
return el.className.baseVal === undefined ? el.className : el.className.baseVal;
|
158
|
+
}
|
159
|
+
|
160
|
+
// @function setOpacity(el: HTMLElement, opacity: Number)
|
161
|
+
// Set the opacity of an element (including old IE support).
|
162
|
+
// `opacity` must be a number from `0` to `1`.
|
163
|
+
export function setOpacity(el, value) {
|
164
|
+
if ('opacity' in el.style) {
|
165
|
+
el.style.opacity = value;
|
166
|
+
} else if ('filter' in el.style) {
|
167
|
+
_setOpacityIE(el, value);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
function _setOpacityIE(el, value) {
|
172
|
+
var filter = false,
|
173
|
+
filterName = 'DXImageTransform.Microsoft.Alpha';
|
174
|
+
|
175
|
+
// filters collection throws an error if we try to retrieve a filter that doesn't exist
|
176
|
+
try {
|
177
|
+
filter = el.filters.item(filterName);
|
178
|
+
} catch (e) {
|
179
|
+
// don't set opacity to 1 if we haven't already set an opacity,
|
180
|
+
// it isn't needed and breaks transparent pngs.
|
181
|
+
if (value === 1) { return; }
|
182
|
+
}
|
183
|
+
|
184
|
+
value = Math.round(value * 100);
|
185
|
+
|
186
|
+
if (filter) {
|
187
|
+
filter.Enabled = (value !== 100);
|
188
|
+
filter.Opacity = value;
|
189
|
+
} else {
|
190
|
+
el.style.filter += ' progid:' + filterName + '(opacity=' + value + ')';
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
// @function testProp(props: String[]): String|false
|
195
|
+
// Goes through the array of style names and returns the first name
|
196
|
+
// that is a valid style name for an element. If no such name is found,
|
197
|
+
// it returns false. Useful for vendor-prefixed styles like `transform`.
|
198
|
+
export function testProp(props) {
|
199
|
+
var style = document.documentElement.style;
|
200
|
+
|
201
|
+
for (var i = 0; i < props.length; i++) {
|
202
|
+
if (props[i] in style) {
|
203
|
+
return props[i];
|
204
|
+
}
|
205
|
+
}
|
206
|
+
return false;
|
207
|
+
}
|
208
|
+
|
209
|
+
// @function setTransform(el: HTMLElement, offset: Point, scale?: Number)
|
210
|
+
// Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
|
211
|
+
// and optionally scaled by `scale`. Does not have an effect if the
|
212
|
+
// browser doesn't support 3D CSS transforms.
|
213
|
+
export function setTransform(el, offset, scale) {
|
214
|
+
var pos = offset || new Point(0, 0);
|
215
|
+
|
216
|
+
el.style[TRANSFORM] =
|
217
|
+
(Browser.ie3d ?
|
218
|
+
'translate(' + pos.x + 'px,' + pos.y + 'px)' :
|
219
|
+
'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') +
|
220
|
+
(scale ? ' scale(' + scale + ')' : '');
|
221
|
+
}
|
222
|
+
|
223
|
+
// @function setPosition(el: HTMLElement, position: Point)
|
224
|
+
// Sets the position of `el` to coordinates specified by `position`,
|
225
|
+
// using CSS translate or top/left positioning depending on the browser
|
226
|
+
// (used by Leaflet internally to position its layers).
|
227
|
+
export function setPosition(el, point) {
|
228
|
+
|
229
|
+
/*eslint-disable */
|
230
|
+
el._leaflet_pos = point;
|
231
|
+
/* eslint-enable */
|
232
|
+
|
233
|
+
if (Browser.any3d) {
|
234
|
+
setTransform(el, point);
|
235
|
+
} else {
|
236
|
+
el.style.left = point.x + 'px';
|
237
|
+
el.style.top = point.y + 'px';
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
// @function getPosition(el: HTMLElement): Point
|
242
|
+
// Returns the coordinates of an element previously positioned with setPosition.
|
243
|
+
export function getPosition(el) {
|
244
|
+
// this method is only used for elements previously positioned using setPosition,
|
245
|
+
// so it's safe to cache the position for performance
|
246
|
+
|
247
|
+
return el._leaflet_pos || new Point(0, 0);
|
248
|
+
}
|
249
|
+
|
250
|
+
// @function disableTextSelection()
|
251
|
+
// Prevents the user from generating `selectstart` DOM events, usually generated
|
252
|
+
// when the user drags the mouse through a page with text. Used internally
|
253
|
+
// by Leaflet to override the behaviour of any click-and-drag interaction on
|
254
|
+
// the map. Affects drag interactions on the whole document.
|
255
|
+
|
256
|
+
// @function enableTextSelection()
|
257
|
+
// Cancels the effects of a previous [`L.DomUtil.disableTextSelection`](#domutil-disabletextselection).
|
258
|
+
export var disableTextSelection;
|
259
|
+
export var enableTextSelection;
|
260
|
+
var _userSelect;
|
261
|
+
if ('onselectstart' in document) {
|
262
|
+
disableTextSelection = function () {
|
263
|
+
DomEvent.on(window, 'selectstart', DomEvent.preventDefault);
|
264
|
+
};
|
265
|
+
enableTextSelection = function () {
|
266
|
+
DomEvent.off(window, 'selectstart', DomEvent.preventDefault);
|
267
|
+
};
|
268
|
+
} else {
|
269
|
+
var userSelectProperty = testProp(
|
270
|
+
['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']);
|
271
|
+
|
272
|
+
disableTextSelection = function () {
|
273
|
+
if (userSelectProperty) {
|
274
|
+
var style = document.documentElement.style;
|
275
|
+
_userSelect = style[userSelectProperty];
|
276
|
+
style[userSelectProperty] = 'none';
|
277
|
+
}
|
278
|
+
};
|
279
|
+
enableTextSelection = function () {
|
280
|
+
if (userSelectProperty) {
|
281
|
+
document.documentElement.style[userSelectProperty] = _userSelect;
|
282
|
+
_userSelect = undefined;
|
283
|
+
}
|
284
|
+
};
|
285
|
+
}
|
286
|
+
|
287
|
+
// @function disableImageDrag()
|
288
|
+
// As [`L.DomUtil.disableTextSelection`](#domutil-disabletextselection), but
|
289
|
+
// for `dragstart` DOM events, usually generated when the user drags an image.
|
290
|
+
export function disableImageDrag() {
|
291
|
+
DomEvent.on(window, 'dragstart', DomEvent.preventDefault);
|
292
|
+
}
|
293
|
+
|
294
|
+
// @function enableImageDrag()
|
295
|
+
// Cancels the effects of a previous [`L.DomUtil.disableImageDrag`](#domutil-disabletextselection).
|
296
|
+
export function enableImageDrag() {
|
297
|
+
DomEvent.off(window, 'dragstart', DomEvent.preventDefault);
|
298
|
+
}
|
299
|
+
|
300
|
+
var _outlineElement, _outlineStyle;
|
301
|
+
// @function preventOutline(el: HTMLElement)
|
302
|
+
// Makes the [outline](https://developer.mozilla.org/docs/Web/CSS/outline)
|
303
|
+
// of the element `el` invisible. Used internally by Leaflet to prevent
|
304
|
+
// focusable elements from displaying an outline when the user performs a
|
305
|
+
// drag interaction on them.
|
306
|
+
export function preventOutline(element) {
|
307
|
+
while (element.tabIndex === -1) {
|
308
|
+
element = element.parentNode;
|
309
|
+
}
|
310
|
+
if (!element.style) { return; }
|
311
|
+
restoreOutline();
|
312
|
+
_outlineElement = element;
|
313
|
+
_outlineStyle = element.style.outlineStyle;
|
314
|
+
element.style.outlineStyle = 'none';
|
315
|
+
DomEvent.on(window, 'keydown', restoreOutline);
|
316
|
+
}
|
317
|
+
|
318
|
+
// @function restoreOutline()
|
319
|
+
// Cancels the effects of a previous [`L.DomUtil.preventOutline`]().
|
320
|
+
export function restoreOutline() {
|
321
|
+
if (!_outlineElement) { return; }
|
322
|
+
_outlineElement.style.outlineStyle = _outlineStyle;
|
323
|
+
_outlineElement = undefined;
|
324
|
+
_outlineStyle = undefined;
|
325
|
+
DomEvent.off(window, 'keydown', restoreOutline);
|
326
|
+
}
|
327
|
+
|
328
|
+
// @function getSizedParentNode(el: HTMLElement): HTMLElement
|
329
|
+
// Finds the closest parent node which size (width and height) is not null.
|
330
|
+
export function getSizedParentNode(element) {
|
331
|
+
do {
|
332
|
+
element = element.parentNode;
|
333
|
+
} while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body);
|
334
|
+
return element;
|
335
|
+
}
|
336
|
+
|
337
|
+
// @function getScale(el: HTMLElement): Object
|
338
|
+
// Computes the CSS scale currently applied on the element.
|
339
|
+
// Returns an object with `x` and `y` members as horizontal and vertical scales respectively,
|
340
|
+
// and `boundingClientRect` as the result of [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
|
341
|
+
export function getScale(element) {
|
342
|
+
var rect = element.getBoundingClientRect(); // Read-only in old browsers.
|
343
|
+
|
344
|
+
return {
|
345
|
+
x: rect.width / element.offsetWidth || 1,
|
346
|
+
y: rect.height / element.offsetHeight || 1,
|
347
|
+
boundingClientRect: rect
|
348
|
+
};
|
349
|
+
}
|