adt-js-components 1.5.7 → 1.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Map/index.js CHANGED
@@ -71,31 +71,9 @@ async function run(options) {
71
71
  iconAnchor: [img.width / 2, img.height]
72
72
  });
73
73
  if (markers.length) {
74
- const markerPositions = [];
75
- const cluster = L.markerClusterGroup({
76
- disableClusteringAtZoom: map.getMaxZoom()
77
- });
78
- for (const marker of markers) {
79
- const mapMarker = L.marker(marker.position, {...markerOptions, id: marker.id});
80
- if (marker.callback) {
81
- mapMarker.on('click', window[marker.callback]);
82
- }
83
- if (marker.popup) {
84
- mapMarker.bindPopup(marker.popup);
85
- } else if (marker.popupCallback) {
86
- mapMarker.bindPopup(() => window[marker.popupCallback](mapMarker));
87
- }
88
- if (!marker.excludeFromBoundary) {
89
- markerPositions.push(marker.position);
90
- }
91
- cluster.addLayer(mapMarker);
92
- }
93
- if (!position.length) {
94
- map.fitBounds(markerPositions);
95
- }
96
- map.addLayer(cluster);
74
+ addMarkers(map, markers, markerOptions, position);
97
75
  } else {
98
- L.marker(position, markerOptions).addTo(map);
76
+ createMarker({id: 0, position: position}, markerOptions).addTo(map);
99
77
  }
100
78
  };
101
79
  }
@@ -136,4 +114,53 @@ async function run(options) {
136
114
  });
137
115
  }
138
116
 
117
+ function addMarkers(map, markers, options, position) {
118
+ const positionsOfMarkers = [];
119
+ const cluster = L.markerClusterGroup({
120
+ disableClusteringAtZoom: map.getMaxZoom(),
121
+ });
122
+ for (const marker of markers) {
123
+ if (marker.img) {
124
+ let markerOptions = options;
125
+ let markerImage = new Image();
126
+ markerImage.src = marker.img;
127
+ markerImage.onload = function () {
128
+ markerOptions.icon = L.icon({
129
+ iconUrl: marker.img,
130
+ iconSize: [markerImage.width, markerImage.height],
131
+ iconAnchor: [markerImage.width / 2, markerImage.height]
132
+ });
133
+ createMarker(marker, markerOptions, cluster);
134
+ };
135
+ } else {
136
+ createMarker(marker, options, cluster);
137
+ }
138
+
139
+ if (!marker.excludeFromBoundary) {
140
+ positionsOfMarkers.push(marker.position);
141
+ }
142
+ }
143
+
144
+ if (!position.length) {
145
+ map.fitBounds(positionsOfMarkers);
146
+ }
147
+ map.addLayer(cluster);
148
+ }
149
+
150
+ function createMarker(marker, options, cluster = null) {
151
+ const mapMarker = L.marker(marker.position, {...options, id: marker.id});
152
+ if (marker.callback) {
153
+ mapMarker.on('click', window[marker.callback]);
154
+ }
155
+ if (marker.popup) {
156
+ mapMarker.bindPopup(marker.popup);
157
+ } else if (marker.popupCallback) {
158
+ mapMarker.bindPopup(() => window[marker.popupCallback](mapMarker));
159
+ }
160
+ if (cluster) {
161
+ cluster.addLayer(mapMarker);
162
+ }
163
+ return mapMarker;
164
+ }
165
+
139
166
  export default { run }
@@ -52,9 +52,9 @@ function run(options, $el) {
52
52
  if (typeof Nette !== "undefined") {
53
53
  Nette.showFormErrors = function(form, errors) {
54
54
  // remove previously displayed error messages
55
- for (const error of errors) {
56
- document.getElementById('snippet-' + getErrorElementId(error.element) + '-errors').innerHTML = '';
57
- }
55
+ form.querySelectorAll('[id$="-errors"]').forEach(el => {
56
+ el.innerHTML = '';
57
+ });
58
58
 
59
59
  for (const error of errors) {
60
60
  // because radio lists and checkbox lists contains one error message multiple times