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); |
|
|
|
|
7
|
|
|
if (c.indexOf(name) == 0) return c.substring(name.length,c.length); |
|
|
|
|
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
|
|
|
if (getCookie('Map2D3DSync')) { |
36
|
|
|
createCookie('MapType3D',type[0],9999); |
37
|
|
|
createCookie('MapType3DId',type[1],9999); |
38
|
|
|
} |
39
|
|
|
} else { |
40
|
|
|
createCookie('MapType',atype,9999); |
41
|
|
|
if (getCookie('Map2D3DSync')) { |
42
|
|
|
createCookie('MapType3D',atype,9999); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
window.location.reload(); |
46
|
|
|
} |
47
|
|
|
function mapType3D(selectObj) { |
48
|
|
|
var idx = selectObj.selectedIndex; |
49
|
|
|
var atype = selectObj.options[idx].value; |
50
|
|
|
var type = atype.split('-'); |
51
|
|
|
if (type[0] == 'Mapbox') { |
52
|
|
|
createCookie('MapType3D',type[0],9999); |
53
|
|
|
createCookie('MapType3DId',type[1],9999); |
54
|
|
|
if (getCookie('Map2D3DSync')) { |
55
|
|
|
createCookie('MapType',type[0],9999); |
56
|
|
|
createCookie('MapTypeId',type[1],9999); |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
createCookie('MapType3D',atype,9999); |
60
|
|
|
if (getCookie('Map2D3DSync')) { |
61
|
|
|
createCookie('MapType',atype,9999); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
window.location.reload(); |
65
|
|
|
} |
66
|
|
|
function clickSyncMap2D3D(cb) { |
67
|
|
|
createCookie('Map2D3DSync',cb.checked,9999); |
68
|
|
|
if (cb.checked) { |
69
|
|
|
createCookie('MapType3D',getCookie('MapType'),9999); |
70
|
|
|
createCookie('MapType3DId',getCookie('MapTypeId'),9999); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
function terrainType(selectObj) { |
75
|
|
|
var idx = selectObj.selectedIndex; |
76
|
|
|
var atype = selectObj.options[idx].value; |
77
|
|
|
var type = atype.split('-'); |
78
|
|
|
document.cookie = 'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/' |
79
|
|
|
createCookie('MapTerrain',type,9999); |
80
|
|
|
window.location.reload(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function sattypes(selectObj) { |
84
|
|
|
var sattypes = [], sattype; |
85
|
|
|
for (var i=0, len=selectObj.options.length; i< len;i++) { |
86
|
|
|
sattype = selectObj.options[i]; |
87
|
|
|
if (sattype.selected) { |
88
|
|
|
sattypes.push(sattype.value); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
createCookie('sattypes',sattypes.join(),2); |
92
|
|
|
updateSat(); |
93
|
|
|
} |
94
|
|
|
function airlines(selectObj) { |
95
|
|
|
var airs = [], air; |
96
|
|
|
for (var i=0, len=selectObj.options.length; i< len;i++) { |
97
|
|
|
air = selectObj.options[i]; |
98
|
|
|
if (air.selected) { |
99
|
|
|
airs.push(air.value); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
createCookie('filter_Airlines',airs.join(),2); |
103
|
|
|
} |
104
|
|
|
function airlinestype(selectObj) { |
105
|
|
|
var idx = selectObj.selectedIndex; |
106
|
|
|
var airtype = selectObj.options[idx].value; |
107
|
|
|
createCookie('filter_airlinestype',airtype,2); |
108
|
|
|
} |
109
|
|
|
function alliance(selectObj) { |
110
|
|
|
var idx = selectObj.selectedIndex; |
111
|
|
|
var alliance = selectObj.options[idx].value; |
112
|
|
|
createCookie('filter_alliance',alliance,2); |
113
|
|
|
} |
114
|
|
|
function identfilter() { |
115
|
|
|
var ident = $("#identfilter").value; |
116
|
|
|
createCookie('filter_ident',ident,2); |
117
|
|
|
} |
118
|
|
|
function mmsifilter() { |
119
|
|
|
var ident = $("#mmsifilter").value; |
120
|
|
|
createCookie('filter_mmsi',ident,2); |
121
|
|
|
} |
122
|
|
|
function removefilters() { |
123
|
|
|
// Get an array of all cookie names (the regex matches what we don't want) |
124
|
|
|
var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/); |
125
|
|
|
// Remove any that match the pattern |
126
|
|
|
for (var i = 0; i < cookieNames.length; i++) { |
127
|
|
|
if (/^filter_/.test(cookieNames[i])) { |
128
|
|
|
delCookie(cookieNames[i]); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
window.location.reload(); |
132
|
|
|
} |
133
|
|
|
function sources(selectObj) { |
134
|
|
|
var sources = [], source; |
135
|
|
|
for (var i=0, len=selectObj.options.length; i< len;i++) { |
136
|
|
|
source = selectObj.options[i]; |
137
|
|
|
if (source.selected) { |
138
|
|
|
sources.push(source.value); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
createCookie('filter_Sources',sources.join(),2); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
function show2D() { |
146
|
|
|
createCookie('MapFormat','2d',10); |
147
|
|
|
if (document.getElementById("pointtype").className == 'tracker') { |
148
|
|
|
createCookie('MapTrackTracker',document.getElementById("pointident").className,1); |
149
|
|
|
} else if (document.getElementById("pointtype").className == 'marine') { |
150
|
|
|
createCookie('MapTrackMarine',document.getElementById("pointident").className,1); |
151
|
|
|
} else { |
152
|
|
|
createCookie('MapTrack',document.getElementById("pointident").className,1); |
153
|
|
|
} |
154
|
|
|
window.location.reload(); |
155
|
|
|
} |
156
|
|
|
function show3D() { |
157
|
|
|
createCookie('MapFormat','3d',10); |
158
|
|
|
if (document.getElementById("pointtype").className == 'tracker') { |
159
|
|
|
createCookie('MapTrackTracker',document.getElementById("pointident").className,1); |
160
|
|
|
} else if (document.getElementById("pointtype").className == 'marine') { |
161
|
|
|
createCookie('MapTrackMarine',document.getElementById("pointident").className,1); |
162
|
|
|
} else { |
163
|
|
|
createCookie('MapTrack',document.getElementById("pointident").className,1); |
164
|
|
|
} |
165
|
|
|
window.location.reload(); |
166
|
|
|
} |
167
|
|
|
function clickPolar(cb) { |
168
|
|
|
createCookie('polar',cb.checked,9999); |
169
|
|
|
window.location.reload(); |
170
|
|
|
} |
171
|
|
|
function clickDisplayAirports(cb) { |
172
|
|
|
createCookie('displayairports',cb.checked,9999); |
173
|
|
|
window.location.reload(); |
174
|
|
|
} |
175
|
|
|
function clickDisplayISS(cb) { |
176
|
|
|
createCookie('displayiss',cb.checked,9999); |
177
|
|
|
updateSat(); |
178
|
|
|
} |
179
|
|
|
function clickDisplayMinimap(cb) { |
180
|
|
|
createCookie('displayminimap',cb.checked,9999); |
181
|
|
|
window.location.reload(); |
182
|
|
|
} |
183
|
|
|
function clickSingleModel(cb) { |
184
|
|
|
createCookie('singlemodel',cb.checked,9999); |
185
|
|
|
} |
186
|
|
|
function clickVATSIM(cb) { |
187
|
|
|
createCookie('filter_ShowVATSIM',cb.checked,2); |
188
|
|
|
} |
189
|
|
|
function clickIVAO(cb) { |
190
|
|
|
createCookie('filter_ShowIVAO',cb.checked,2); |
191
|
|
|
} |
192
|
|
|
function clickphpVMS(cb) { |
193
|
|
|
createCookie('filter_ShowVMS',cb.checked,2); |
194
|
|
|
} |
195
|
|
|
function clickSBS1(cb) { |
196
|
|
|
createCookie('filter_ShowSBS1',cb.checked,2); |
197
|
|
|
} |
198
|
|
|
function clickAPRS(cb) { |
199
|
|
|
createCookie('filter_ShowAPRS',cb.checked,2); |
200
|
|
|
} |
201
|
|
|
function clickDisplayGroundStation(cb) { |
202
|
|
|
createCookie('show_GroundStation',cb.checked,2); |
203
|
|
|
window.location.reload(); |
204
|
|
|
} |
205
|
|
|
function clickDisplayWeatherStation(cb) { |
206
|
|
|
createCookie('show_WeatherStation',cb.checked,2); |
207
|
|
|
window.location.reload(); |
208
|
|
|
} |
209
|
|
|
function clickDisplayLightning(cb) { |
210
|
|
|
createCookie('show_Lightning',cb.checked,2); |
211
|
|
|
window.location.reload(); |
212
|
|
|
} |
213
|
|
|
function clickDisplayFires(cb) { |
214
|
|
|
createCookie('show_Fires',cb.checked,2); |
215
|
|
|
window.location.reload(); |
216
|
|
|
} |
217
|
|
|
function clickDisplay2DBuildings(cb) { |
218
|
|
|
createCookie('Map2DBuildings',cb.checked,2); |
219
|
|
|
window.location.reload(); |
220
|
|
|
} |
221
|
|
|
function unitdistance(selectObj) { |
222
|
|
|
var idx = selectObj.selectedIndex; |
223
|
|
|
var unit = selectObj.options[idx].value; |
224
|
|
|
createCookie('unitdistance',unit,9999); |
225
|
|
|
} |
226
|
|
|
function unitspeed(selectObj) { |
227
|
|
|
var idx = selectObj.selectedIndex; |
228
|
|
|
var unit = selectObj.options[idx].value; |
229
|
|
|
createCookie('unitspeed',unit,9999); |
230
|
|
|
} |
231
|
|
|
function unitaltitude(selectObj) { |
232
|
|
|
var idx = selectObj.selectedIndex; |
233
|
|
|
var unit = selectObj.options[idx].value; |
234
|
|
|
createCookie('unitaltitude',unit,9999); |
235
|
|
|
} |
236
|
|
|
function addarchive(begindate,enddate) { |
237
|
|
|
console.log('Add archive'); |
|
|
|
|
238
|
|
|
createCookie('archive',true,2); |
239
|
|
|
createCookie('archive_begin',begindate,2); |
240
|
|
|
createCookie('archive_end',enddate,2); |
241
|
|
|
createCookie('archive_speed',document.getElementById("archivespeed").value,2); |
242
|
|
|
window.location.reload(); |
243
|
|
|
} |
244
|
|
|
function noarchive() { |
245
|
|
|
console.log('Exit archive!'); |
|
|
|
|
246
|
|
|
delCookie('archive'); |
247
|
|
|
delCookie('archive_begin'); |
248
|
|
|
delCookie('archive_end'); |
249
|
|
|
delCookie('archive_speed'); |
250
|
|
|
window.location.reload(); |
251
|
|
|
} |
252
|
|
|
function msgbox(text,buttontext) { |
253
|
|
|
buttontext = buttontext || "OK"; |
254
|
|
|
$("<div>" + text + "</div>").dialog({ |
255
|
|
|
dialogClass: "no-close", |
256
|
|
|
buttons: [{ |
257
|
|
|
text: buttontext, |
258
|
|
|
click: function() { |
259
|
|
|
$( this ).dialog( "close" ); |
260
|
|
|
$(this).remove(); |
261
|
|
|
} |
262
|
|
|
}] |
263
|
|
|
}); |
264
|
|
|
} |
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 you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.