Skip to content

Commit 0e2912f

Browse files
js style and code cleanup
1 parent 1e29f06 commit 0e2912f

File tree

4 files changed

+203
-196
lines changed

4 files changed

+203
-196
lines changed

js/app.js

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
var is_mobile = false;
33

44
if(
5-
navigator.userAgent.match(/Android/i)
6-
|| navigator.userAgent.match(/iPhone/i)
7-
|| navigator.userAgent.match(/iPod/i)
8-
|| navigator.userAgent.match(/iPad/i)
9-
|| navigator.userAgent.match(/Windows Phone/i)
10-
|| navigator.userAgent.match(/webOS/i)
11-
|| navigator.userAgent.match(/BlackBerry/i)
5+
navigator.userAgent.match(/Android/i) ||
6+
navigator.userAgent.match(/iPhone/i) ||
7+
navigator.userAgent.match(/iPod/i) ||
8+
navigator.userAgent.match(/iPad/i) ||
9+
navigator.userAgent.match(/Windows Phone/i) ||
10+
navigator.userAgent.match(/webOS/i) ||
11+
navigator.userAgent.match(/BlackBerry/i)
1212
) is_mobile = true;
1313

1414
// wvar detection
@@ -23,7 +23,8 @@ var wvar = {
2323
latestonly: is_mobile,
2424
focus: "",
2525
docid: ""
26-
}
26+
};
27+
2728
var params = window.location.search.substring(1).split('&');
2829

2930
for(var idx in params) {
@@ -62,14 +63,14 @@ var loadComplete = function(e) {
6263
// swapCache may throw exception if the isn't a previous cache
6364
try {
6465
window.applicationCache.swapCache();
65-
} catch(e) {}
66+
} catch(v) {}
6667

6768
window.location.reload();
6869
return;
6970
}
7071

7172
$('#loading .complete').stop(true,true).animate({width: 200}, {complete: trackerInit });
72-
}
73+
};
7374

7475
var hysplit = {};
7576
var hysplit_data = {};
@@ -94,7 +95,7 @@ var refresh_hysplit = function() {
9495

9596
if(refresh) refreshUI();
9697
});
97-
}
98+
};
9899

99100
// loads the tracker interface
100101
function trackerInit() {
@@ -140,7 +141,7 @@ var GPS_alt = null;
140141
var GPS_speed = null;
141142
var CHASE_enabled = null;
142143
var CHASE_listenerSent = false;
143-
var CHASE_timer = 0
144+
var CHASE_timer = 0;
144145
var callsign = "";
145146

146147
function checkSize() {
@@ -228,9 +229,9 @@ var positionUpdateHandle = function(position) {
228229
var hours = Math.floor(delta_ts / 3600);
229230
var minutes = Math.floor(delta_ts / 60) % 60;
230231
var ts_str = (delta_ts >= 60) ?
231-
((hours)?hours+'h ':'')
232-
+ ((minutes)?minutes+'m':'')
233-
+ ' ago'
232+
((hours)?hours+'h ':'') +
233+
((minutes)?minutes+'m':'') +
234+
' ago'
234235
: 'just now';
235236
$('#cc_timestamp').text(ts_str);
236237
}, 30000);
@@ -239,12 +240,13 @@ var positionUpdateHandle = function(position) {
239240
}
240241

241242
// save position and update only if different is available
242-
if(CHASE_timer < (new Date()).getTime()
243-
&& (
244-
GPS_lat != lat
245-
|| GPS_lon != lon
246-
|| GPS_alt != alt
247-
|| GPS_speed != speed)
243+
if(CHASE_timer < (new Date()).getTime() &&
244+
(
245+
GPS_lat != lat ||
246+
GPS_lon != lon ||
247+
GPS_alt != alt ||
248+
GPS_speed != speed
249+
)
248250
)
249251
{
250252
GPS_lat = lat;
@@ -255,7 +257,7 @@ var positionUpdateHandle = function(position) {
255257
$('#cc_timestamp').text('just now');
256258

257259
// update look angles once we get position
258-
if(follow_vehicle != null) { update_lookangles(follow_vehicle); }
260+
if(follow_vehicle !== null) { update_lookangles(follow_vehicle); }
259261

260262
if(CHASE_enabled) {
261263
ChaseCar.updatePosition(callsign, position);
@@ -292,12 +294,12 @@ var positionUpdateHandle = function(position) {
292294
$('#app_name b').html('mobile<br/>tracker');
293295
});
294296
*/
295-
}
297+
};
296298

297299
var twoZeroPad = function(n) {
298300
n = String(n);
299301
return (n.length<2) ? '0'+n : n;
300-
}
302+
};
301303

302304
// updates timebox
303305
var updateTimebox = function(date) {
@@ -322,7 +324,7 @@ var updateTimebox = function(date) {
322324
z = date.getTimezoneOffset() / -60;
323325

324326
elm.find(".local").text("Local: "+a+'-'+b+'-'+c+' '+e+':'+f+':'+g+" UTC"+((z<0)?"-":"+")+z);
325-
}
327+
};
326328

327329
var format_time_friendly = function(start, end) {
328330
var dt = Math.floor((end - start) / 1000);
@@ -337,7 +339,7 @@ var format_time_friendly = function(start, end) {
337339
dt = Math.floor(dt/3600);
338340
return Math.floor(dt/24)+'d '+(dt % 24)+'h';
339341
}
340-
}
342+
};
341343

