Completed
Push — master ( e37ce2...f4833e )
by Yannick
10:24 queued 02:21
created

js/map.common.js   B

Complexity

Total Complexity 40
Complexity/F 1.48

Size

Lines of Code 178
Function Count 27

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 40
nc 1
mnd 2
bc 40
fnc 27
dl 0
loc 178
rs 8.2608
bpm 1.4814
cpm 1.4814
noi 2
c 0
b 0
f 0

26 Functions

Rating   Name   Duplication   Size   Complexity  
A map.common.js ➔ sattypes 0 12 3
A map.common.js ➔ createCookie 0 11 2
A map.common.js ➔ clickSBS1 0 4 1
A map.common.js ➔ clickIVAO 0 4 1
A map.common.js ➔ clickVATSIM 0 4 1
A map.common.js ➔ clickDisplayISS 0 4 1
A map.common.js ➔ delCookie 0 3 1
A map.common.js ➔ show2D 0 5 1
A map.common.js ➔ clickAPRS 0 4 1
A map.common.js ➔ airlines 0 11 3
A map.common.js ➔ terrainType 0 7 1
A map.common.js ➔ show3D 0 5 1
A map.common.js ➔ clickDisplayMinimap 0 4 1
A map.common.js ➔ clickPolar 0 4 1
A map.common.js ➔ identfilter 0 5 1
A map.common.js ➔ mapType 0 13 2
A map.common.js ➔ clickDisplayAirports 0 4 1
A map.common.js ➔ clickphpVMS 0 4 1
A map.common.js ➔ alliance 0 6 1
A map.common.js ➔ sources 0 11 3
A map.common.js ➔ removefilters 0 11 3
A map.common.js ➔ airlinestype 0 6 1
A map.common.js ➔ clickDisplayGroundStation 0 4 1
A map.common.js ➔ unitspeed 0 5 1
A map.common.js ➔ unitdistance 0 5 1
A map.common.js ➔ unitaltitude 0 5 1

How to fix   Complexity   

Complexity

Complex classes like js/map.common.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
        date = new Date();
20
        date.setTime(date.getTime()+(days*24*60*60*1000));
21
        expires = "; expires="+date.toGMTString();
