Completed
Push — master ( b3a018...2e1a6c )
by Simon
01:30
created

googlemapsfield.js ➔ ... ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 9.4285
1
const targets = Array.from(document.body.querySelectorAll('input[data-mapsfield=mapsfield]'));
2
const latField = document.getElementById('GoogleMapsLatField');
3
const lngField = document.getElementById('GoogleMapsLngField');
4
5
let options = {};
6
let autoComplete;
7
8
const fillAddress = () => {
9
  const location = autoComplete.getPlace();
10
  const components = location.address_components;
11
12
  latField.setAttribute('value', location.geometry.location.lat());
13
  lngField.setAttribute('value', location.geometry.location.lng());
14
15
  components.forEach((component) => {
16
    component.types.forEach((type) => {
17
      const field = document.getElementById(type);
18
      if (field) {
19
        field.setAttribute('value', component.long_name);
20
      }
21
    });
22
  });
23
};
24
25
const mountMapsField = (mapsfield) => {
26
  options = Object.assign(options, window.customisations);
27
  autoComplete = new google.maps.places.Autocomplete(mapsfield, options);
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
28
  autoComplete.addListener('place_changed', fillAddress);
29
};
30
31
export default function() {
32
  targets.forEach(mountMapsField);
33
}