-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (59 loc) · 1.72 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" manifest="cache.manifest">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="vendor/components/jquery/jquery.min.js"></script>
<script type="text/javascript" src="lib/persist-js/persist-min.js"></script>
<script>
var online = null;
var store;
function logAdd(text){
var td = $('<td>');
td.html(text);
var tr = $('<tr>');
tr.append(td);
var table = $('#log');
table.prepend(tr);
}
$(document).ready(function(){
if(typeof(Storage) !== 'undefined'){
store = new Persist.Store('App1');
var k1val = store.get('key1');
console.log(k1val);
if(k1val == null){
var d = new Date();
store.set('key1', 'val1 ' + d);
}
}
else{
logAdd('ERROR: Storage not available.');
return;
}
$('#button1').click(function(){
logAdd('Click');
if(online){
$.get('data.php', function(data){
logAdd('Request done: ' + data.date);
});
}
else{
// Store values with 'store'.
logAdd('You are offline. Nothing has been sent to the server.');
}
});
window.addEventListener('offline', function(event){ logAdd('Offline'); online = false; }, false);
window.addEventListener('online', function(event){ logAdd('Online'); online = true; }, false);
online = navigator.onLine;
logAdd('Loaded: ' + (online ? 'Online' : 'Offline'));
});
</script>
<title>Offline Storage</title>
</head>
<body>
<p><button id="button1">Test</button></p>
<p><a href="deeplink.html">Deeplink</a></p>
<table id="log">
<tr><td>Log</td></tr>
</table>
</body>
</html>