web/js/partials/location.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 2.25

Size

Lines of Code 47
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 33
dl 0
loc 47
rs 10
c 2
b 0
f 0
cc 0
nc 2
mnd 2
bc 10
fnc 4
bpm 2.5
cpm 2.25
noi 4
1
2
$(document).ready(function () {
3
4
    function setMapByCoords(lng, lat) {
5
        var myLatLng = new google.maps.LatLng(lat, lng);
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...
6
        if (typeof google === 'undefined') {
7
            return;
8
        }
9
        var map = new google.maps.Map(document.getElementById('map'),
10
            {
11
                zoom: 17,
12
                center: myLatLng,
13
                mapTypeId: google.maps.MapTypeId.ROADMAP
14
            });
15
        var marker = new google.maps.Marker(
0 ignored issues
show
Unused Code introduced by
The variable marker seems to be never used. Consider removing it.
Loading history...
16
            {
17
                position: myLatLng,
18
                map: map
19
            });
20
    }
21
22
    function initMap() {
23
        var map_element = $('#map');
24
        var e_slug = map_element.data('event');
25
        var lng = map_element.data('lng');
26
        var lat = map_element.data('lat');
27
        if (!lng || !lat) {
28
            $.ajax({
29
                type: 'post',
30
                url: Routing.generate('get_event_map_position', {slug: e_slug})
0 ignored issues
show
Bug introduced by
The variable Routing seems to be never declared. If this is a global, consider adding a /** global: Routing */ 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...
31
            }).done(
32
                function (data) {
33
                    if (data.result) {
34
                        setMapByCoords(data.lng, data.lat)
35
                    } else {
36
                        console.log('Error:' + data.error);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
37
                    }
38
                }
39
            );
40
        } else {
41
            setMapByCoords(lng, lat)
42
        }
43
    }
44
45
    if ($('#map').length > 0) {
46
        initMap();
47
    }
48
});