-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock.html
53 lines (49 loc) · 1.21 KB
/
mock.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
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body style="background: #eee">
Test:
<ul id="equations"></ul>
<script type="text/javascript">
function receiveMessage(event) {
var evt;
try {
evt = JSON.parse(event.data);
} catch (ex) {}
if (!evt) return;
if (api[evt.name]) {
api[evt.name](evt.data, function () {
if (evt.id) {
event.source.postMessage(JSON.stringify({equationIO: 1, ack: 1, id: evt.id, args: arguments}), event.origin);
}
});
}
}
var ul = document.getElementById('equations');
var api = {
init: function (data, done) {
setTimeout(done, 500);
},
'api.v1.payload': function (data, done) {
data.forEach(function (msg) {
updatesAPI[msg.name](msg.data);
});
done();
},
'api.v1.update': function (data, done) {
while(ul.firstChild) {
ul.removeChild(ul.firstChild);
}
data.equations.forEach(function (eq) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(JSON.stringify(eq)));
ul.appendChild(li);
});
}
};
window.addEventListener('message', receiveMessage, false);
</script>
</body>
</html>