@@ -10,17 +10,23 @@ var loadComplete = function(e) {
1010
1111 loadReload = false ;
1212
13- $ ( '#loading .complete' ) . stop ( true , true ) . animate ( { width : 200 } , { complete : function ( ) {
14- $ ( '#loading,#settingsbox,#aboutbox,#chasebox' ) . hide ( ) ; // welcome screen
15- $ ( 'header,#main,#map' ) . show ( ) ; // interface elements
16- checkSize ( ) ;
17-
18- if ( ! map ) load ( ) ;
19- } } ) ;
13+ $ ( '#loading .complete' ) . stop ( true , true ) . animate ( { width : 200 } , { complete : trackerInit } ) ;
2014}
2115
16+ // loads the tracker interface
17+ function trackerInit ( ) {
18+ $ ( '#loading,#settingsbox,#aboutbox,#chasebox' ) . hide ( ) ; // welcome screen
19+ $ ( 'header,#main,#map' ) . show ( ) ; // interface elements
20+ checkSize ( ) ;
21+
22+ if ( ! map ) load ( ) ;
23+ }
24+
25+ // if for some reason, applicationCache is not working, load the app after a 5s timeout
26+ var initTimer = setTimeout ( trackerInit , 5000 ) ;
27+
2228var cache = window . applicationCache ;
23- cache . addEventListener ( 'checking' , function ( ) { $ ( '#loading .bar,#loading' ) . show ( ) ; $ ( '#loading .complete' ) . css ( { width : 0 } ) ; } , false ) ;
29+ cache . addEventListener ( 'checking' , function ( ) { clearTimeout ( initTimer ) ; $ ( '#loading .bar,#loading' ) . show ( ) ; $ ( '#loading .complete' ) . css ( { width : 0 } ) ; } , false ) ;
2430cache . addEventListener ( 'noupdate' , loadComplete , false ) ;
2531cache . addEventListener ( 'updateready' , loadComplete , false ) ;
2632cache . addEventListener ( 'cached' , loadComplete , false ) ;
@@ -71,7 +77,7 @@ window.onchangeorientation = checkSize;
7177// functions
7278
7379var positionUpdateHandle = function ( ) {
74- if ( CHASE_enabled && ! CHASE_listenerSent ) {
80+ if ( CHASE_enabled && ! CHASE_listenerSent ) {
7581 if ( offline . get ( 'opt_station' ) ) {
7682 ChaseCar . putListenerInfo ( callsign ) ;
7783 CHASE_listenerSent = true ;
@@ -95,7 +101,7 @@ var positionUpdateHandle = function() {
95101 // generate friendly timestamp
96102 var hours = Math . floor ( delta_ts / 3600 ) ;
97103 var minutes = Math . floor ( delta_ts / 60 ) % 60 ;
98- var ts_str = ( delta_ts >= 60 ) ?
104+ var ts_str = ( delta_ts >= 60 ) ?
99105 ( ( hours ) ?hours + 'h ' :'' )
100106 + ( ( minutes ) ?minutes + 'm' :'' )
101107 + ' ago'
@@ -127,7 +133,7 @@ var positionUpdateHandle = function() {
127133
128134 // add/update marker on the map (tracker.js)
129135 updateCurrentPosition ( lat , lon ) ;
130-
136+
131137 // round the coordinates
132138 lat = parseInt ( lat * 1000000 ) / 1000000 ; // 6 decimal places
133139 lon = parseInt ( lon * 1000000 ) / 1000000 ; // 6 decimal places
@@ -144,7 +150,7 @@ var positionUpdateHandle = function() {
144150 $ ( '#cc_alt' ) . text ( alt + " m" ) ;
145151 $ ( '#cc_accuracy' ) . text ( accuracy + " m" ) ;
146152 $ ( '#cc_speed' ) . text ( speed + " m/s" ) ;
147- } ,
153+ } ,
148154 function ( ) {
149155 // when there is no location
150156 $ ( '#app_name b' ) . html ( 'mobile<br/>tracker' ) ;
@@ -185,13 +191,13 @@ $(window).ready(function() {
185191 e . find ( '.data' ) . show ( ) ;
186192
187193 listScroll . refresh ( ) ;
188-
194+
189195 // auto scroll when expanding an item
190196 if ( $ ( '.portrait:visible' ) . length ) {
191197 var eName = "." + e . parent ( ) . attr ( 'class' ) + " ." + e . attr ( 'class' ) . match ( / v e h i c l e \d + / ) [ 0 ] ;
192198 listScroll . scrollToElement ( eName ) ;
193199 }
194-
200+
195201 // pan to selected vehicle
196202 followVehicle ( parseInt ( e . attr ( 'class' ) . match ( / v e h i c l e ( \d + ) / ) [ 1 ] ) ) ;
197203 }
@@ -248,19 +254,19 @@ $(window).ready(function() {
248254 CHASE_enabled = false ;
249255
250256 // blue man reappers :)
251- if ( currentPosition && currentPosition . marker ) currentPosition . marker . setVisible ( true ) ;
257+ if ( currentPosition && currentPosition . marker ) currentPosition . marker . setVisible ( true ) ;
252258 // turning the switch on
253259 } else {
254260 if ( callsign . length < 5 ) { alert ( 'Please enter a valid callsign, at least 5 characters' ) ; return ; }
255261 if ( ! callsign . match ( / ^ [ a - z A - Z 0 - 9 \_ \- ] + $ / ) ) { alert ( 'Invalid characters in callsign (use only a-z,0-9,-,_)' ) ; return ; }
256262
257263 field . attr ( 'disabled' , 'disabled' ) ;
258264 e . removeClass ( 'off' ) . addClass ( 'on' ) ;
259-
265+
260266 // push listener doc to habitat
261267 // this gets a station on the map, under the car marker
262268 // im still not sure its nessesary
263- if ( ! CHASE_listenerSent ) {
269+ if ( ! CHASE_listenerSent ) {
264270 if ( offline . get ( 'opt_station' ) ) {
265271 ChaseCar . putListenerInfo ( callsign ) ;
266272 CHASE_listenerSent = true ;
@@ -280,7 +286,7 @@ $(window).ready(function() {
280286 // remember callsign as a cookie
281287 $ ( "#cc_callsign" ) . on ( 'change keyup' , function ( ) {
282288 callsign = $ ( this ) . val ( ) . trim ( ) ;
283- offline . set ( 'callsign' , callsign ) ; // put in localStorage
289+ offline . set ( 'callsign' , callsign ) ; // put in localStorage
284290 CHASE_listenerSent = false ;
285291 } ) ;
286292
@@ -295,7 +301,7 @@ $(window).ready(function() {
295301 var e = $ ( this ) ;
296302 var name = e . attr ( 'id' ) . replace ( 'sw' , 'opt' ) ;
297303 var on ;
298-
304+
299305 if ( e . hasClass ( 'on' ) ) {
300306 e . removeClass ( 'on' ) . addClass ( 'off' ) ;
301307 on = 0 ;
@@ -306,17 +312,17 @@ $(window).ready(function() {
306312 nite . show ( ) ;
307313 }
308314
309- offline . set ( name , on ) ;
315+ offline . set ( name , on ) ;
310316 } ) ;
311317
312318 if ( offline . get ( 'opt_daylight' ) ) $ ( '#sw_daylight' ) . removeClass ( 'off' ) . addClass ( 'on' ) ;
313-
319+
314320 // offline and mobile
315321 $ ( '#sw_offline, #sw_station, #sw_imperial' ) . click ( function ( ) {
316322 var e = $ ( this ) ;
317323 var name = e . attr ( 'id' ) . replace ( 'sw' , 'opt' ) ;
318324 var on ;
319-
325+
320326 if ( e . hasClass ( 'on' ) ) {
321327 e . removeClass ( 'on' ) . addClass ( 'off' ) ;
322328 on = 0 ;
@@ -325,7 +331,7 @@ $(window).ready(function() {
325331 on = 1 ;
326332 }
327333
328- offline . set ( name , on ) ;
334+ offline . set ( name , on ) ;
329335 if ( name == "opt_imperial" ) refreshUI ( ) ;
330336 } ) ;
331337
@@ -347,7 +353,7 @@ $(window).ready(function() {
347353
348354 // We are able to get GPS position on idevices, if the user allows
349355 // The position is displayed in top right corner of the screen
350- // This should be very handly for in the field tracking
356+ // This should be very handly for in the field tracking
351357 //setTimeout(function() {updateCurrentPosition(50.27533, 3.335166);}, 5000);
352358 if ( navigator . geolocation ) {
353359 // if we have geolocation services, show the locate me button
@@ -360,14 +366,14 @@ $(window).ready(function() {
360366 // open map
361367 $ ( '.nav .home' ) . click ( ) ;
362368 // pan map to our current location
363- map . panTo ( new google . maps . LatLng ( currentPosition . lat , currentPosition . lon ) ) ;
369+ map . panTo ( new google . maps . LatLng ( currentPosition . lat , currentPosition . lon ) ) ;
364370 } else {
365371 alert ( "No position available" ) ;
366372 }
367373 } ) ;
368374
369375 // check for location update every 30sec
370- setInterval ( positionUpdateHandle , 30000 ) ;
376+ setInterval ( positionUpdateHandle , 30000 ) ;
371377 // immediatelly check for position
372378 positionUpdateHandle ( ) ;
373379 }
0 commit comments