Completed
Push — master ( e2a702...676958 )
by Yannick
44:36 queued 16:19
created

map.common.js ➔ msgbox   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
dl 0
loc 13
rs 9.4285
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A map.common.js ➔ ... ➔ $(?!?).dialog.buttons.click 0 4 1
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; path=/';
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
    if (type[0] == 'Mapbox') {
33
	createCookie('MapType',type[0],9999);
34
	createCookie('MapTypeId',type[1],9999);
35
    } else {
36
	createCookie('MapType',atype,9999);
37
    }
38
    window.location.reload();
39
}
40
41
function terrainType(selectObj) {
42
    var idx = selectObj.selectedIndex;
43
    var atype = selectObj.options[idx].value;
44
    var type = atype.split('-');
45
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
46
    createCookie('MapTerrain',type,9999);
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
    createCookie('sattypes',sattypes.join(),2);
59
    updateSat();
60
}
61
function airlines(selectObj) {
62
    var airs = [], air;
63
    for (var i=0, len=selectObj.options.length; i< len;i++) {
64
	air = selectObj.options[i];
65
	if (air.selected) {
66
	    airs.push(air.value);
67
	}
68
    }
69
    createCookie('filter_Airlines',airs.join(),2);
70
}
71
function airlinestype(selectObj) {
72
    var idx = selectObj.selectedIndex;
73
    var airtype = selectObj.options[idx].value;
74
    createCookie('filter_airlinestype',airtype,2);
75
}
76
function alliance(selectObj) {
77
    var idx = selectObj.selectedIndex;
78
    var alliance = selectObj.options[idx].value;
79
    createCookie('filter_alliance',alliance,2);
80
}
81
function identfilter() {
82
    var ident = $("#identfilter").value;
83
    createCookie('filter_ident',ident,2);
84
}
85
function mmsifilter() {
86
    var ident = $("#mmsifilter").value;
87
    createCookie('filter_mmsi',ident,2);
88
}
89
function removefilters() {
90
    // Get an array of all cookie names (the regex matches what we don't want)
91
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
92
    // Remove any that match the pattern
93
    for (var i = 0; i < cookieNames.length; i++) {
94
	if (/^filter_/.test(cookieNames[i])) {
95
	    delCookie(cookieNames[i]);
96
	}
97
    }
98
    window.location.reload();
99
}
100
function sources(selectObj) {
101
    var sources = [], source;
102
    for (var i=0, len=selectObj.options.length; i< len;i++) {
103
	source = selectObj.options[i];
104
	if (source.selected) {
105
	    sources.push(source.value);
106
	}
107
    }
108
    createCookie('filter_Sources',sources.join(),2);
109
}
110
111
112
function show2D() {
113
    createCookie('MapFormat','2d',10);
114
    createCookie('MapTrack',document.getElementById("aircraft_ident").className,9999);
115
    window.location.reload();
116
}
117
function show3D() {
118
    createCookie('MapFormat','3d',10);
119
    createCookie('MapTrack',document.getElementById("aircraft_ident").className,9999);
120
    window.location.reload();
121
}
122
function clickPolar(cb) {
123
    createCookie('polar',cb.checked,9999);
124
    window.location.reload();
125
}
126
function clickDisplayAirports(cb) {
127
    createCookie('displayairports',cb.checked,9999);
128
    window.location.reload();
129
}
130
function clickDisplayISS(cb) {
131
    createCookie('displayiss',cb.checked,9999);
132
    updateSat();
133
}
134
function clickDisplayMinimap(cb) {
135
    createCookie('displayminimap',cb.checked,9999);
136
    window.location.reload();
137
}
138
function clickSingleModel(cb) {
139
    createCookie('singlemodel',cb.checked,9999);
140
}
141
function clickVATSIM(cb) {
142
    createCookie('filter_ShowVATSIM',cb.checked,2);
143
}
144
function clickIVAO(cb) {
145
     createCookie('filter_ShowIVAO',cb.checked,2);
146
}
147
function clickphpVMS(cb) {
148
    createCookie('filter_ShowVMS',cb.checked,2);
149
}
150
function clickSBS1(cb) {
151
    createCookie('filter_ShowSBS1',cb.checked,2);
152
}
153
function clickAPRS(cb) {
154
    createCookie('filter_ShowAPRS',cb.checked,2);
155
}
156
function clickDisplayGroundStation(cb) {
157
    createCookie('show_GroundStation',cb.checked,2);
158
    window.location.reload();
159
}
160
function clickDisplayWeatherStation(cb) {
161
    createCookie('show_WeatherStation',cb.checked,2);
162
    window.location.reload();
163
}
164
function clickDisplayLightning(cb) {
165
    createCookie('show_Lightning',cb.checked,2);
166
    window.location.reload();
167
}
168
function clickDisplayFires(cb) {
169
    createCookie('show_Fires',cb.checked,2);
170
    window.location.reload();
171
}
172
function clickDisplay2DBuildings(cb) {
173
    createCookie('Map2DBuildings',cb.checked,2);
174
    window.location.reload();
175
}
176
function unitdistance(selectObj) {
177
    var idx = selectObj.selectedIndex;
178
    var unit = selectObj.options[idx].value;
179
    createCookie('unitdistance',unit,9999);
180
}
181
function unitspeed(selectObj) {
182
    var idx = selectObj.selectedIndex;
183
    var unit = selectObj.options[idx].value;
184
    createCookie('unitspeed',unit,9999);
185
}
186
function unitaltitude(selectObj) {
187
    var idx = selectObj.selectedIndex;
188
    var unit = selectObj.options[idx].value;
189
    createCookie('unitaltitude',unit,9999);
190
}
191
function addarchive(begindate,enddate) {
192
    console.log('Add archive');
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...
193
    createCookie('archive',true,2);
194
    createCookie('archive_begin',begindate,2);
195
    createCookie('archive_end',enddate,2);
196
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
197
    window.location.reload();
198
}
199
function noarchive() {
200
    console.log('Exit archive!');
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...
201
    delCookie('archive');
202
    delCookie('archive_begin');
203
    delCookie('archive_end');
204
    delCookie('archive_speed');
205
    window.location.reload();
206
}
207
function msgbox(text,buttontext) {
208
	buttontext = buttontext || "OK";
209
	$("<div>" + text + "</div>").dialog({
210
	    dialogClass: "no-close",
211
	    buttons: [{
212
		text: buttontext,
213
		click: function() {
214
		    $( this ).dialog( "close" );
215
		    $(this).remove();
216
		}
217
	    }]
218
	});
219
}