22
    } else {
23
        expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function mapType(selectObj) {
29
    var idx = selectObj.selectedIndex;
30
    var atype = selectObj.options[idx].value;
31
    var type = atype.split('-');
32
    document.cookie =  'MapType='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
33
    if (type[0] == 'Mapbox') {
34
	document.cookie =  'MapType='+type[0]+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
35
	document.cookie =  'MapTypeId='+type[1]+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
36
    } else {
37
	document.cookie =  'MapType='+atype+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
38
    }
39
    window.location.reload();
40
}
41
42
function terrainType(selectObj) {
43
    var idx = selectObj.selectedIndex;
44
    var atype = selectObj.options[idx].value;
45
    var type = atype.split('-');
46
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
47
    window.location.reload();
48
}
49
50
function sattypes(selectObj) {
51
    var sattypes = [], sattype;
52
    for (var i=0, len=selectObj.options.length; i< len;i++) {
53
	sattype = selectObj.options[i];
54
	if (sattype.selected) {
55
	    sattypes.push(sattype.value);
56
	}
57
    }
58
    //document.cookie =  'sattypes='+sattypes.join()+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/'
59
    createCookie('sattypes',sattypes.join(),2);
60
    updateSat();
61
}
62
function airlines(selectObj) {
63
    var airs = [], air;
64
    for (var i=0, len=selectObj.options.length; i< len;i++) {
65
	air = selectObj.options[i];
66
	if (air.selected) {
67
	    airs.push(air.value);
68
	}
69
    }
70
    //document.cookie =  'filter_Airlines='+airs.join()+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/'
71
    createCookie('filter_Airlines',airs.join(),2);
72
}
73
function airlinestype(selectObj) {
74
    var idx = selectObj.selectedIndex;
75
    var airtype = selectObj.options[idx].value;
76
    //document.cookie =  'filter_airlinestype='+airtype+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/'
77
    createCookie('filter_airlinestype',airtype,2);
78
}
79
function alliance(selectObj) {
80
    var idx = selectObj.selectedIndex;
81
    var alliance = selectObj.options[idx].value;
82
    //document.cookie =  'filter_alliance='+alliance+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/'
83
    createCookie('filter_alliance',alliance,2);
84
}
85
function identfilter() {
86
    var ident = $("#identfilter").value;
87
    //document.cookie =  'filter_ident='+ident+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/'
88
    createCookie('filter_ident',ident,2);
89
}
90
function removefilters() {
91
    // Get an array of all cookie names (the regex matches what we don't want)
92
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
93
    // Remove any that match the pattern
94
    for (var i = 0; i < cookieNames.length; i++) {
95
    if (/^filter_/.test(cookieNames[i])) {
96
        document.cookie = cookieNames[i] + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
97
        }
98
    }
99
    window.location.reload();
100
}
101
function sources(selectObj) {
102
    var sources = [], source;
103
    for (var i=0, len=selectObj.options.length; i< len;i++) {
104
	source = selectObj.options[i];
105
	if (source.selected) {
106
	    sources.push(source.value);
107
	}
108
    }
109
    //document.cookie =  'filter_Sources='+sources.join()+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
110
    createCookie('filter_Sources',sources.join(),2);
111
}
112
113
114
function show2D() {
115
    //document.cookie =  'MapFormat=2d; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
116
    createCookie('MapFormat','2d',10);
117
    window.location.reload();
118
}
119
function show3D() {
120
    //document.cookie =  'MapFormat=3d; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
121
    createCookie('MapFormat','3d',10);
122
    window.location.reload();
123
}
124
function clickPolar(cb) {
125
    document.cookie =  'polar='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
126
    window.location.reload();
127
}
128
function clickDisplayAirports(cb) {
129
    document.cookie =  'displayairports='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
130
    window.location.reload();
131
}
132
function clickDisplayISS(cb) {
133
    document.cookie =  'displayiss='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
134
    window.location.reload();
135
}
136
function clickDisplayMinimap(cb) {
137
    document.cookie =  'displayminimap='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
138
    window.location.reload();
139
}
140
function clickVATSIM(cb) {
141
    //document.cookie =  'filter_ShowVATSIM='+cb.checked+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
142
    createCookie('filter_ShowVATSIM',cb.checked,2);
143
}
144
function clickIVAO(cb) {
145
     //document.cookie =  'filter_ShowIVAO='+cb.checked+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
146
     createCookie('filter_ShowIVAO',cb.checked,2);
147
}
148
function clickphpVMS(cb) {
149
    //document.cookie =  'filter_ShowVMS='+cb.checked+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
150
    createCookie('filter_ShowVMS',cb.checked,2);
151
}
152
function clickSBS1(cb) {
153
    //document.cookie =  'filter_ShowSBS1='+cb.checked+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
154
    createCookie('filter_ShowSBS1',cb.checked,2);
155
}
156
function clickAPRS(cb) {
157
    //document.cookie =  'filter_ShowAPRS='+cb.checked+'; expires=<?php print date("D, j M Y G:i:s T",mktime(0, 0, 0, date("m")  , date("d")+2, date("Y"))); ?>; path=/';
158
    createCookie('filter_ShowAPRS',cb.checked,2);
159
}
160
function clickDisplayGroundStation(cb) {
161
    createCookie('show_GroundStation',cb.checked,2);
162
    window.location.reload();
163
}
164
function unitdistance(selectObj) {
165
    var idx = selectObj.selectedIndex;
166
    var unit = selectObj.options[idx].value;
167
    document.cookie =  'unitdistance='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
168
}
169
function unitspeed(selectObj) {
170
    var idx = selectObj.selectedIndex;
171
    var unit = selectObj.options[idx].value;
172
    document.cookie =  'unitspeed='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
173
}
174
function unitaltitude(selectObj) {
175
    var idx = selectObj.selectedIndex;
176
    var unit = selectObj.options[idx].value;
177
    document.cookie =  'unitaltitude='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
178
}
179