Completed
Push — master ( f2c63f...720388 )
by Donata
02:09
created

src/javascript/maps-frontend.js   A

Size

Lines of Code 48

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 48
rs 10
noi 1
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A maps-frontend.js ➔ ??? 0 23 1
1
import GoogleMap from './blocks/maps/modules/GoogleMap';
2
import {createRandomId} from './blocks/maps/functions/createRandomId';
3
4
class App {
5
    constructor() {
6
        window.GoogleMap = {
7
            readyApi: false,
8
            api: document.querySelector('meta[property="maps:key"]').getAttribute('content'),
9
            instances: [],
10
            init: () => {
11
                [].forEach.call(document.querySelectorAll('*[data-module="google-map"]'), (container, index) => {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
                    let instanceId = createRandomId();
13
                    let options = container.getAttribute('data-options');
14
15
                    if (typeof options == 'undefined' || options == '') {
16
                        options = {};
17
                    } else {
18
                        options = JSON.parse(options);
19
                    }
20
21
                    window.GoogleMap.instances.push(new GoogleMap(container, Object.assign({
22
                        instanceId: instanceId
23
                    }, options)));
24
                });
25
            }
26
        };
27
    }
28
29
    init() {
30
        if (!window.GoogleMap.readyApi && (window.GoogleMap.api != '' || typeof window.GoogleMap.api != 'undefined')) {
31
            let script = document.createElement('script');
32
33
            script.type = 'text/javascript';
34
            script.src = `//maps.googleapis.com/maps/api/js?key=${window.GoogleMap.api}&libraries=places&callback=window.GoogleMap.init`;
35
36
            document.body.appendChild(script);
37
            window.GoogleMap.readyApi = true;
38
        }
39
    }
40
}
41
42
document.addEventListener("DOMContentLoaded", () => {
43
    if (!('GoogleMap' in window)) {
44
        const APP = new App();
45
46
        APP.init();
47
    }
48
});