-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathembed.html
115 lines (91 loc) · 3.72 KB
/
embed.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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style> </style>
<script src="progress.js"></script>
<script src="timer.js"></script>
<script>
//xxx: do it right
function connect(node,event,fnc) {
node[event] = fnc;
}
function disconnect(node,event) {
node[event] = null;
}
function apos(node) {
var offsetX = 0;
var offsetY = 0;
var cn = node;
do {
offsetX += cn.offsetLeft;
offsetY += cn.offsetTop;
}while ((cn = cn.parentNode) !=null && cn.nodeName.toLowerCase() != "html");
return {
left : offsetX,
top : offsetY
};
}
function init_monitor() {
var root = document.createElement("div");
var style = root.style;
style.position = "absolute";
var progressNode = root.appendChild( document.createElement("div") );
document.body.appendChild( root );
connect( root, 'onmousedown', function(e) {
var mouseLeft = e.clientX;
var mouseTop = e.clientY;
var elPos = apos(root);
var oleft = mouseLeft - elPos.left;
var otop = mouseTop - elPos.top;
connect( document, 'onmousemove', function(e) {
var top = e.clientY,
left = e.clientX,
style = root.style;
style.left = (left - oleft) + "px";
style.top = (top - otop ) + "px";
});
connect( document,'onmouseup', function() {
disconnect( document, 'onmouseup' );
disconnect( document, 'onmousemove' );
});
});
progress.build( progressNode );
var textNode = document.createElement("div");
var style = textNode.style;
style.position = "absolute";
style.left = "2px";
style.top = "2px";
style.color = "white";
style.fontSize = "10px";
style.cursor = "pointer";
textNode.innerHTML = "Click to Start";
root.appendChild( textNode );
var running = false;
var calibrated = false;
connect(textNode,'onclick', function clicker() {
if (calibrated) {
if (running) {
progress.stop();
textNode.innerHTML = "Start";
} else {
progress.collect();
textNode.innerHTML = "Stop";
}
running = !running;
} else {
textNode.innerHTML = "Calibrating";
timer.callibrate(function() {
document.body.appendChild(document.createTextNode("baseline" + topline + " :" + bottomline ));
calibrated = true;
clicker();
});
}
});
}
</script>
</head>
<body>
<button onclick="init_monitor()">Init monitor</button>
Testing embed:
</body>
</html>