forked from magento/pwa-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (97 loc) · 3.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import DOMPurify from 'dompurify';
export const createGoogleMapApi = currentMapApi => {
return {
maps: {
Map: class Map {
constructor(element, options) {
this.element = element;
this.options = options;
const noticeContainer = document.createElement('h2');
const noticeContent = document.createTextNode(
'Google API mocked for testing'
);
noticeContainer.appendChild(noticeContent);
this.element.append(noticeContainer);
const mapInfoWindowContainer = document.createElement(
'div'
);
this.element.append(mapInfoWindowContainer);
this.infoWindowContainer = mapInfoWindowContainer;
currentMapApi.map = { element, options };
}
fitBounds(bounds) {
currentMapApi.map.bounds = bounds;
}
setCenter(center) {
currentMapApi.map.center = center;
}
setZoom(zoom) {
currentMapApi.map.zoom = zoom;
}
},
LatLng: class LatLng {
constructor(latitude, longitude) {
this.latitude = latitude;
this.longitude = longitude;
currentMapApi.latLng.push({ latitude, longitude });
}
},
Marker: class Marker {
constructor({ map, position, title }) {
this.map = map;
this.position = position;
this.title = title;
const markerElement = document.createElement('div');
markerElement.classList.add('cp-marker-element');
const markerTitle = document.createElement('h3');
const markerTitleContent = document.createTextNode(
`${this.title} (${this.position.latitude}, ${
this.position.longitude
})`
);
markerTitle.appendChild(markerTitleContent);
markerElement.appendChild(markerTitle);
this.map.element.append(markerElement);
this.element = markerElement;
currentMapApi.marker.push({
map,
position,
title
});
}
addListener(type, listener) {
this.element.addEventListener(type, listener);
}
},
InfoWindow: class InfoWindow {
constructor({ content, maxWidth }) {
this.content = content;
this.maxWidth = maxWidth;
currentMapApi.infoWindow.push({
content,
maxWidth
});
}
open(map) {
map.infoWindowContainer.style.maxWidth = this.maxWidth;
map.infoWindowContainer.innerHTML = DOMPurify.sanitize(
this.content
);
}
close() {
return false;
}
},
LatLngBounds: class LatLngBounds {
extend(position) {
return position;
}
},
event: {
clearInstanceListeners: a => {
return a;
}
}
}
};
};