Skip to content

Commit ca67424

Browse files
updated the logic for appcache
1 parent 4351fc8 commit ca67424

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,17 @@ <h2><i class="icon-settings rfloat"></i>Settings</h2>
146146
</span>
147147
</div>
148148
<div class="row option">
149-
<span><b>Force refresh cache</b></span>
149+
<span><b>Force check for new version</b></span>
150150
<div class="switch off" id="sw_cache">
151151
<span class="thumb"></span>
152152
<input type="checkbox" id="opt_cache">
153153
</div>
154154
</div>
155155
<div class="row info">
156156
<span>
157-
The size of cache files is around 600 KB.
157+
Reloads appcache if nessasary.
158+
The size of cache files is 1.2 MB.
159+
This does not include map tiles.
158160
</span>
159161
</div>
160162
</div>

js/app.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,22 @@ if(embed.enabled) {
4545
$.ajaxSetup({ cache: true });
4646

4747
// handle cachin events and display a loading bar
48-
var loadReload = false;
4948
var loadComplete = function(e) {
5049
clearTimeout(initTimer);
5150

52-
if(loadReload && e.type == 'updateready') {
53-
if(confirm("Reload app?")) {
54-
window.location.href = window.location.href;
55-
return;
56-
}
51+
if(e.type == 'updateready') {
52+
window.applicationCache.swapCache();
53+
window.location.reload();
54+
return;
5755
}
5856

59-
loadReload = false;
60-
6157
$('#loading .complete').stop(true,true).animate({width: 200}, {complete: trackerInit });
6258
}
6359

6460
// loads the tracker interface
6561
function trackerInit() {
62+
if(map) return;
63+
6664
$('#loading,#settingsbox,#aboutbox,#chasebox').hide(); // welcome screen
6765
$('header,#main,#map').show(); // interface elements
6866

@@ -83,11 +81,13 @@ function trackerInit() {
8381
var initTimer = setTimeout(trackerInit, 3000);
8482

8583
var cache = window.applicationCache;
86-
cache.addEventListener('checking', function() { clearTimeout(initTimer); $('#loading .bar,#loading').show(); $('#loading .complete').css({width: 0}); }, false);
8784
cache.addEventListener('noupdate', loadComplete, false);
8885
cache.addEventListener('updateready', loadComplete, false);
8986
cache.addEventListener('cached', loadComplete, false);
9087
cache.addEventListener('error', loadComplete, false);
88+
89+
// if the browser supports progress events, display a loading bar
90+
cache.addEventListener('checking', function() { clearTimeout(initTimer); $('#loading .bar,#loading').show(); $('#loading .complete').css({width: 0}); }, false);
9191
cache.addEventListener('progress', function(e) { $('#loading .complete').stop(true,true).animate({width: (200/e.total)*e.loaded}); }, false);
9292

9393
var listScroll;
@@ -537,10 +537,7 @@ $(window).ready(function() {
537537
// force re-cache
538538
$('#sw_cache').click(function() {
539539
var e = $(this).removeClass('off').addClass('on');
540-
if(confirm("Force re-cache?")) {
541-
window.scrollTo(0,1);
542-
$("#settingsbox").hide();
543-
loadReload = true;
540+
if(confirm("The app will automatically reload, if new version is available.")) {
544541
applicationCache.update();
545542
}
546543
e.removeClass('on').addClass('off');

0 commit comments

Comments
 (0)