-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.html
94 lines (90 loc) · 2.72 KB
/
popup.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
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="/css/popup.css">
<script type='text/javascript' src='/js/shared.js'></script>
<script type='text/javascript' src='/js/runner_factory.js'></script>
<script>
// The background page is needed since it hosts the plugin.
var bkg = chrome.extension.getBackgroundPage();
var haptics = bkg.plugin;
var renderer = null;
var factory = null;
var examples = {
'Free Style' : '/js/free_style_runner.js',
'Virtual Sphere' : '/js/virtual_sphere_runner.js',
'Virtual Wall' : '/js/virtual_wall_runner.js',
'Virtual Tracking' : '/js/virtual_tracking_runner.js'
};
/**
* Haptics device Controller.
* @param {string} method The method to trigger.
*/
function controller(method) {
switch (method) {
case 'startDevice':
haptics.startDevice();
break;
case 'stopDevice':
haptics.stopDevice();
break;
case 'runProgram':
factory.run(document.getElementById('runners').value);
break;
case 'stopProgram':
factory.stop();
break;
case 'runDemo':
bkg.openSingletonPage('demo.html');
break;
default:
bkg.console.error('Controller method not defined.');
}
}
/**
* Creates the dom for the runner options.
* @param {string} name The name of the element.
* @returns {HTMLElement} The option.
*/
function createRunnerOption(name) {
var option = document.createElement('option');
option.text = name;
option.value = name;
return option;
}
/**
* Initialize when window is shown.
*/
function init() {
// We need to register the renderer canvas and factory right after dom loaded.
renderer = document.getElementById('renderer');
factory = new RunnerFactory(haptics, renderer);
factory.register(examples);
// Fill up the available examples.
var runner_array = factory.list();
var runner_element = document.getElementById('runners');
for (var i = 0; i < runner_array.length; i++) {
runner_element.add(createRunnerOption(runner_array[i]));
}
}
</script>
<body onload="init()">
<h2>Haptics Controller</h2>
<div class="command-group" id="device-group">
<label>Device: </label>
<button onclick="controller('startDevice')">Start</button>
<button onclick="controller('stopDevice')">Stop</button>
</div>
<div class="command-group" id="process-group">
<label>Program: </label>
<select id="runners"></select>
<br />
<button onclick="controller('runProgram')">Run</button>
<button onclick="controller('stopProgram')">Stop</button>
<button onclick="controller('runDemo')">Demo</button>
</div>
<div class="command-group" id="renderer-group">
<label>Renderer: </label>
<canvas id="renderer" width="250px" height="250px"></canvas>
</div>
</body>
</html>