-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathhldm-cache-split.html
86 lines (80 loc) · 3.08 KB
/
hldm-cache-split.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html manifest="hldm-split-1.appcache">
<body onerror="alert(event)">
<script>
var parts = [];
var partcount = 0;
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
if( !parent )
document.write("This must be loaded as frame!");
var Module = parent.window.Module;
var appCache = window.applicationCache;
var mounted = false;
var packageName = 'hldm-split.zip.part1';
function partCb( part, buf)
{
parts[part] = buf;
partcount++;
if(partcount == 2)
{
var newbuf = Uint8Array(parts[0].byteLength+parts[1].byteLength);
newbuf.set( new Uint8Array(parts[0]),0);
newbuf.set( new Uint8Array(parts[1]),parts[0].byteLength);
parent.window.mountZIP(newbuf);
parent.window.savedRun();
}
}
function mountCache()
{
if( mounted ) return;
mounted = true;
Module.setStatus('Preparing part1');
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onerror = function(event) {
throw new Error("NetworkError");
parent.window.offlineCacheFallback()
}
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
partCb(0,xhr.response);
var el = document.createElement('iframe');
el.src = 'hldm-cache-split2.html';
el.style.display = 'none';
document.body.appendChild(el);
} else {
Module.print(xhr.statusText + " : " + xhr.responseURL);
parent.window.offlineCacheFallback();
}
};
xhr.send(null);
}
if( appCache )
{
var initState = appCache.status;
if( initState == 1 || initState == 2 || initState == 4 )
mountCache();
else
Module.setStatus('Cache not ready!');
Module.print("appCache status: "+ appCache.status);
appCache.addEventListener('cached', function(e) {Module.print('Appcache cached, status:' + appCache.status);mountCache();}, false);
appCache.addEventListener('downloading', function(e) {Module.setStatus('Starting download offline cache');
Module.print('Appcache downloading, status:' + appCache.status)}, false);
appCache.addEventListener('progress', function(e) {Module.setStatus('Downloading offline cache');Module.print('Appcache progress, status:' + appCache.status); if(initState != 0 && appCache.status == 0) Module.print("appCache error detected");}, false);
appCache.addEventListener('updateready', function(e) {Module.print('Appcache updateready, status:' + appCache.status);mountCache();}, false);
appCache.addEventListener('error', function(e) {Module.setStatus('Error: failed to activate caching!');parent.window.offlineCacheFallback();}, false);
appCache.addEventListener('checking', function(e) {Module.print('Appcache checking, status:' + appCache.status); if( appCache.status == 2 ) mountCache();}, false);
}
else
{
Module.print("appCache not supported!");
parent.window.offlineCacheFallback();
}
</script>
</body>
</html>