aboutsummaryrefslogtreecommitdiff
path: root/radicale_infcloud/web/cache_handler.js
blob: a285d091053d5ff9080e59542ade353115946044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// OFFLINE CACHE DEBUGGING

/*var cacheStatusValues=[];
cacheStatusValues[0]='uncached';
cacheStatusValues[1]='idle';
cacheStatusValues[2]='checking';
cacheStatusValues[3]='downloading';
cacheStatusValues[4]='updateready';
cacheStatusValues[5]='obsolete';

var cache=window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);

function logEvent(e)
{
	var online, status, type, message;
	online=(navigator.onLine) ? 'yes' : 'no';
	status=cacheStatusValues[cache.status];
	type=e.type;
	message='online: '+online;
	message+=', event: '+type;
	message+=', status: '+status;
	if(type=='error' && navigator.onLine)
		message+=' (prolly a syntax error in manifest)';
	console.log(message);
}

window.applicationCache.addEventListener('updateready', function(){
		window.applicationCache.swapCache();
		console.log('swap cache has been called');
	}, false
);

//setInterval(function(){cache.update()}, 10000);*/

// Check if a new cache is available on page load.
window.addEventListener('load', function(e)
{
	// Suppress useless warning/errors about applicationCache not existing.
	if(window.applicationCache)
	{
		window.applicationCache.addEventListener('cached', function(e)
		{
			if(!isUserLogged)
				window.location.reload();
			else
				$('#cacheDialog').css('display','block');
		}, false);

		window.applicationCache.addEventListener('updateready', function(e)
		{
			if(!isUserLogged)
				window.location.reload();
			else
				$('#cacheDialog').css('display','block');
		}, false);

		window.applicationCache.addEventListener('obsolete', function(e)
		{
			if(!isUserLogged)
				window.location.reload();
			else
				$('#cacheDialog').css('display','block');
		}, false);

		window.applicationCache.addEventListener('noupdate', function(e)
		{
			if(!isUserLogged)
			{
				clearInterval(globalCacheUpdateInterval);
				globalCacheUpdateInterval=setInterval(function(){window.applicationCache.update();}, 300000);
				//$('#LoginPage .window').css('display', 'inline-block');
			}
		}, false);
	};
}, false);
bgstack15