342344
// runs every second
343345
var updateTime = function(date) {
@@ -346,7 +348,7 @@ var updateTime = function(date) {
346348
if(elm.length > 0) updateTimebox(date);
347349

348350
// update friendly delta time fields
349-
var elm = $(".friendly-dtime");
351+
elm = $(".friendly-dtime");
350352
if(elm.length > 0) {
351353
var now = new Date().getTime();
352354

@@ -357,7 +359,7 @@ var updateTime = function(date) {
357359
if(str) e.text(str + ' ago');
358360
});
359361
}
360-
}
362+
};
361363

362364

363365
$(window).ready(function() {
@@ -373,18 +375,18 @@ $(window).ready(function() {
373375
listScroll = new iScroll('main', { hScrollbar: false, hScroll: false, snap: false, scrollbarClass: 'scrollStyle' });
374376

375377
$('#telemetry_graph').on('click', '.graph_label', function() {
376-
var e = $(this);
378+
var e = $(this), h;
377379
if(e.hasClass('active')) {
378380
e.removeClass('active');
379-
var h = $('#map').height() + $('#telemetry_graph').height();
381+
h = $('#map').height() + $('#telemetry_graph').height();
380382

381383
plot_open = false;
382384

383385
//analytics
384386
if(typeof _gaq == 'object') _gaq.push(['_trackEvent', 'UI', 'Collapse', 'Telemetry Graph']);
385387
} else {
386388
e.addClass('active');
387-
var h = $('#map').height() - $('#telemetry_graph').height();
389+
h = $('#map').height() - $('#telemetry_graph').height();
388390

389391
plot_open = true;
390392

@@ -394,7 +396,7 @@ $(window).ready(function() {
394396
$('#map').stop(null,null).animate({'height': h}, function() {
395397
if(map) google.maps.event.trigger(map, 'resize');
396398

397-
if(plot_open && follow_vehicle != null && vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, true);
399+
if(plot_open && follow_vehicle !== null && vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, true);
398400
});
399401
});
400402

@@ -430,7 +432,7 @@ $(window).ready(function() {
430432
// hand cursor for dragging the vehicle list
431433
$("#main").on("mousedown", ".row", function () {
432434
$("#main").addClass("drag");
433-
})
435+
});
434436
$("body").on("mouseup", function () {
435437
$("#main").removeClass("drag");
436438
});
@@ -463,7 +465,7 @@ $(window).ready(function() {
463465
listScroll.refresh();
464466

465467
// disable following only we are collapsing the followed vehicle
466-
if(follow_vehicle != null && follow_vehicle == e.attr('data-vcallsign')) {
468+
if(follow_vehicle !== null && follow_vehicle == e.attr('data-vcallsign')) {
467469
stopFollow();
468470
}
469471
} else {
@@ -506,7 +508,7 @@ $(window).ready(function() {
506508
if(typeof _gaq == 'object') _gaq.push(['_trackEvent', 'UI Menubar', 'Open Page', pretty_name]);
507509
}
508510
checkSize();
509-
})
511+
});
510512

511513
// toggle functionality for switch button
512514
$("#sw_chasecar").click(function() {
@@ -670,7 +672,7 @@ $(window).ready(function() {
670672

671673
try {
672674
applicationCache.update();
673-
} catch (e) {
675+
} catch (v) {
674676
force_check_cache = false;
675677
alert("There is no applicationCache available");
676678
}
@@ -762,13 +764,13 @@ $(window).ready(function() {
762764
var id = switches[i][0];
763765
var name = switches[i][1];
764766

765-
var html = '<div class="row option">'
766-
+ '<span><b>'+name+'</b></span>'
767-
+ '<div class="switch off" id="sw_weather_'+id+'">'
768-
+ '<span class="thumb"></span>'
769-
+ '<input type="checkbox" id="opt_weather_'+id+'">'
770-
+ '</div>'
771-
+ '</div>';
767+
var html = '<div class="row option">' +
768+
'<span><b>'+name+'</b></span>' +
769+
'<div class="switch off" id="sw_weather_'+id+'">' +
770+
'<span class="thumb"></span>' +
771+
'<input type="checkbox" id="opt_weather_'+id+'">' +
772+
'</div>' +
773+
'</div>';
772774

773775
elm.append(html);
774776
}

js/chasecar.lib.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ChaseCar.getUUIDS = function(callback) {
2222
ChaseCar.uused = 0; // reset counter
2323
if(callback) callback();
2424
});
25-
}
25+
};
2626
// handles request and uuid management
2727
// @doc JSONobject
2828
ChaseCar.request = function(doc) {
@@ -40,7 +40,8 @@ ChaseCar.request = function(doc) {
4040
} else {
4141
ChaseCar.uused++;
4242
// get one uuid and one doc from the queue and push to habitat
43-
var uuid = ChaseCar._uuids.shift(), doc = ChaseCar.queue.shift();
43+
var uuid = ChaseCar._uuids.shift();
44+
doc = ChaseCar.queue.shift();
4445

4546
// update doc with uuids and time of upload
4647
doc._id = uuid;
@@ -56,7 +57,7 @@ ChaseCar.request = function(doc) {
5657
});
5758
}
5859
}
59-
}
60+
};
6061
// run once at start,
6162
// @callsign string
6263
ChaseCar.putListenerInfo = function(callsign) {
@@ -67,7 +68,7 @@ ChaseCar.putListenerInfo = function(callsign) {
6768
'time_created': (new Date()).toISOString(),
6869
'data': { 'callsign': callsign }
6970
});
70-
}
71+
};
7172
// run every time the location has changed
7273
// @callsign string
7374
// @position object (geolocation position object)
@@ -91,4 +92,4 @@ ChaseCar.updatePosition = function(callsign, position) {
9192
}
9293
}
9394
});
94-
}
95+
};

