-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcontrols.js
74 lines (57 loc) · 1.54 KB
/
controls.js
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
function Controls (controls, options)
{
var speedometer = options.speedometer;
if (!speedometer) throw ('Please pass the speedometer object to the controls constructor');
var controls = document.getElementById(controls); // TODO use .querySelector
if (!controls) throw ('No controls container found');
var update = controls.querySelector('[name=update]');
var mode_incr = controls.querySelector ('[name=mode][value=incremental]'),
mode_rand = controls.querySelector ('[name=mode][value=random]');
var rescale = controls.querySelector ('[name=rescale]'),
maxvalue = controls.querySelector ('[name=maxvalue]');
// Animated update
//
var start_update = function ()
{
if (mode_incr.checked)
incrementalUpdate (speedometer);
else if (mode_rand.checked)
randomUpdate (speedometer);
update.value = 'stop';
}
var stop_update = function ()
{
stopAnimation (speedometer);
update.value = 'start';
}
var updating = function ()
{
return update.value == 'stop';
}
this.start = start_update;
update.onclick = function () {
if (updating ())
stop_update ();
else
start_update ();
}
mode_incr.onchange = mode_rand.onchange = function ()
{
if (updating ())
{
stop_update ();
start_update ();
}
}
// Animated Rescale
//
rescale.onclick = function ()
{
var max = parseInt (maxvalue.value);
if (max == speedometer.max ())
return;
if (updating ())
stop_update ();
speedometer.animatedRescale (max, 2000);
}
}