-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
131 lines (110 loc) · 2.84 KB
/
index.html
File metadata and controls
131 lines (110 loc) · 2.84 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
<head>
<style>
#l {
width:100px;
height:100px;
background:orange;
position:absolute;
top:0;left:0;
}
</style>
</head>
<body>
<div id="l"></div>
</body>
</html>
<script type="text/worker" id="worker-xhr">
var xhrs = [];
function onComplete(xhr) {
for (var i = 0, l = xhrs.length; i < l; i++) {
if (xhrs[i].src == xhr.responseURL) {
xhrs.splice(i, 1);
postMessage(JSON.parse(JSON.stringify({proxy : "oncomplete", data: {response: xhr.response, src: xhr.responseURL }})));
break;
}
}
}
function onAbort(event) {
i = xhrs.length;
while (i--) {
if(xhrs[i].src == event.file.src) {
xhrs[i].xhr.abort();
xhrs.splice(i, 1)
}
}
}
self.addEventListener('message', function(e) {
switch (e.data.proxy) {
case "load":
var xhr = new XHRRequest(e.data.data.src, onComplete).xhr;
xhrs.push({ src: e.data.data.src, xhr: xhr })
break;
case "abort":
onAbort(e.data);
break;
}
}, false);
function XHRRequest(url, callback) {
this.xhr = new XMLHttpRequest();
this.callback = callback;
this.xhr.onprogress = this.handleProgress.bind(this);
this.xhr.onload = this.handleLoad.bind(this);
this.xhr.onabort = this.handleAbort.bind(this);
this.xhr.open("GET", url);
this.xhr.send(null);
}
XHRRequest.prototype.handleProgress = function(event) {
obj = JSON.parse(JSON.stringify({proxy : "onprogress", data: {loaded: event.loaded, total: event.total, src: event.target.responseURL }}));
postMessage(obj);
}
XHRRequest.prototype.handleAbort = function() {
this.clean();
}
XHRRequest.prototype.clean = function() {
this.xhr.onload = null;
this.xhr.onabort = null;
this.xhr.onprogress = null;
this.callback = null;
this.xhr = null;
}
XHRRequest.prototype.handleLoad = function(event) {
if(this.xhr.readyState < 4 || this.xhr.status !== 200) {
this.clean();
return;
}
if(this.xhr.readyState === 4 && this.callback) {
this.callback(this.xhr);
this.clean();
}
}
</script>
<script type="text/javascript" src="WebWorkerUtils.js" ></script>
<script type="text/javascript" src="MM.loader.js" ></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js" ></script>
<script type="text/javascript">
// absolute paths
var absPath = window.location.href;
var files = [
{src: absPath + "sample.yml"},
{src: absPath + "16384.rnd"}
];
var files2 = [
{src: absPath + "sample.json"},
{src: absPath + "sample.txt"}
];
var loader = new MM.Loader();
loader.load(files2);
loader.load(files, true);
loader.onFileLoad = function(event) {
console.log(event);
}
loader.onProgress = function(event) {
console.log(event);
}
loader.onComplete = function(event) {
console.log("complete");
}
TweenMax.to(document.getElementById('l'), 15, { x: window.innerWidth, y: window.innerHeight });
</script>