js/plot_config.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ function updateLegend() {
3636
}
3737

3838
var y;
39-
if(series.noInterpolate > 0) { y = series.data[((j==0)?j:j-1)][1]; }
39+
if(series.noInterpolate > 0) { y = series.data[((j===0)?j:j-1)][1]; }
4040
else {
41-
var p1 = (j==0) ? null : series.data[j-1];
41+
var p1 = (j===0) ? null : series.data[j-1];
4242
p2 = series.data[j];
4343

44-
if (p1 == null) {
44+
if (p1 === null) {
4545
y = p2[1];
46-
} else if (p2 == null) {
46+
} else if (p2 === null) {
4747
y = p1[1];
4848
} else {
4949
y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
5050
}
5151

52-
y = ((p1 && p1[1] == null) || (p2 && p2[1] == null)) ? null : y.toFixed(2);
52+
y = ((p1 && p1[1] === null) || (p2 && p2[1] === null)) ? null : y.toFixed(2);
5353
}
5454
legend.eq(i).text(series.label.replace(/=.*/, "= " + y));
5555
}
@@ -72,25 +72,26 @@ function updateLegend() {
7272
}
7373
}
7474

75-
if(follow_vehicle != null && vehicles[follow_vehicle].positions.length) {
75+
if(follow_vehicle !== null && vehicles[follow_vehicle].positions.length) {
7676
// adjust index for null data points
7777
var null_count = 0;
7878
var data_ref = vehicles[follow_vehicle].graph_data[0];
7979

8080
if(j > data_ref.data.length / 2) {
81-
for(var i = data_ref.data.length - 1; i > j; i--) null_count += (data_ref.data[i][1] == null) ? 1 : 0;
81+
for(i = data_ref.data.length - 1; i > j; i--) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
8282
null_count = data_ref.nulls - null_count * 2;
8383
} else {
84-
for(var i = 0; i < j; i++) null_count += (data_ref.data[i][1] == null) ? 1 : 0;
84+
for(i = 0; i < j; i++) null_count += (data_ref.data[i][1] === null) ? 1 : 0;
8585
null_count *= 2;
8686
}
8787

8888
// update position
8989
polyMarker.setPosition(vehicles[follow_vehicle].positions[j - null_count]);
9090

9191
// adjust nite overlay
92+
var date;
9293
try {
93-
var date = new Date(data_ref.data[j][0])
94+
date = new Date(data_ref.data[j][0]);
9495
} catch(e) {
9596
return;
9697
}

0 commit comments

Comments
 (0)