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

src/javascript/maps-backend.js   A

Complexity

Total Complexity 11
Complexity/F 1.22

Size

Lines of Code 79
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 11
nc 1
mnd 2
bc 12
fnc 9
dl 0
loc 79
rs 10
bpm 1.3333
cpm 1.2222
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B 0 77 1
A $.entwine(ꞌssꞌ) 0 75 1
1
import GoogleMapEditor from './blocks/maps/modules/GoogleMapEditor';
2
3
(function ($) {
4
    $.entwine('ss', function ($) {
5
        $('*[data-module="editor"]').entwine({
6
            onmatch: function () {
7
8
                window.editor = {
9
                    readyApi: false,
10
                    instance: null,
11
                    api: $(this).data('key'),
12
                    init: () => {
13
                        window.editor.instance = new GoogleMapEditor($(this)[0], {
14
                            closures: {
15
                                onMarkerPlaced: (instance, marker) => {
16
                                    $.ajax({
17
                                        url: $(this).data('update-marker-link'),
18
                                        method: 'GET',
19
                                        data: marker.getData()
20
                                    })
21
                                },
22
                                onMarkerSave: (instance, marker) => {
23
                                    $.ajax({
24
                                        url: $(this).data('update-marker-link'),
25
                                        method: 'GET',
26
                                        data: marker.getData()
27
                                    })
28
                                },
29
                                onMarkerDelete: (instance, marker) => {
30
                                    $.ajax({
31
                                        url: $(this).data('delete-marker-link'),
32
                                        method: 'GET',
33
                                        data: {
34
                                            InstanceId: marker.options.instanceId
35
                                        }
36
                                    })
37
                                },
38
                                onZoomChanged: (instance, zoomLevel) => {
39
                                    $.ajax({
40
                                        url: $(this).data('zoom-changed-link'),
41
                                        method: 'GET',
42
                                        data: {
43
                                            zoom: zoomLevel
44
                                        }
45
                                    })
46
                                },
47
                                onCoordinatesChanged: (instance, coordinates) => {
48
                                    $.ajax({
49
                                        url: $(this).data('coordinates-changed-link'),
50
                                        method: 'GET',
51
                                        data: {
52
                                            coordinates: coordinates
53
                                        }
54
                                    })
55
                                }
56
                            }
57
                        });
58
                    }
59
                };
60
61
                if (!window.editor.readyApi) {
62
                    if ($('#google-maps-api').length <= 0) {
63
                        let script = document.createElement('script');
64
65
                        script.id = 'google-maps-api';
66
                        script.type = 'text/javascript';
67
                        script.src = `//maps.googleapis.com/maps/api/js?key=${window.editor.api}&libraries=places&callback=window.editor.init`;
68
69
                        document.body.appendChild(script);
70
                        window.editor.readyApi = true;
71
                    } else {
72
                        window.editor.readyApi = true;
73
                        window.editor.init();
74
                    }
75
                }
76
            }
77
        });
78
    });
79
})(jQuery);