wonder-image 1.2.0 → 1.2.2

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.
@@ -0,0 +1,174 @@
1
+ function placeNeedCheck(input) {
2
+
3
+ inputError(input, 'Indirizzo non valido');
4
+
5
+ }
6
+
7
+ function checkInputPlace(input, autocomplete) {
8
+
9
+ var inputContainer = input.parentElement;
10
+
11
+ var country = inputContainer.querySelector('[data-wi-spi="country"]');
12
+ var province = inputContainer.querySelector('[data-wi-spi="province"]');
13
+ var cap = inputContainer.querySelector('[data-wi-spi="cap"]');
14
+ var city = inputContainer.querySelector('[data-wi-spi="city"]');
15
+ var street = inputContainer.querySelector('[data-wi-spi="street"]');
16
+ var number = inputContainer.querySelector('[data-wi-spi="number"]');
17
+
18
+ country.value = "";
19
+ province.value = "";
20
+ cap.value = "";
21
+ city.value = "";
22
+ street.value = "";
23
+ number.value = "";
24
+
25
+ removeInputError(input);
26
+
27
+ if (autocomplete.getPlace()) {
28
+
29
+ var place = autocomplete.getPlace();
30
+
31
+ for (const component of place.address_components) {
32
+
33
+ const componentType = component.types[0];
34
+
35
+ switch (componentType) {
36
+
37
+ case "street_number": { number.value = component.long_name; break; }
38
+ case "route": { street.value = component.short_name; break; }
39
+ case "administrative_area_level_3": { city.value = component.short_name; break; }
40
+ case "postal_code": { cap.value = component.short_name; break; }
41
+ case "administrative_area_level_2": { province.value = component.short_name; break; }
42
+ case "country": { country.value = component.short_name; break; }
43
+
44
+ }
45
+
46
+ }
47
+
48
+ if (country.value == "" || province.value == "" || cap.value == "" || city.value == "" || street.value == "" || number.value == "") {
49
+
50
+ var error = "Indirizzo non valido";
51
+
52
+ if (country.value == "") {
53
+ error += ", manca il paese";
54
+ } else if (province.value == "") {
55
+ error += ", manca la provincia";
56
+ } else if (cap.value == "") {
57
+ error += ", manca il cap";
58
+ } else if (city.value == "") {
59
+ error += ", manca la città";
60
+ } else if (street.value == "") {
61
+ error += ", manca la via";
62
+ } else if (number.value == "") {
63
+ error += ", manca il numero civico";
64
+ }
65
+
66
+ inputError(input, error);
67
+
68
+ }
69
+
70
+ } else {
71
+
72
+ inputError(input, 'Indirizzo non valido');
73
+
74
+ }
75
+
76
+ check();
77
+
78
+ }
79
+
80
+ function setPlace(input, country = null, province = null, cap = null, city = null, street = null, number = null) {
81
+
82
+ var inputContainer = input.parentElement;
83
+
84
+ var countryInput = inputContainer.querySelector('[data-wi-spi="country"]');
85
+ var provinceInput = inputContainer.querySelector('[data-wi-spi="province"]');
86
+ var capInput = inputContainer.querySelector('[data-wi-spi="cap"]');
87
+ var cityInput = inputContainer.querySelector('[data-wi-spi="city"]');
88
+ var streetInput = inputContainer.querySelector('[data-wi-spi="street"]');
89
+ var numberInput = inputContainer.querySelector('[data-wi-spi="number"]');
90
+
91
+ if (country == null) {
92
+
93
+ country = countryInput.value;
94
+ province = provinceInput.value;
95
+ cap = capInput.value;
96
+ city = cityInput.value;
97
+ street = streetInput.value;
98
+ number = numberInput.value;
99
+
100
+ } else {
101
+
102
+ countryInput.value = country;
103
+ provinceInput.value = province;
104
+ capInput.value = cap;
105
+ cityInput.value = city;
106
+ streetInput.value = street;
107
+ numberInput.value = number;
108
+
109
+ }
110
+
111
+ if (country != "" || province != "" || cap != "" || city != "" || street != "" || number != "") {
112
+
113
+ var address = street+', '+number+', '+city+', '+province+', '+country;
114
+ input.value = address;
115
+
116
+ checkLabel();
117
+ check();
118
+
119
+ }
120
+
121
+ }
122
+
123
+ function setGoogleMapsPlace() {
124
+
125
+ document.querySelectorAll("[data-wi-search-place='true']").forEach(input => {
126
+
127
+ input.disabled = false;
128
+
129
+ var restrictions = JSON.parse(input.dataset.wiRestriction);
130
+
131
+ var options = {};
132
+
133
+ if (input.dataset.wiRestriction != '[]') {
134
+
135
+ var restrictions = JSON.parse(input.dataset.wiRestriction);
136
+ options.componentRestrictions = restrictions;
137
+
138
+ }
139
+
140
+ options.fields = [ "address_components" ];
141
+ options.types = [ "address" ];
142
+
143
+ var googlePlace = new google.maps.places.Autocomplete(input, options);
144
+
145
+ input.addEventListener("change", () => { placeNeedCheck(input); });
146
+ googlePlace.addListener("place_changed", () => { checkInputPlace(input, googlePlace); });
147
+
148
+ });
149
+
150
+ }
151
+
152
+ function setGoogleMapsApi() {
153
+
154
+ if (document.querySelector("[data-wi-search-place]")) {
155
+
156
+ var GOOGLE_API_KEY = "AIzaSyAhBslKzmgy6pRrLGyhlN34pN1yQYE1hvI";
157
+
158
+ /**
159
+ *
160
+ * Se ci sono degli input Place chiama le API di Google Place
161
+ * Documentazione: https://developers.google.com/maps/documentation/javascript/place-autocomplete?hl=it
162
+ *
163
+ */
164
+
165
+ var script = document.createElement('script');
166
+ script.type = 'text/javascript';
167
+ script.async = true;
168
+ script.src = 'https://maps.googleapis.com/maps/api/js?key='+GOOGLE_API_KEY+'&loading=async&libraries=places&callback=setGoogleMapsPlace';
169
+
170
+ document.head.appendChild(script);
171
+
172
+ }
173
+
174
+ }
@@ -4,6 +4,7 @@ import 'script-loader!/src/build/frontend/js/header.js';
4
4
  import 'script-loader!/src/build/frontend/js/alert.js';
5
5
  import 'script-loader!/src/build/frontend/js/dropdown.js';
6
6
  import 'script-loader!/src/build/frontend/js/modal.js';
7
+ import 'script-loader!/src/build/frontend/js/form/place.js';
7
8
  import 'script-loader!/src/build/frontend/js/form/select.js';
8
9
  import 'script-loader!/src/build/frontend/js/form/send.js';
9
10
  import 'script-loader!/src/build/frontend/js/pageSetUp.js';
@@ -39,4 +39,5 @@ import '/src/build/frontend/css/components/spinner.css';
39
39
  import '/src/build/frontend/css/components/form/input.css';
40
40
  import '/src/build/frontend/css/components/form/date.css';
41
41
  import '/src/build/frontend/css/components/form/checkbox.css';
42
+ import '/src/build/frontend/css/components/form/place.css';
42
43
  import '/src/build/frontend/css/components/form/select.css';