Completed
Push — master ( 3c8e70...140646 )
by Yannick
30:21
created

map.common.js ➔ noarchive   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
nc 1
dl 0
loc 8
rs 9.4285
nop 0
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 mmsifilter() {
91
    var ident = $("#mmsifilter").value;
92
    //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=/'
93
    createCookie('filter_mmsi',ident,2);
94
}
95
function removefilters() {
96
    // Get an array of all cookie names (the regex matches what we don't want)
97
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
98
    // Remove any that match the pattern
99
    for (var i = 0; i < cookieNames.length; i++) {
100
    if (/^filter_/.test(cookieNames[i])) {
101
        document.cookie = cookieNames[i] + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
102
        }
103
    }
104
    window.location.reload();
105
}
106
function sources(selectObj) {
107
    var sources = [], source;
108
    for (var i=0, len=selectObj.options.length; i< len;i++) {
109
	source = selectObj.options[i];
110
	if (source.selected) {
111
	    sources.push(source.value);
112
	}
113
    }
114
    //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=/';
115
    createCookie('filter_Sources',sources.join(),2);
116
}
117
118
119
function show2D() {
120
    //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=/';
121
    createCookie('MapFormat','2d',10);
122
    document.cookie =  'MapTrack='+document.getElementById("aircraft_ident").className+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
123
    window.location.reload();
124
}
125
function show3D() {
126
    createCookie('MapFormat','3d',10);
127
    document.cookie =  'MapTrack='+document.getElementById("aircraft_ident").className+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
128
    window.location.reload();
129
}
130
function clickPolar(cb) {
131
    document.cookie =  'polar='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
132
    window.location.reload();
133
}
134
function clickDisplayAirports(cb) {
135
    document.cookie =  'displayairports='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
136
    window.location.reload();
137
}
138
function clickDisplayISS(cb) {
139
    document.cookie =  'displayiss='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
140
    updateSat();
141
}
142
function clickDisplayMinimap(cb) {
143
    document.cookie =  'displayminimap='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
144
    window.location.reload();
145
}
146
function clickSingleModel(cb) {
147
    document.cookie =  'singlemodel='+cb.checked+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
148
}
149
function clickVATSIM(cb) {
150
    //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=/';
151
    createCookie('filter_ShowVATSIM',cb.checked,2);
152
}
153
function clickIVAO(cb) {
154
     //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=/';
155
     createCookie('filter_ShowIVAO',cb.checked,2);
156
}
157
function clickphpVMS(cb) {
158
    //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=/';
159
    createCookie('filter_ShowVMS',cb.checked,2);
160
}
161
function clickSBS1(cb) {
162
    //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=/';
163
    createCookie('filter_ShowSBS1',cb.checked,2);
164
}
165
function clickAPRS(cb) {
166
    //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=/';
167
    createCookie('filter_ShowAPRS',cb.checked,2);
168
}
169
function clickDisplayGroundStation(cb) {
170
    createCookie('show_GroundStation',cb.checked,2);
171
    window.location.reload();
172
}
173
function clickDisplayWeatherStation(cb) {
174
    createCookie('show_WeatherStation',cb.checked,2);
175
    window.location.reload();
176
}
177
function clickDisplayLightning(cb) {
178
    createCookie('show_Lightning',cb.checked,2);
179
    window.location.reload();
180
}
181
function clickDisplayFires(cb) {
182
    createCookie('show_Fires',cb.checked,2);
183
    window.location.reload();
184
}
185
function clickDisplay2DBuildings(cb) {
186
    createCookie('Map2DBuildings',cb.checked,2);
187
    window.location.reload();
188
}
189
function unitdistance(selectObj) {
190
    var idx = selectObj.selectedIndex;
191
    var unit = selectObj.options[idx].value;
192
    document.cookie =  'unitdistance='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
193
}
194
function unitspeed(selectObj) {
195
    var idx = selectObj.selectedIndex;
196
    var unit = selectObj.options[idx].value;
197
    document.cookie =  'unitspeed='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
198
}
199
function unitaltitude(selectObj) {
200
    var idx = selectObj.selectedIndex;
201
    var unit = selectObj.options[idx].value;
202
    document.cookie =  'unitaltitude='+unit+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/';
203
}
204
function addarchive(begindate,enddate) {
205
    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...
206
    createCookie('archive',true,2);
207
//    createCookie('archive_begin',document.getElementById("start_date").value,2);
208
//    createCookie('archive_end',document.getElementById("end_date").value,2);
209
    createCookie('archive_begin',begindate,2);
210
    createCookie('archive_end',enddate,2);
211
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
212
    window.location.reload();
213
}
214
function noarchive() {
215
    console.log('No 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...
216
    delCookie('archive');
217
    delCookie('archive_begin');
218
    delCookie('archive_end');
219
    delCookie('archive_speed');
220
    window.location.reload();
221
}