nickjillings@1563
|
1 /**
|
nickjillings@1563
|
2 * core.js
|
nickjillings@1563
|
3 *
|
nickjillings@1563
|
4 * Main script to run, calls all other core functions and manages loading/store to backend.
|
nickjillings@1563
|
5 * Also contains all global variables.
|
nickjillings@1563
|
6 */
|
nickjillings@1563
|
7
|
nickjillings@1563
|
8 /* create the web audio API context and store in audioContext*/
|
nickjillings@1563
|
9 var audioContext; // Hold the browser web audio API
|
nickjillings@1563
|
10 var projectXML; // Hold the parsed setup XML
|
nickjillings@1563
|
11 var specification;
|
nickjillings@1563
|
12 var interfaceContext;
|
nickjillings@1563
|
13 var popup; // Hold the interfacePopup object
|
nickjillings@1563
|
14 var testState;
|
nickjillings@1563
|
15 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
|
nickjillings@1563
|
16 var audioEngineContext; // The custome AudioEngine object
|
nickjillings@1563
|
17 var projectReturn; // Hold the URL for the return
|
nickjillings@1563
|
18
|
nickjillings@1563
|
19
|
nickjillings@1563
|
20 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
|
nickjillings@1563
|
21 AudioBufferSourceNode.prototype.owner = undefined;
|
nickjillings@1563
|
22
|
nickjillings@1563
|
23 window.onload = function() {
|
nickjillings@1563
|
24 // Function called once the browser has loaded all files.
|
nickjillings@1563
|
25 // This should perform any initial commands such as structure / loading documents
|
nickjillings@1563
|
26
|
nickjillings@1563
|
27 // Create a web audio API context
|
nickjillings@1563
|
28 // Fixed for cross-browser support
|
nickjillings@1563
|
29 var AudioContext = window.AudioContext || window.webkitAudioContext;
|
nickjillings@1563
|
30 audioContext = new AudioContext;
|
nickjillings@1563
|
31
|
nickjillings@1563
|
32 // Create test state
|
nickjillings@1563
|
33 testState = new stateMachine();
|
nickjillings@1563
|
34
|
nickjillings@1563
|
35 // Create the audio engine object
|
nickjillings@1563
|
36 audioEngineContext = new AudioEngine();
|
nickjillings@1563
|
37
|
nickjillings@1563
|
38 // Create the popup interface object
|
nickjillings@1563
|
39 popup = new interfacePopup();
|
nickjillings@1563
|
40
|
nickjillings@1563
|
41 // Create the specification object
|
nickjillings@1563
|
42 specification = new Specification();
|
nickjillings@1563
|
43
|
nickjillings@1563
|
44 // Create the interface object
|
nickjillings@1563
|
45 interfaceContext = new Interface(specification);
|
nickjillings@1563
|
46 };
|
nickjillings@1563
|
47
|
nickjillings@1563
|
48 function interfacePopup() {
|
nickjillings@1563
|
49 // Creates an object to manage the popup
|
nickjillings@1563
|
50 this.popup = null;
|
nickjillings@1563
|
51 this.popupContent = null;
|
nickjillings@1563
|
52 this.buttonProceed = null;
|
nickjillings@1563
|
53 this.buttonPrevious = null;
|
nickjillings@1563
|
54 this.popupOptions = null;
|
nickjillings@1563
|
55 this.currentIndex = null;
|
nickjillings@1563
|
56 this.responses = null;
|
nickjillings@1563
|
57
|
nickjillings@1563
|
58 this.createPopup = function(){
|
nickjillings@1563
|
59 // Create popup window interface
|
nickjillings@1563
|
60 var insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1563
|
61 var blank = document.createElement('div');
|
nickjillings@1563
|
62 blank.className = 'testHalt';
|
nickjillings@1563
|
63
|
nickjillings@1563
|
64 this.popup = document.createElement('div');
|
nickjillings@1563
|
65 this.popup.id = 'popupHolder';
|
nickjillings@1563
|
66 this.popup.className = 'popupHolder';
|
nickjillings@1563
|
67 this.popup.style.position = 'absolute';
|
nickjillings@1563
|
68 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
|
nickjillings@1563
|
69 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
|
nickjillings@1563
|
70
|
nickjillings@1563
|
71 this.popupContent = document.createElement('div');
|
nickjillings@1563
|
72 this.popupContent.id = 'popupContent';
|
nickjillings@1563
|
73 this.popupContent.style.marginTop = '25px';
|
nickjillings@1563
|
74 this.popupContent.align = 'center';
|
nickjillings@1563
|
75 this.popup.appendChild(this.popupContent);
|
nickjillings@1563
|
76
|
nickjillings@1563
|
77 this.buttonProceed = document.createElement('button');
|
nickjillings@1563
|
78 this.buttonProceed.className = 'popupButton';
|
nickjillings@1563
|
79 this.buttonProceed.style.left = '440px';
|
nickjillings@1563
|
80 this.buttonProceed.style.top = '215px';
|
nickjillings@1563
|
81 this.buttonProceed.innerHTML = 'Next';
|
nickjillings@1563
|
82 this.buttonProceed.onclick = function(){popup.proceedClicked();};
|
nickjillings@1563
|
83
|
nickjillings@1563
|
84 this.buttonPrevious = document.createElement('button');
|
nickjillings@1563
|
85 this.buttonPrevious.className = 'popupButton';
|
nickjillings@1563
|
86 this.buttonPrevious.style.left = '10px';
|
nickjillings@1563
|
87 this.buttonPrevious.style.top = '215px';
|
nickjillings@1563
|
88 this.buttonPrevious.innerHTML = 'Back';
|
nickjillings@1563
|
89 this.buttonPrevious.onclick = function(){popup.previousClick();};
|
nickjillings@1563
|
90
|
nickjillings@1563
|
91 this.popup.style.zIndex = -1;
|
nickjillings@1563
|
92 this.popup.style.visibility = 'hidden';
|
nickjillings@1563
|
93 blank.style.zIndex = -2;
|
nickjillings@1563
|
94 blank.style.visibility = 'hidden';
|
nickjillings@1563
|
95 insertPoint.appendChild(this.popup);
|
nickjillings@1563
|
96 insertPoint.appendChild(blank);
|
nickjillings@1563
|
97 };
|
nickjillings@1563
|
98
|
nickjillings@1563
|
99 this.showPopup = function(){
|
nickjillings@1563
|
100 if (this.popup == null) {
|
nickjillings@1563
|
101 this.createPopup();
|
nickjillings@1563
|
102 }
|
nickjillings@1563
|
103 this.popup.style.zIndex = 3;
|
nickjillings@1563
|
104 this.popup.style.visibility = 'visible';
|
nickjillings@1563
|
105 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1563
|
106 blank.style.zIndex = 2;
|
nickjillings@1563
|
107 blank.style.visibility = 'visible';
|
nickjillings@1563
|
108 };
|
nickjillings@1563
|
109
|
nickjillings@1563
|
110 this.hidePopup = function(){
|
nickjillings@1563
|
111 this.popup.style.zIndex = -1;
|
nickjillings@1563
|
112 this.popup.style.visibility = 'hidden';
|
nickjillings@1563
|
113 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1563
|
114 blank.style.zIndex = -2;
|
nickjillings@1563
|
115 blank.style.visibility = 'hidden';
|
nickjillings@1563
|
116 };
|
nickjillings@1563
|
117
|
nickjillings@1563
|
118 this.postNode = function() {
|
nickjillings@1563
|
119 // This will take the node from the popupOptions and display it
|
nickjillings@1563
|
120 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1563
|
121 this.popupContent.innerHTML = null;
|
nickjillings@1563
|
122 if (node.type == 'statement') {
|
nickjillings@1563
|
123 var span = document.createElement('span');
|
nickjillings@1563
|
124 span.textContent = node.statement;
|
nickjillings@1563
|
125 this.popupContent.appendChild(span);
|
nickjillings@1563
|
126 } else if (node.type == 'question') {
|
nickjillings@1563
|
127 var span = document.createElement('span');
|
nickjillings@1563
|
128 span.textContent = node.question;
|
nickjillings@1563
|
129 var textArea = document.createElement('textarea');
|
nickjillings@1563
|
130 switch (node.boxsize) {
|
nickjillings@1563
|
131 case 'small':
|
nickjillings@1563
|
132 textArea.cols = "20";
|
nickjillings@1563
|
133 textArea.rows = "1";
|
nickjillings@1563
|
134 break;
|
nickjillings@1563
|
135 case 'normal':
|
nickjillings@1563
|
136 textArea.cols = "30";
|
nickjillings@1563
|
137 textArea.rows = "2";
|
nickjillings@1563
|
138 break;
|
nickjillings@1563
|
139 case 'large':
|
nickjillings@1563
|
140 textArea.cols = "40";
|
nickjillings@1563
|
141 textArea.rows = "5";
|
nickjillings@1563
|
142 break;
|
nickjillings@1563
|
143 case 'huge':
|
nickjillings@1563
|
144 textArea.cols = "50";
|
nickjillings@1563
|
145 textArea.rows = "10";
|
nickjillings@1563
|
146 break;
|
nickjillings@1563
|
147 }
|
nickjillings@1563
|
148 var br = document.createElement('br');
|
nickjillings@1563
|
149 this.popupContent.appendChild(span);
|
nickjillings@1563
|
150 this.popupContent.appendChild(br);
|
nickjillings@1563
|
151 this.popupContent.appendChild(textArea);
|
nickjillings@1563
|
152 this.popupContent.childNodes[2].focus();
|
nickjillings@1563
|
153 } else if (node.type == 'checkbox') {
|
nickjillings@1563
|
154 var span = document.createElement('span');
|
nickjillings@1563
|
155 span.textContent = node.statement;
|
nickjillings@1563
|
156 this.popupContent.appendChild(span);
|
nickjillings@1563
|
157 var optHold = document.createElement('div');
|
nickjillings@1563
|
158 optHold.id = 'option-holder';
|
nickjillings@1563
|
159 optHold.align = 'left';
|
nickjillings@1563
|
160 for (var i=0; i<node.options.length; i++) {
|
nickjillings@1563
|
161 var option = node.options[i];
|
nickjillings@1563
|
162 var input = document.createElement('input');
|
nickjillings@1563
|
163 input.id = option.id;
|
nickjillings@1563
|
164 input.type = 'checkbox';
|
nickjillings@1563
|
165 var span = document.createElement('span');
|
nickjillings@1563
|
166 span.textContent = option.text;
|
nickjillings@1563
|
167 var hold = document.createElement('div');
|
nickjillings@1563
|
168 hold.setAttribute('name','option');
|
nickjillings@1563
|
169 hold.style.float = 'left';
|
nickjillings@1563
|
170 hold.style.padding = '4px';
|
nickjillings@1563
|
171 hold.appendChild(input);
|
nickjillings@1563
|
172 hold.appendChild(span);
|
nickjillings@1563
|
173 optHold.appendChild(hold);
|
nickjillings@1563
|
174 }
|
nickjillings@1563
|
175 this.popupContent.appendChild(optHold);
|
nickjillings@1563
|
176 } else if (node.type == 'radio') {
|
nickjillings@1563
|
177 var span = document.createElement('span');
|
nickjillings@1563
|
178 span.textContent = node.statement;
|
nickjillings@1563
|
179 this.popupContent.appendChild(span);
|
nickjillings@1563
|
180 var optHold = document.createElement('div');
|
nickjillings@1563
|
181 optHold.id = 'option-holder';
|
nickjillings@1563
|
182 optHold.align = 'none';
|
nickjillings@1563
|
183 optHold.style.float = 'left';
|
nickjillings@1563
|
184 optHold.style.width = "100%";
|
nickjillings@1563
|
185 for (var i=0; i<node.options.length; i++) {
|
nickjillings@1563
|
186 var option = node.options[i];
|
nickjillings@1563
|
187 var input = document.createElement('input');
|
nickjillings@1563
|
188 input.id = option.name;
|
nickjillings@1563
|
189 input.type = 'radio';
|
nickjillings@1563
|
190 input.name = node.id;
|
nickjillings@1563
|
191 var span = document.createElement('span');
|
nickjillings@1563
|
192 span.textContent = option.text;
|
nickjillings@1563
|
193 var hold = document.createElement('div');
|
nickjillings@1563
|
194 hold.setAttribute('name','option');
|
nickjillings@1563
|
195 hold.style.padding = '4px';
|
nickjillings@1563
|
196 hold.appendChild(input);
|
nickjillings@1563
|
197 hold.appendChild(span);
|
nickjillings@1563
|
198 optHold.appendChild(hold);
|
nickjillings@1563
|
199 }
|
nickjillings@1563
|
200 this.popupContent.appendChild(optHold);
|
nickjillings@1563
|
201 } else if (node.type == 'number') {
|
nickjillings@1563
|
202 var span = document.createElement('span');
|
nickjillings@1563
|
203 span.textContent = node.statement;
|
nickjillings@1563
|
204 this.popupContent.appendChild(span);
|
nickjillings@1563
|
205 this.popupContent.appendChild(document.createElement('br'));
|
nickjillings@1563
|
206 var input = document.createElement('input');
|
nickjillings@1563
|
207 input.type = 'number';
|
nickjillings@1563
|
208 if (node.min != null) {input.min = node.min;}
|
nickjillings@1563
|
209 if (node.max != null) {input.max = node.max;}
|
nickjillings@1563
|
210 if (node.step != null) {input.step = node.step;}
|
nickjillings@1563
|
211 this.popupContent.appendChild(input);
|
nickjillings@1563
|
212 }
|
nickjillings@1563
|
213 this.popupContent.appendChild(this.buttonProceed);
|
nickjillings@1563
|
214 if(this.currentIndex+1 == this.popupOptions.length) {
|
nickjillings@1563
|
215 this.buttonProceed.textContent = 'Submit';
|
nickjillings@1563
|
216 } else {
|
nickjillings@1563
|
217 this.buttonProceed.textContent = 'Next';
|
nickjillings@1563
|
218 }
|
nickjillings@1563
|
219 if(this.currentIndex > 0)
|
nickjillings@1563
|
220 this.popupContent.appendChild(this.buttonPrevious);
|
nickjillings@1563
|
221 };
|
nickjillings@1563
|
222
|
nickjillings@1563
|
223 this.initState = function(node) {
|
nickjillings@1563
|
224 //Call this with your preTest and postTest nodes when needed to
|
nickjillings@1563
|
225 // initialise the popup procedure.
|
nickjillings@1563
|
226 this.popupOptions = node.options;
|
nickjillings@1563
|
227 if (this.popupOptions.length > 0) {
|
nickjillings@1563
|
228 if (node.type == 'pretest') {
|
nickjillings@1563
|
229 this.responses = document.createElement('PreTest');
|
nickjillings@1563
|
230 } else if (node.type == 'posttest') {
|
nickjillings@1563
|
231 this.responses = document.createElement('PostTest');
|
nickjillings@1563
|
232 } else {
|
nickjillings@1563
|
233 console.log ('WARNING - popup node neither pre or post!');
|
nickjillings@1563
|
234 this.responses = document.createElement('responses');
|
nickjillings@1563
|
235 }
|
nickjillings@1563
|
236 this.currentIndex = 0;
|
nickjillings@1563
|
237 this.showPopup();
|
nickjillings@1563
|
238 this.postNode();
|
nickjillings@1563
|
239 } else {
|
nickjillings@1563
|
240 advanceState();
|
nickjillings@1563
|
241 }
|
nickjillings@1563
|
242 };
|
nickjillings@1563
|
243
|
nickjillings@1563
|
244 this.proceedClicked = function() {
|
nickjillings@1563
|
245 // Each time the popup button is clicked!
|
nickjillings@1563
|
246 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1563
|
247 if (node.type == 'question') {
|
nickjillings@1563
|
248 // Must extract the question data
|
nickjillings@1563
|
249 var textArea = $(popup.popupContent).find('textarea')[0];
|
nickjillings@1563
|
250 if (node.mandatory == true && textArea.value.length == 0) {
|
nickjillings@1563
|
251 alert('This question is mandatory');
|
nickjillings@1563
|
252 return;
|
nickjillings@1563
|
253 } else {
|
nickjillings@1563
|
254 // Save the text content
|
nickjillings@1563
|
255 var hold = document.createElement('comment');
|
nickjillings@1563
|
256 hold.id = node.id;
|
nickjillings@1563
|
257 hold.innerHTML = textArea.value;
|
nickjillings@1563
|
258 console.log("Question: "+ node.question);
|
nickjillings@1563
|
259 console.log("Question Response: "+ textArea.value);
|
nickjillings@1563
|
260 this.responses.appendChild(hold);
|
nickjillings@1563
|
261 }
|
nickjillings@1563
|
262 } else if (node.type == 'checkbox') {
|
nickjillings@1563
|
263 // Must extract checkbox data
|
nickjillings@1563
|
264 var optHold = document.getElementById('option-holder');
|
nickjillings@1563
|
265 var hold = document.createElement('checkbox');
|
nickjillings@1563
|
266 console.log("Checkbox: "+ node.statement);
|
nickjillings@1563
|
267 hold.id = node.id;
|
nickjillings@1563
|
268 for (var i=0; i<optHold.childElementCount; i++) {
|
nickjillings@1563
|
269 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
|
nickjillings@1563
|
270 var statement = optHold.childNodes[i].getElementsByTagName('span')[0];
|
nickjillings@1563
|
271 var response = document.createElement('option');
|
nickjillings@1563
|
272 response.setAttribute('name',input.id);
|
nickjillings@1563
|
273 response.textContent = input.checked;
|
nickjillings@1563
|
274 hold.appendChild(response);
|
nickjillings@1563
|
275 console.log(input.id +': '+ input.checked);
|
nickjillings@1563
|
276 }
|
nickjillings@1563
|
277 this.responses.appendChild(hold);
|
nickjillings@1563
|
278 } else if (node.type == "radio") {
|
nickjillings@1563
|
279 var optHold = document.getElementById('option-holder');
|
nickjillings@1563
|
280 var hold = document.createElement('radio');
|
nickjillings@1563
|
281 var responseID = null;
|
nickjillings@1563
|
282 var i=0;
|
nickjillings@1563
|
283 while(responseID == null) {
|
nickjillings@1563
|
284 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
|
nickjillings@1563
|
285 if (input.checked == true) {
|
nickjillings@1563
|
286 responseID = i;
|
nickjillings@1563
|
287 }
|
nickjillings@1563
|
288 i++;
|
nickjillings@1563
|
289 }
|
nickjillings@1563
|
290 hold.id = node.id;
|
nickjillings@1563
|
291 hold.setAttribute('name',node.options[responseID].name);
|
nickjillings@1563
|
292 hold.textContent = node.options[responseID].text;
|
nickjillings@1563
|
293 this.responses.appendChild(hold);
|
nickjillings@1563
|
294 } else if (node.type == "number") {
|
nickjillings@1563
|
295 var input = this.popupContent.getElementsByTagName('input')[0];
|
nickjillings@1563
|
296 if (node.mandatory == true && input.value.length == 0) {
|
nickjillings@1563
|
297 alert('This question is mandatory. Please enter a number');
|
nickjillings@1563
|
298 return;
|
nickjillings@1563
|
299 }
|
nickjillings@1563
|
300 var enteredNumber = Number(input.value);
|
nickjillings@1563
|
301 if (enteredNumber == undefined) {
|
nickjillings@1563
|
302 alert('Please enter a valid number');
|
nickjillings@1563
|
303 return;
|
nickjillings@1563
|
304 }
|
nickjillings@1563
|
305 if (enteredNumber < node.min && node.min != null) {
|
nickjillings@1563
|
306 alert('Number is below the minimum value of '+node.min);
|
nickjillings@1563
|
307 return;
|
nickjillings@1563
|
308 }
|
nickjillings@1563
|
309 if (enteredNumber > node.max && node.max != null) {
|
nickjillings@1563
|
310 alert('Number is above the maximum value of '+node.max);
|
nickjillings@1563
|
311 return;
|
nickjillings@1563
|
312 }
|
nickjillings@1563
|
313 var hold = document.createElement('number');
|
nickjillings@1563
|
314 hold.id = node.id;
|
nickjillings@1563
|
315 hold.textContent = input.value;
|
nickjillings@1563
|
316 this.responses.appendChild(hold);
|
nickjillings@1563
|
317 }
|
nickjillings@1563
|
318 this.currentIndex++;
|
nickjillings@1563
|
319 if (this.currentIndex < this.popupOptions.length) {
|
nickjillings@1563
|
320 this.postNode();
|
nickjillings@1563
|
321 } else {
|
nickjillings@1563
|
322 // Reached the end of the popupOptions
|
nickjillings@1563
|
323 this.hidePopup();
|
nickjillings@1563
|
324 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) {
|
nickjillings@1563
|
325 testState.stateResults[testState.stateIndex] = this.responses;
|
nickjillings@1563
|
326 } else {
|
nickjillings@1563
|
327 testState.stateResults[testState.stateIndex].appendChild(this.responses);
|
nickjillings@1563
|
328 }
|
nickjillings@1563
|
329 advanceState();
|
nickjillings@1563
|
330 }
|
nickjillings@1563
|
331 };
|
nickjillings@1563
|
332
|
nickjillings@1563
|
333 this.previousClick = function() {
|
nickjillings@1563
|
334 // Triggered when the 'Back' button is clicked in the survey
|
nickjillings@1563
|
335 if (this.currentIndex > 0) {
|
nickjillings@1563
|
336 this.currentIndex--;
|
nickjillings@1563
|
337 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1563
|
338 if (node.type != 'statement') {
|
nickjillings@1563
|
339 var prevResp = this.responses.childNodes[this.responses.childElementCount-1];
|
nickjillings@1563
|
340 this.responses.removeChild(prevResp);
|
nickjillings@1563
|
341 }
|
nickjillings@1563
|
342 this.postNode();
|
nickjillings@1563
|
343 if (node.type == 'question') {
|
nickjillings@1563
|
344 this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent;
|
nickjillings@1563
|
345 } else if (node.type == 'checkbox') {
|
nickjillings@1563
|
346 var options = this.popupContent.getElementsByTagName('input');
|
nickjillings@1563
|
347 var savedOptions = prevResp.getElementsByTagName('option');
|
nickjillings@1563
|
348 for (var i=0; i<options.length; i++) {
|
nickjillings@1563
|
349 var id = options[i].id;
|
nickjillings@1563
|
350 for (var j=0; j<savedOptions.length; j++) {
|
nickjillings@1563
|
351 if (savedOptions[j].getAttribute('name') == id) {
|
nickjillings@1563
|
352 if (savedOptions[j].textContent == 'true') {options[i].checked = true;}
|
nickjillings@1563
|
353 else {options[i].checked = false;}
|
nickjillings@1563
|
354 break;
|
nickjillings@1563
|
355 }
|
nickjillings@1563
|
356 }
|
nickjillings@1563
|
357 }
|
nickjillings@1563
|
358 } else if (node.type == 'number') {
|
nickjillings@1563
|
359 this.popupContent.getElementsByTagName('input')[0].value = prevResp.textContent;
|
nickjillings@1563
|
360 } else if (node.type == 'radio') {
|
nickjillings@1563
|
361 var options = this.popupContent.getElementsByTagName('input');
|
nickjillings@1563
|
362 var name = prevResp.getAttribute('name');
|
nickjillings@1563
|
363 for (var i=0; i<options.length; i++) {
|
nickjillings@1563
|
364 if (options[i].id == name) {
|
nickjillings@1563
|
365 options[i].checked = true;
|
nickjillings@1563
|
366 break;
|
nickjillings@1563
|
367 }
|
nickjillings@1563
|
368 }
|
nickjillings@1563
|
369 }
|
nickjillings@1563
|
370 }
|
nickjillings@1563
|
371 };
|
nickjillings@1563
|
372 }
|
nickjillings@1563
|
373
|
nickjillings@1563
|
374 function advanceState()
|
nickjillings@1563
|
375 {
|
nickjillings@1563
|
376 // Just for complete clarity
|
nickjillings@1563
|
377 testState.advanceState();
|
nickjillings@1563
|
378 }
|
nickjillings@1563
|
379
|
nickjillings@1563
|
380 function stateMachine()
|
nickjillings@1563
|
381 {
|
nickjillings@1563
|
382 // Object prototype for tracking and managing the test state
|
nickjillings@1563
|
383 this.stateMap = [];
|
nickjillings@1563
|
384 this.stateIndex = null;
|
nickjillings@1563
|
385 this.currentStateMap = [];
|
nickjillings@1563
|
386 this.currentIndex = null;
|
nickjillings@1563
|
387 this.currentTestId = 0;
|
nickjillings@1563
|
388 this.stateResults = [];
|
nickjillings@1563
|
389 this.timerCallBackHolders = null;
|
nickjillings@1563
|
390 this.initialise = function(){
|
nickjillings@1563
|
391 if (this.stateMap.length > 0) {
|
nickjillings@1563
|
392 if(this.stateIndex != null) {
|
nickjillings@1563
|
393 console.log('NOTE - State already initialise');
|
nickjillings@1563
|
394 }
|
nickjillings@1563
|
395 this.stateIndex = -1;
|
nickjillings@1563
|
396 var that = this;
|
nickjillings@1563
|
397 for (var id=0; id<this.stateMap.length; id++){
|
nickjillings@1563
|
398 var name = this.stateMap[id].type;
|
nickjillings@1563
|
399 var obj = document.createElement(name);
|
nickjillings@1563
|
400 if (name == 'audioHolder') {
|
nickjillings@1563
|
401 obj.id = this.stateMap[id].id;
|
nickjillings@1563
|
402 }
|
nickjillings@1563
|
403 this.stateResults.push(obj);
|
nickjillings@1563
|
404 }
|
nickjillings@1563
|
405 } else {
|
nickjillings@1563
|
406 conolse.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
|
nickjillings@1563
|
407 }
|
nickjillings@1563
|
408 };
|
nickjillings@1563
|
409 this.advanceState = function(){
|
nickjillings@1563
|
410 if (this.stateIndex == null) {
|
nickjillings@1563
|
411 this.initialise();
|
nickjillings@1563
|
412 }
|
nickjillings@1563
|
413 if (this.stateIndex == -1) {
|
nickjillings@1563
|
414 console.log('Starting test...');
|
nickjillings@1563
|
415 }
|
nickjillings@1563
|
416 if (this.currentIndex == null){
|
nickjillings@1563
|
417 if (this.currentStateMap.type == "audioHolder") {
|
nickjillings@1563
|
418 // Save current page
|
nickjillings@1563
|
419 this.testPageCompleted(this.stateResults[this.stateIndex],this.currentStateMap,this.currentTestId);
|
nickjillings@1563
|
420 this.currentTestId++;
|
nickjillings@1563
|
421 }
|
nickjillings@1563
|
422 this.stateIndex++;
|
nickjillings@1563
|
423 if (this.stateIndex >= this.stateMap.length) {
|
nickjillings@1563
|
424 console.log('Test Completed');
|
nickjillings@1563
|
425 createProjectSave(specification.projectReturn);
|
nickjillings@1563
|
426 } else {
|
nickjillings@1563
|
427 this.currentStateMap = this.stateMap[this.stateIndex];
|
nickjillings@1563
|
428 if (this.currentStateMap.type == "audioHolder") {
|
nickjillings@1563
|
429 console.log('Loading test page');
|
nickjillings@1563
|
430 loadTest(this.currentStateMap);
|
nickjillings@1563
|
431 this.initialiseInnerState(this.currentStateMap);
|
nickjillings@1563
|
432 } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") {
|
nickjillings@1563
|
433 if (this.currentStateMap.options.length >= 1) {
|
nickjillings@1563
|
434 popup.initState(this.currentStateMap);
|
nickjillings@1563
|
435 } else {
|
nickjillings@1563
|
436 this.advanceState();
|
nickjillings@1563
|
437 }
|
nickjillings@1563
|
438 } else {
|
nickjillings@1563
|
439 this.advanceState();
|
nickjillings@1563
|
440 }
|
nickjillings@1563
|
441 }
|
nickjillings@1563
|
442 } else {
|
nickjillings@1563
|
443 this.advanceInnerState();
|
nickjillings@1563
|
444 }
|
nickjillings@1563
|
445 };
|
nickjillings@1563
|
446
|
nickjillings@1563
|
447 this.testPageCompleted = function(store, testXML, testId) {
|
nickjillings@1563
|
448 // Function called each time a test page has been completed
|
nickjillings@1563
|
449 // Can be used to over-rule default behaviour
|
nickjillings@1563
|
450
|
nickjillings@1563
|
451 pageXMLSave(store, testXML);
|
nickjillings@1563
|
452 };
|
nickjillings@1563
|
453
|
nickjillings@1563
|
454 this.initialiseInnerState = function(node) {
|
nickjillings@1563
|
455 // Parses the received testXML for pre and post test options
|
nickjillings@1563
|
456 this.currentStateMap = [];
|
nickjillings@1563
|
457 var preTest = node.preTest;
|
nickjillings@1563
|
458 var postTest = node.postTest;
|
nickjillings@1563
|
459 if (preTest == undefined) {preTest = document.createElement("preTest");}
|
nickjillings@1563
|
460 if (postTest == undefined){postTest= document.createElement("postTest");}
|
nickjillings@1563
|
461 this.currentStateMap.push(preTest);
|
nickjillings@1563
|
462 this.currentStateMap.push(node);
|
nickjillings@1563
|
463 this.currentStateMap.push(postTest);
|
nickjillings@1563
|
464 this.currentIndex = -1;
|
nickjillings@1563
|
465 this.advanceInnerState();
|
nickjillings@1563
|
466 };
|
nickjillings@1563
|
467
|
nickjillings@1563
|
468 this.advanceInnerState = function() {
|
nickjillings@1563
|
469 this.currentIndex++;
|
nickjillings@1563
|
470 if (this.currentIndex >= this.currentStateMap.length) {
|
nickjillings@1563
|
471 this.currentIndex = null;
|
nickjillings@1563
|
472 this.currentStateMap = this.stateMap[this.stateIndex];
|
nickjillings@1563
|
473 this.advanceState();
|
nickjillings@1563
|
474 } else {
|
nickjillings@1563
|
475 if (this.currentStateMap[this.currentIndex].type == "audioHolder") {
|
nickjillings@1563
|
476 console.log("Loading test page"+this.currentTestId);
|
nickjillings@1563
|
477 } else if (this.currentStateMap[this.currentIndex].type == "pretest") {
|
nickjillings@1563
|
478 popup.initState(this.currentStateMap[this.currentIndex]);
|
nickjillings@1563
|
479 } else if (this.currentStateMap[this.currentIndex].type == "posttest") {
|
nickjillings@1563
|
480 popup.initState(this.currentStateMap[this.currentIndex]);
|
nickjillings@1563
|
481 } else {
|
nickjillings@1563
|
482 this.advanceInnerState();
|
nickjillings@1563
|
483 }
|
nickjillings@1563
|
484 }
|
nickjillings@1563
|
485 };
|
nickjillings@1563
|
486
|
nickjillings@1563
|
487 this.previousState = function(){};
|
nickjillings@1563
|
488 }
|
nickjillings@1563
|
489
|
nickjillings@1563
|
490 function testEnded(testId)
|
nickjillings@1563
|
491 {
|
nickjillings@1563
|
492 pageXMLSave(testId);
|
nickjillings@1563
|
493 if (testXMLSetups.length-1 > testId)
|
nickjillings@1563
|
494 {
|
nickjillings@1563
|
495 // Yes we have another test to perform
|
nickjillings@1563
|
496 testId = (Number(testId)+1);
|
nickjillings@1563
|
497 currentState = 'testRun-'+testId;
|
nickjillings@1563
|
498 loadTest(testId);
|
nickjillings@1563
|
499 } else {
|
nickjillings@1563
|
500 console.log('Testing Completed!');
|
nickjillings@1563
|
501 currentState = 'postTest';
|
nickjillings@1563
|
502 // Check for any post tests
|
nickjillings@1563
|
503 var xmlSetup = projectXML.find('setup');
|
nickjillings@1563
|
504 var postTest = xmlSetup.find('PostTest')[0];
|
nickjillings@1563
|
505 popup.initState(postTest);
|
nickjillings@1563
|
506 }
|
nickjillings@1563
|
507 }
|
nickjillings@1563
|
508
|
nickjillings@1563
|
509 function loadProjectSpec(url) {
|
nickjillings@1563
|
510 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
|
nickjillings@1563
|
511 // If url is null, request client to upload project XML document
|
nickjillings@1563
|
512 var r = new XMLHttpRequest();
|
nickjillings@1563
|
513 r.open('GET',url,true);
|
nickjillings@1563
|
514 r.onload = function() {
|
nickjillings@1563
|
515 loadProjectSpecCallback(r.response);
|
nickjillings@1563
|
516 };
|
nickjillings@1563
|
517 r.send();
|
nickjillings@1563
|
518 };
|
nickjillings@1563
|
519
|
nickjillings@1563
|
520 function loadProjectSpecCallback(response) {
|
nickjillings@1563
|
521 // Function called after asynchronous download of XML project specification
|
nickjillings@1563
|
522 //var decode = $.parseXML(response);
|
nickjillings@1563
|
523 //projectXML = $(decode);
|
nickjillings@1563
|
524
|
nickjillings@1563
|
525 var parse = new DOMParser();
|
nickjillings@1563
|
526 projectXML = parse.parseFromString(response,'text/xml');
|
nickjillings@1563
|
527
|
nickjillings@1563
|
528 // Build the specification
|
nickjillings@1563
|
529 specification.decode();
|
nickjillings@1563
|
530
|
nickjillings@1563
|
531 testState.stateMap.push(specification.preTest);
|
nickjillings@1563
|
532
|
nickjillings@1563
|
533 // New check if we need to randomise the test order
|
nickjillings@1563
|
534 if (specification.randomiseOrder)
|
nickjillings@1563
|
535 {
|
nickjillings@1563
|
536 specification.audioHolders = randomiseOrder(specification.audioHolders);
|
nickjillings@1563
|
537 }
|
nickjillings@1563
|
538
|
nickjillings@1563
|
539 $(specification.audioHolders).each(function(index,elem){
|
nickjillings@1563
|
540 testState.stateMap.push(elem);
|
nickjillings@1563
|
541 });
|
nickjillings@1563
|
542
|
nickjillings@1563
|
543 testState.stateMap.push(specification.postTest);
|
nickjillings@1563
|
544
|
nickjillings@1563
|
545 // Obtain the metrics enabled
|
nickjillings@1563
|
546 $(specification.metrics).each(function(index,node){
|
nickjillings@1563
|
547 var enabled = node.textContent;
|
nickjillings@1563
|
548 switch(node.enabled)
|
nickjillings@1563
|
549 {
|
nickjillings@1563
|
550 case 'testTimer':
|
nickjillings@1563
|
551 sessionMetrics.prototype.enableTestTimer = true;
|
nickjillings@1563
|
552 break;
|
nickjillings@1563
|
553 case 'elementTimer':
|
nickjillings@1563
|
554 sessionMetrics.prototype.enableElementTimer = true;
|
nickjillings@1563
|
555 break;
|
nickjillings@1563
|
556 case 'elementTracker':
|
nickjillings@1563
|
557 sessionMetrics.prototype.enableElementTracker = true;
|
nickjillings@1563
|
558 break;
|
nickjillings@1563
|
559 case 'elementListenTracker':
|
nickjillings@1563
|
560 sessionMetrics.prototype.enableElementListenTracker = true;
|
nickjillings@1563
|
561 break;
|
nickjillings@1563
|
562 case 'elementInitialPosition':
|
nickjillings@1563
|
563 sessionMetrics.prototype.enableElementInitialPosition = true;
|
nickjillings@1563
|
564 break;
|
nickjillings@1563
|
565 case 'elementFlagListenedTo':
|
nickjillings@1563
|
566 sessionMetrics.prototype.enableFlagListenedTo = true;
|
nickjillings@1563
|
567 break;
|
nickjillings@1563
|
568 case 'elementFlagMoved':
|
nickjillings@1563
|
569 sessionMetrics.prototype.enableFlagMoved = true;
|
nickjillings@1563
|
570 break;
|
nickjillings@1563
|
571 case 'elementFlagComments':
|
nickjillings@1563
|
572 sessionMetrics.prototype.enableFlagComments = true;
|
nickjillings@1563
|
573 break;
|
nickjillings@1563
|
574 }
|
nickjillings@1563
|
575 });
|
nickjillings@1563
|
576
|
nickjillings@1563
|
577
|
nickjillings@1563
|
578
|
nickjillings@1563
|
579 // Detect the interface to use and load the relevant javascripts.
|
nickjillings@1563
|
580 var interfaceJS = document.createElement('script');
|
nickjillings@1563
|
581 interfaceJS.setAttribute("type","text/javascript");
|
nickjillings@1563
|
582 if (specification.interfaceType == 'APE') {
|
nickjillings@1563
|
583 interfaceJS.setAttribute("src","ape.js");
|
nickjillings@1563
|
584
|
nickjillings@1563
|
585 // APE comes with a css file
|
nickjillings@1563
|
586 var css = document.createElement('link');
|
nickjillings@1563
|
587 css.rel = 'stylesheet';
|
nickjillings@1563
|
588 css.type = 'text/css';
|
nickjillings@1563
|
589 css.href = 'ape.css';
|
nickjillings@1563
|
590
|
nickjillings@1563
|
591 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1563
|
592 }
|
nickjillings@1563
|
593 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
|
nickjillings@1563
|
594
|
nickjillings@1563
|
595 // Define window callbacks for interface
|
nickjillings@1563
|
596 window.onresize = function(event){resizeWindow(event);};
|
nickjillings@1563
|
597 }
|
nickjillings@1563
|
598
|
nickjillings@1563
|
599 function createProjectSave(destURL) {
|
nickjillings@1563
|
600 // Save the data from interface into XML and send to destURL
|
nickjillings@1563
|
601 // If destURL is null then download XML in client
|
nickjillings@1563
|
602 // Now time to render file locally
|
nickjillings@1563
|
603 var xmlDoc = interfaceXMLSave();
|
nickjillings@1563
|
604 var parent = document.createElement("div");
|
nickjillings@1563
|
605 parent.appendChild(xmlDoc);
|
nickjillings@1563
|
606 var file = [parent.innerHTML];
|
nickjillings@1563
|
607 if (destURL == "null" || destURL == undefined) {
|
nickjillings@1563
|
608 var bb = new Blob(file,{type : 'application/xml'});
|
nickjillings@1563
|
609 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1563
|
610 var a = document.createElement("a");
|
nickjillings@1563
|
611 a.hidden = '';
|
nickjillings@1563
|
612 a.href = dnlk;
|
nickjillings@1563
|
613 a.download = "save.xml";
|
nickjillings@1563
|
614 a.textContent = "Save File";
|
nickjillings@1563
|
615
|
nickjillings@1563
|
616 popup.showPopup();
|
nickjillings@1563
|
617 popup.popupContent.innerHTML = null;
|
nickjillings@1563
|
618 popup.popupContent.appendChild(a);
|
nickjillings@1563
|
619 } else {
|
nickjillings@1563
|
620 var xmlhttp = new XMLHttpRequest;
|
nickjillings@1563
|
621 xmlhttp.open("POST",destURL,true);
|
nickjillings@1563
|
622 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
|
nickjillings@1563
|
623 xmlhttp.onerror = function(){
|
nickjillings@1563
|
624 console.log('Error saving file to server! Presenting download locally');
|
nickjillings@1563
|
625 createProjectSave(null);
|
nickjillings@1563
|
626 };
|
nickjillings@1563
|
627 xmlhttp.onreadystatechange = function() {
|
nickjillings@1563
|
628 console.log(xmlhttp.status);
|
nickjillings@1563
|
629 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
|
nickjillings@1563
|
630 createProjectSave(null);
|
nickjillings@1563
|
631 }
|
nickjillings@1563
|
632 };
|
nickjillings@1563
|
633 xmlhttp.send(file);
|
nickjillings@1563
|
634 }
|
nickjillings@1563
|
635 }
|
nickjillings@1563
|
636
|
nickjillings@1563
|
637 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nickjillings@1563
|
638 function interfaceXMLSave(){
|
nickjillings@1563
|
639 // Create the XML string to be exported with results
|
nickjillings@1563
|
640 var xmlDoc = document.createElement("BrowserEvaluationResult");
|
nickjillings@1563
|
641 xmlDoc.appendChild(returnDateNode());
|
nickjillings@1563
|
642 for (var i=0; i<testState.stateResults.length; i++)
|
nickjillings@1563
|
643 {
|
nickjillings@1563
|
644 xmlDoc.appendChild(testState.stateResults[i]);
|
nickjillings@1563
|
645 }
|
nickjillings@1563
|
646
|
nickjillings@1563
|
647 return xmlDoc;
|
nickjillings@1563
|
648 }
|
nickjillings@1563
|
649
|
nickjillings@1563
|
650 function AudioEngine() {
|
nickjillings@1563
|
651
|
nickjillings@1563
|
652 // Create two output paths, the main outputGain and fooGain.
|
nickjillings@1563
|
653 // Output gain is default to 1 and any items for playback route here
|
nickjillings@1563
|
654 // Foo gain is used for analysis to ensure paths get processed, but are not heard
|
nickjillings@1563
|
655 // because web audio will optimise and any route which does not go to the destination gets ignored.
|
nickjillings@1563
|
656 this.outputGain = audioContext.createGain();
|
nickjillings@1563
|
657 this.fooGain = audioContext.createGain();
|
nickjillings@1563
|
658 this.fooGain.gain = 0;
|
nickjillings@1563
|
659
|
nickjillings@1563
|
660 // Use this to detect playback state: 0 - stopped, 1 - playing
|
nickjillings@1563
|
661 this.status = 0;
|
nickjillings@1563
|
662 this.audioObjectsReady = false;
|
nickjillings@1563
|
663
|
nickjillings@1563
|
664 // Connect both gains to output
|
nickjillings@1563
|
665 this.outputGain.connect(audioContext.destination);
|
nickjillings@1563
|
666 this.fooGain.connect(audioContext.destination);
|
nickjillings@1563
|
667
|
nickjillings@1563
|
668 // Create the timer Object
|
nickjillings@1563
|
669 this.timer = new timer();
|
nickjillings@1563
|
670 // Create session metrics
|
nickjillings@1563
|
671 this.metric = new sessionMetrics(this);
|
nickjillings@1563
|
672
|
nickjillings@1563
|
673 this.loopPlayback = false;
|
nickjillings@1563
|
674
|
nickjillings@1563
|
675 // Create store for new audioObjects
|
nickjillings@1563
|
676 this.audioObjects = [];
|
nickjillings@1563
|
677
|
nickjillings@1563
|
678 this.play = function() {
|
nickjillings@1563
|
679 // Start the timer and set the audioEngine state to playing (1)
|
nickjillings@1563
|
680 if (this.status == 0) {
|
nickjillings@1563
|
681 // Check if all audioObjects are ready
|
nickjillings@1563
|
682 if (this.audioObjectsReady == false) {
|
nickjillings@1563
|
683 this.audioObjectsReady = this.checkAllReady();
|
nickjillings@1563
|
684 }
|
nickjillings@1563
|
685 if (this.audioObjectsReady == true) {
|
nickjillings@1563
|
686 this.timer.startTest();
|
nickjillings@1563
|
687 if (this.loopPlayback) {
|
nickjillings@1563
|
688 for(var i=0; i<this.audioObjects.length; i++) {
|
nickjillings@1563
|
689 this.audioObjects[i].play(this.timer.getTestTime()+1);
|
nickjillings@1563
|
690 }
|
nickjillings@1563
|
691 }
|
nickjillings@1563
|
692 this.status = 1;
|
nickjillings@1563
|
693 }
|
nickjillings@1563
|
694 }
|
nickjillings@1563
|
695 };
|
nickjillings@1563
|
696
|
nickjillings@1563
|
697 this.stop = function() {
|
nickjillings@1563
|
698 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1)
|
nickjillings@1563
|
699 if (this.status == 1) {
|
nickjillings@1563
|
700 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1563
|
701 {
|
nickjillings@1563
|
702 this.audioObjects[i].stop();
|
nickjillings@1563
|
703 }
|
nickjillings@1563
|
704 this.status = 0;
|
nickjillings@1563
|
705 }
|
nickjillings@1563
|
706 };
|
nickjillings@1563
|
707
|
nickjillings@1563
|
708
|
nickjillings@1563
|
709 this.newTrack = function(element) {
|
nickjillings@1563
|
710 // Pull data from given URL into new audio buffer
|
nickjillings@1563
|
711 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
|
nickjillings@1563
|
712
|
nickjillings@1563
|
713 // Create the audioObject with ID of the new track length;
|
nickjillings@1563
|
714 audioObjectId = this.audioObjects.length;
|
nickjillings@1563
|
715 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
|
nickjillings@1563
|
716
|
nickjillings@1563
|
717 // AudioObject will get track itself.
|
nickjillings@1563
|
718 this.audioObjects[audioObjectId].specification = element;
|
nickjillings@1563
|
719 this.audioObjects[audioObjectId].constructTrack(element.parent.hostURL + element.url);
|
nickjillings@1563
|
720 return this.audioObjects[audioObjectId];
|
nickjillings@1563
|
721 };
|
nickjillings@1563
|
722
|
nickjillings@1563
|
723 this.newTestPage = function() {
|
nickjillings@1563
|
724 this.state = 0;
|
nickjillings@1563
|
725 this.audioObjectsReady = false;
|
nickjillings@1563
|
726 this.metric.reset();
|
nickjillings@1563
|
727 this.audioObjects = [];
|
nickjillings@1563
|
728 };
|
nickjillings@1563
|
729
|
nickjillings@1563
|
730 this.checkAllPlayed = function() {
|
nickjillings@1563
|
731 arr = [];
|
nickjillings@1563
|
732 for (var id=0; id<this.audioObjects.length; id++) {
|
nickjillings@1563
|
733 if (this.audioObjects[id].metric.wasListenedTo == false) {
|
nickjillings@1563
|
734 arr.push(this.audioObjects[id].id);
|
nickjillings@1563
|
735 }
|
nickjillings@1563
|
736 }
|
nickjillings@1563
|
737 return arr;
|
nickjillings@1563
|
738 };
|
nickjillings@1563
|
739
|
nickjillings@1563
|
740 this.checkAllReady = function() {
|
nickjillings@1563
|
741 var ready = true;
|
nickjillings@1563
|
742 for (var i=0; i<this.audioObjects.length; i++) {
|
nickjillings@1563
|
743 if (this.audioObjects[i].state == 0) {
|
nickjillings@1563
|
744 // Track not ready
|
nickjillings@1563
|
745 console.log('WAIT -- audioObject '+i+' not ready yet!');
|
nickjillings@1563
|
746 ready = false;
|
nickjillings@1563
|
747 };
|
nickjillings@1563
|
748 }
|
nickjillings@1563
|
749 return ready;
|
nickjillings@1563
|
750 };
|
nickjillings@1563
|
751
|
nickjillings@1563
|
752 }
|
nickjillings@1563
|
753
|
nickjillings@1563
|
754 function audioObject(id) {
|
nickjillings@1563
|
755 // The main buffer object with common control nodes to the AudioEngine
|
nickjillings@1563
|
756
|
nickjillings@1563
|
757 this.specification;
|
nickjillings@1563
|
758 this.id = id;
|
nickjillings@1563
|
759 this.state = 0; // 0 - no data, 1 - ready
|
nickjillings@1563
|
760 this.url = null; // Hold the URL given for the output back to the results.
|
nickjillings@1563
|
761 this.metric = new metricTracker(this);
|
nickjillings@1563
|
762
|
nickjillings@1563
|
763 // Bindings for GUI
|
nickjillings@1563
|
764 this.interfaceDOM = null;
|
nickjillings@1563
|
765 this.commentDOM = null;
|
nickjillings@1563
|
766
|
nickjillings@1563
|
767 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
|
nickjillings@1563
|
768 this.bufferNode = undefined;
|
nickjillings@1563
|
769 this.outputGain = audioContext.createGain();
|
nickjillings@1563
|
770
|
nickjillings@1563
|
771 // Default output gain to be zero
|
nickjillings@1563
|
772 this.outputGain.gain.value = 0.0;
|
nickjillings@1563
|
773
|
nickjillings@1563
|
774 // Connect buffer to the audio graph
|
nickjillings@1563
|
775 this.outputGain.connect(audioEngineContext.outputGain);
|
nickjillings@1563
|
776
|
nickjillings@1563
|
777 // the audiobuffer is not designed for multi-start playback
|
nickjillings@1563
|
778 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
|
nickjillings@1563
|
779 this.buffer;
|
nickjillings@1563
|
780
|
nickjillings@1563
|
781 this.loopStart = function() {
|
nickjillings@1563
|
782 this.outputGain.gain.value = 1.0;
|
nickjillings@1563
|
783 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1563
|
784 };
|
nickjillings@1563
|
785
|
nickjillings@1563
|
786 this.loopStop = function() {
|
nickjillings@1563
|
787 if (this.outputGain.gain.value != 0.0) {
|
nickjillings@1563
|
788 this.outputGain.gain.value = 0.0;
|
nickjillings@1563
|
789 this.metric.stopListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1563
|
790 }
|
nickjillings@1563
|
791 };
|
nickjillings@1563
|
792
|
nickjillings@1563
|
793 this.play = function(startTime) {
|
nickjillings@1563
|
794 this.bufferNode = audioContext.createBufferSource();
|
nickjillings@1563
|
795 this.bufferNode.owner = this;
|
nickjillings@1563
|
796 this.bufferNode.connect(this.outputGain);
|
nickjillings@1563
|
797 this.bufferNode.buffer = this.buffer;
|
nickjillings@1563
|
798 this.bufferNode.loop = audioEngineContext.loopPlayback;
|
nickjillings@1563
|
799 this.bufferNode.onended = function() {
|
nickjillings@1563
|
800 // Safari does not like using 'this' to reference the calling object!
|
nickjillings@1563
|
801 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1563
|
802 };
|
nickjillings@1563
|
803 if (this.bufferNode.loop == false) {
|
nickjillings@1563
|
804 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1563
|
805 }
|
nickjillings@1563
|
806 this.bufferNode.start(startTime);
|
nickjillings@1563
|
807 };
|
nickjillings@1563
|
808
|
nickjillings@1563
|
809 this.stop = function() {
|
nickjillings@1563
|
810 if (this.bufferNode != undefined)
|
nickjillings@1563
|
811 {
|
nickjillings@1563
|
812 this.bufferNode.stop(0);
|
nickjillings@1563
|
813 this.bufferNode = undefined;
|
nickjillings@1563
|
814 this.metric.stopListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1563
|
815 }
|
nickjillings@1563
|
816 };
|
nickjillings@1563
|
817
|
nickjillings@1563
|
818 this.getCurrentPosition = function() {
|
nickjillings@1563
|
819 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1563
|
820 if (this.bufferNode != undefined) {
|
nickjillings@1563
|
821 if (this.bufferNode.loop == true) {
|
nickjillings@1563
|
822 if (audioEngineContext.status == 1) {
|
nickjillings@1563
|
823 return time%this.buffer.duration;
|
nickjillings@1563
|
824 } else {
|
nickjillings@1563
|
825 return 0;
|
nickjillings@1563
|
826 }
|
nickjillings@1563
|
827 } else {
|
nickjillings@1563
|
828 if (this.metric.listenHold) {
|
nickjillings@1563
|
829 return time - this.metric.listenStart;
|
nickjillings@1563
|
830 } else {
|
nickjillings@1563
|
831 return 0;
|
nickjillings@1563
|
832 }
|
nickjillings@1563
|
833 }
|
nickjillings@1563
|
834 } else {
|
nickjillings@1563
|
835 return 0;
|
nickjillings@1563
|
836 }
|
nickjillings@1563
|
837 };
|
nickjillings@1563
|
838
|
nickjillings@1563
|
839 this.constructTrack = function(url) {
|
nickjillings@1563
|
840 var request = new XMLHttpRequest();
|
nickjillings@1563
|
841 this.url = url;
|
nickjillings@1563
|
842 request.open('GET',url,true);
|
nickjillings@1563
|
843 request.responseType = 'arraybuffer';
|
nickjillings@1563
|
844
|
nickjillings@1563
|
845 var audioObj = this;
|
nickjillings@1563
|
846
|
nickjillings@1563
|
847 // Create callback to decode the data asynchronously
|
nickjillings@1563
|
848 request.onloadend = function() {
|
nickjillings@1563
|
849 audioContext.decodeAudioData(request.response, function(decodedData) {
|
nickjillings@1563
|
850 audioObj.buffer = decodedData;
|
nickjillings@1563
|
851 audioObj.state = 1;
|
nickjillings@1563
|
852 }, function(){
|
nickjillings@1563
|
853 // Should only be called if there was an error, but sometimes gets called continuously
|
nickjillings@1563
|
854 // Check here if the error is genuine
|
nickjillings@1563
|
855 if (audioObj.state == 0 || audioObj.buffer == undefined) {
|
nickjillings@1563
|
856 // Genuine error
|
nickjillings@1563
|
857 console.log('FATAL - Error loading buffer on '+audioObj.id);
|
nickjillings@1563
|
858 }
|
nickjillings@1563
|
859 });
|
nickjillings@1563
|
860 };
|
nickjillings@1563
|
861 request.send();
|
nickjillings@1563
|
862 };
|
nickjillings@1563
|
863
|
nickjillings@1563
|
864 this.exportXMLDOM = function() {
|
nickjillings@1563
|
865 var root = document.createElement('audioElement');
|
nickjillings@1563
|
866 root.id = this.specification.id;
|
nickjillings@1563
|
867 root.setAttribute('url',this.url);
|
nickjillings@1563
|
868 root.appendChild(this.interfaceDOM.exportXMLDOM());
|
nickjillings@1563
|
869 root.appendChild(this.commentDOM.exportXMLDOM());
|
nickjillings@1563
|
870 root.appendChild(this.metric.exportXMLDOM());
|
nickjillings@1563
|
871 return root;
|
nickjillings@1563
|
872 };
|
nickjillings@1563
|
873 }
|
nickjillings@1563
|
874
|
nickjillings@1563
|
875 function timer()
|
nickjillings@1563
|
876 {
|
nickjillings@1563
|
877 /* Timer object used in audioEngine to keep track of session timings
|
nickjillings@1563
|
878 * Uses the timer of the web audio API, so sample resolution
|
nickjillings@1563
|
879 */
|
nickjillings@1563
|
880 this.testStarted = false;
|
nickjillings@1563
|
881 this.testStartTime = 0;
|
nickjillings@1563
|
882 this.testDuration = 0;
|
nickjillings@1563
|
883 this.minimumTestTime = 0; // No minimum test time
|
nickjillings@1563
|
884 this.startTest = function()
|
nickjillings@1563
|
885 {
|
nickjillings@1563
|
886 if (this.testStarted == false)
|
nickjillings@1563
|
887 {
|
nickjillings@1563
|
888 this.testStartTime = audioContext.currentTime;
|
nickjillings@1563
|
889 this.testStarted = true;
|
nickjillings@1563
|
890 this.updateTestTime();
|
nickjillings@1563
|
891 audioEngineContext.metric.initialiseTest();
|
nickjillings@1563
|
892 }
|
nickjillings@1563
|
893 };
|
nickjillings@1563
|
894 this.stopTest = function()
|
nickjillings@1563
|
895 {
|
nickjillings@1563
|
896 if (this.testStarted)
|
nickjillings@1563
|
897 {
|
nickjillings@1563
|
898 this.testDuration = this.getTestTime();
|
nickjillings@1563
|
899 this.testStarted = false;
|
nickjillings@1563
|
900 } else {
|
nickjillings@1563
|
901 console.log('ERR: Test tried to end before beginning');
|
nickjillings@1563
|
902 }
|
nickjillings@1563
|
903 };
|
nickjillings@1563
|
904 this.updateTestTime = function()
|
nickjillings@1563
|
905 {
|
nickjillings@1563
|
906 if (this.testStarted)
|
nickjillings@1563
|
907 {
|
nickjillings@1563
|
908 this.testDuration = audioContext.currentTime - this.testStartTime;
|
nickjillings@1563
|
909 }
|
nickjillings@1563
|
910 };
|
nickjillings@1563
|
911 this.getTestTime = function()
|
nickjillings@1563
|
912 {
|
nickjillings@1563
|
913 this.updateTestTime();
|
nickjillings@1563
|
914 return this.testDuration;
|
nickjillings@1563
|
915 };
|
nickjillings@1563
|
916 }
|
nickjillings@1563
|
917
|
nickjillings@1563
|
918 function sessionMetrics(engine)
|
nickjillings@1563
|
919 {
|
nickjillings@1563
|
920 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
|
nickjillings@1563
|
921 */
|
nickjillings@1563
|
922 this.engine = engine;
|
nickjillings@1563
|
923 this.lastClicked = -1;
|
nickjillings@1563
|
924 this.data = -1;
|
nickjillings@1563
|
925 this.reset = function() {
|
nickjillings@1563
|
926 this.lastClicked = -1;
|
nickjillings@1563
|
927 this.data = -1;
|
nickjillings@1563
|
928 };
|
nickjillings@1563
|
929 this.initialiseTest = function(){};
|
nickjillings@1563
|
930 }
|
nickjillings@1563
|
931
|
nickjillings@1563
|
932 function metricTracker(caller)
|
nickjillings@1563
|
933 {
|
nickjillings@1563
|
934 /* Custom object to track and collect metric data
|
nickjillings@1563
|
935 * Used only inside the audioObjects object.
|
nickjillings@1563
|
936 */
|
nickjillings@1563
|
937
|
nickjillings@1563
|
938 this.listenedTimer = 0;
|
nickjillings@1563
|
939 this.listenStart = 0;
|
nickjillings@1563
|
940 this.listenHold = false;
|
nickjillings@1563
|
941 this.initialPosition = -1;
|
nickjillings@1563
|
942 this.movementTracker = [];
|
nickjillings@1563
|
943 this.listenTracker =[];
|
nickjillings@1563
|
944 this.wasListenedTo = false;
|
nickjillings@1563
|
945 this.wasMoved = false;
|
nickjillings@1563
|
946 this.hasComments = false;
|
nickjillings@1563
|
947 this.parent = caller;
|
nickjillings@1563
|
948
|
nickjillings@1563
|
949 this.initialised = function(position)
|
nickjillings@1563
|
950 {
|
nickjillings@1563
|
951 if (this.initialPosition == -1) {
|
nickjillings@1563
|
952 this.initialPosition = position;
|
nickjillings@1563
|
953 }
|
nickjillings@1563
|
954 };
|
nickjillings@1563
|
955
|
nickjillings@1563
|
956 this.moved = function(time,position)
|
nickjillings@1563
|
957 {
|
nickjillings@1563
|
958 this.wasMoved = true;
|
nickjillings@1563
|
959 this.movementTracker[this.movementTracker.length] = [time, position];
|
nickjillings@1563
|
960 };
|
nickjillings@1563
|
961
|
nickjillings@1563
|
962 this.startListening = function(time)
|
nickjillings@1563
|
963 {
|
nickjillings@1563
|
964 if (this.listenHold == false)
|
nickjillings@1563
|
965 {
|
nickjillings@1563
|
966 this.wasListenedTo = true;
|
nickjillings@1563
|
967 this.listenStart = time;
|
nickjillings@1563
|
968 this.listenHold = true;
|
nickjillings@1563
|
969
|
nickjillings@1563
|
970 var evnt = document.createElement('event');
|
nickjillings@1563
|
971 var testTime = document.createElement('testTime');
|
nickjillings@1563
|
972 testTime.setAttribute('start',time);
|
nickjillings@1563
|
973 var bufferTime = document.createElement('bufferTime');
|
nickjillings@1563
|
974 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
|
nickjillings@1563
|
975 evnt.appendChild(testTime);
|
nickjillings@1563
|
976 evnt.appendChild(bufferTime);
|
nickjillings@1563
|
977 this.listenTracker.push(evnt);
|
nickjillings@1563
|
978
|
nickjillings@1563
|
979 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1563
|
980 }
|
nickjillings@1563
|
981 };
|
nickjillings@1563
|
982
|
nickjillings@1563
|
983 this.stopListening = function(time)
|
nickjillings@1563
|
984 {
|
nickjillings@1563
|
985 if (this.listenHold == true)
|
nickjillings@1563
|
986 {
|
nickjillings@1563
|
987 var diff = time - this.listenStart;
|
nickjillings@1563
|
988 this.listenedTimer += (diff);
|
nickjillings@1563
|
989 this.listenStart = 0;
|
nickjillings@1563
|
990 this.listenHold = false;
|
nickjillings@1563
|
991
|
nickjillings@1563
|
992 var evnt = this.listenTracker[this.listenTracker.length-1];
|
nickjillings@1563
|
993 var testTime = evnt.getElementsByTagName('testTime')[0];
|
nickjillings@1563
|
994 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
|
nickjillings@1563
|
995 testTime.setAttribute('stop',time);
|
nickjillings@1563
|
996 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
|
nickjillings@1563
|
997 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1563
|
998 }
|
nickjillings@1563
|
999 };
|
nickjillings@1563
|
1000
|
nickjillings@1563
|
1001 this.exportXMLDOM = function() {
|
nickjillings@1563
|
1002 var root = document.createElement('metric');
|
nickjillings@1563
|
1003 if (audioEngineContext.metric.enableElementTimer) {
|
nickjillings@1563
|
1004 var mElementTimer = document.createElement('metricresult');
|
nickjillings@1563
|
1005 mElementTimer.setAttribute('name','enableElementTimer');
|
nickjillings@1563
|
1006 mElementTimer.textContent = this.listenedTimer;
|
nickjillings@1563
|
1007 root.appendChild(mElementTimer);
|
nickjillings@1563
|
1008 }
|
nickjillings@1563
|
1009 if (audioEngineContext.metric.enableElementTracker) {
|
nickjillings@1563
|
1010 var elementTrackerFull = document.createElement('metricResult');
|
nickjillings@1563
|
1011 elementTrackerFull.setAttribute('name','elementTrackerFull');
|
nickjillings@1563
|
1012 for (var k=0; k<this.movementTracker.length; k++)
|
nickjillings@1563
|
1013 {
|
nickjillings@1563
|
1014 var timePos = document.createElement('timePos');
|
nickjillings@1563
|
1015 timePos.id = k;
|
nickjillings@1563
|
1016 var time = document.createElement('time');
|
nickjillings@1563
|
1017 time.textContent = this.movementTracker[k][0];
|
nickjillings@1563
|
1018 var position = document.createElement('position');
|
nickjillings@1563
|
1019 position.textContent = this.movementTracker[k][1];
|
nickjillings@1563
|
1020 timePos.appendChild(time);
|
nickjillings@1563
|
1021 timePos.appendChild(position);
|
nickjillings@1563
|
1022 elementTrackerFull.appendChild(timePos);
|
nickjillings@1563
|
1023 }
|
nickjillings@1563
|
1024 root.appendChild(elementTrackerFull);
|
nickjillings@1563
|
1025 }
|
nickjillings@1563
|
1026 if (audioEngineContext.metric.enableElementListenTracker) {
|
nickjillings@1563
|
1027 var elementListenTracker = document.createElement('metricResult');
|
nickjillings@1563
|
1028 elementListenTracker.setAttribute('name','elementListenTracker');
|
nickjillings@1563
|
1029 for (var k=0; k<this.listenTracker.length; k++) {
|
nickjillings@1563
|
1030 elementListenTracker.appendChild(this.listenTracker[k]);
|
nickjillings@1563
|
1031 }
|
nickjillings@1563
|
1032 root.appendChild(elementListenTracker);
|
nickjillings@1563
|
1033 }
|
nickjillings@1563
|
1034 if (audioEngineContext.metric.enableElementInitialPosition) {
|
nickjillings@1563
|
1035 var elementInitial = document.createElement('metricResult');
|
nickjillings@1563
|
1036 elementInitial.setAttribute('name','elementInitialPosition');
|
nickjillings@1563
|
1037 elementInitial.textContent = this.initialPosition;
|
nickjillings@1563
|
1038 root.appendChild(elementInitial);
|
nickjillings@1563
|
1039 }
|
nickjillings@1563
|
1040 if (audioEngineContext.metric.enableFlagListenedTo) {
|
nickjillings@1563
|
1041 var flagListenedTo = document.createElement('metricResult');
|
nickjillings@1563
|
1042 flagListenedTo.setAttribute('name','elementFlagListenedTo');
|
nickjillings@1563
|
1043 flagListenedTo.textContent = this.wasListenedTo;
|
nickjillings@1563
|
1044 root.appendChild(flagListenedTo);
|
nickjillings@1563
|
1045 }
|
nickjillings@1563
|
1046 if (audioEngineContext.metric.enableFlagMoved) {
|
nickjillings@1563
|
1047 var flagMoved = document.createElement('metricResult');
|
nickjillings@1563
|
1048 flagMoved.setAttribute('name','elementFlagMoved');
|
nickjillings@1563
|
1049 flagMoved.textContent = this.wasMoved;
|
nickjillings@1563
|
1050 root.appendChild(flagMoved);
|
nickjillings@1563
|
1051 }
|
nickjillings@1563
|
1052 if (audioEngineContext.metric.enableFlagComments) {
|
nickjillings@1563
|
1053 var flagComments = document.createElement('metricResult');
|
nickjillings@1563
|
1054 flagComments.setAttribute('name','elementFlagComments');
|
nickjillings@1563
|
1055 if (this.parent.commentDOM == null)
|
nickjillings@1563
|
1056 {flag.textContent = 'false';}
|
nickjillings@1563
|
1057 else if (this.parent.commentDOM.textContent.length == 0)
|
nickjillings@1563
|
1058 {flag.textContent = 'false';}
|
nickjillings@1563
|
1059 else
|
nickjillings@1563
|
1060 {flag.textContet = 'true';}
|
nickjillings@1563
|
1061 root.appendChild(flagComments);
|
nickjillings@1563
|
1062 }
|
nickjillings@1563
|
1063
|
nickjillings@1563
|
1064 return root;
|
nickjillings@1563
|
1065 };
|
nickjillings@1563
|
1066 }
|
nickjillings@1563
|
1067
|
nickjillings@1563
|
1068 function randomiseOrder(input)
|
nickjillings@1563
|
1069 {
|
nickjillings@1563
|
1070 // This takes an array of information and randomises the order
|
nickjillings@1563
|
1071 var N = input.length;
|
nickjillings@1563
|
1072 var K = N;
|
nickjillings@1563
|
1073 var holdArr = [];
|
nickjillings@1563
|
1074 for (var n=0; n<N; n++)
|
nickjillings@1563
|
1075 {
|
nickjillings@1563
|
1076 // First pick a random number
|
nickjillings@1563
|
1077 var r = Math.random();
|
nickjillings@1563
|
1078 // Multiply and floor by the number of elements left
|
nickjillings@1563
|
1079 r = Math.floor(r*input.length);
|
nickjillings@1563
|
1080 // Pick out that element and delete from the array
|
nickjillings@1563
|
1081 holdArr.push(input.splice(r,1)[0]);
|
nickjillings@1563
|
1082 }
|
nickjillings@1563
|
1083 return holdArr;
|
nickjillings@1563
|
1084 }
|
nickjillings@1563
|
1085
|
nickjillings@1563
|
1086 function returnDateNode()
|
nickjillings@1563
|
1087 {
|
nickjillings@1563
|
1088 // Create an XML Node for the Date and Time a test was conducted
|
nickjillings@1563
|
1089 // Structure is
|
nickjillings@1563
|
1090 // <datetime>
|
nickjillings@1563
|
1091 // <date year="##" month="##" day="##">DD/MM/YY</date>
|
nickjillings@1563
|
1092 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
|
nickjillings@1563
|
1093 // </datetime>
|
nickjillings@1563
|
1094 var dateTime = new Date();
|
nickjillings@1563
|
1095 var year = document.createAttribute('year');
|
nickjillings@1563
|
1096 var month = document.createAttribute('month');
|
nickjillings@1563
|
1097 var day = document.createAttribute('day');
|
nickjillings@1563
|
1098 var hour = document.createAttribute('hour');
|
nickjillings@1563
|
1099 var minute = document.createAttribute('minute');
|
nickjillings@1563
|
1100 var secs = document.createAttribute('secs');
|
nickjillings@1563
|
1101
|
nickjillings@1563
|
1102 year.nodeValue = dateTime.getFullYear();
|
nickjillings@1563
|
1103 month.nodeValue = dateTime.getMonth()+1;
|
nickjillings@1563
|
1104 day.nodeValue = dateTime.getDate();
|
nickjillings@1563
|
1105 hour.nodeValue = dateTime.getHours();
|
nickjillings@1563
|
1106 minute.nodeValue = dateTime.getMinutes();
|
nickjillings@1563
|
1107 secs.nodeValue = dateTime.getSeconds();
|
nickjillings@1563
|
1108
|
nickjillings@1563
|
1109 var hold = document.createElement("datetime");
|
nickjillings@1563
|
1110 var date = document.createElement("date");
|
nickjillings@1563
|
1111 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
|
nickjillings@1563
|
1112 var time = document.createElement("time");
|
nickjillings@1563
|
1113 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
|
nickjillings@1563
|
1114
|
nickjillings@1563
|
1115 date.setAttributeNode(year);
|
nickjillings@1563
|
1116 date.setAttributeNode(month);
|
nickjillings@1563
|
1117 date.setAttributeNode(day);
|
nickjillings@1563
|
1118 time.setAttributeNode(hour);
|
nickjillings@1563
|
1119 time.setAttributeNode(minute);
|
nickjillings@1563
|
1120 time.setAttributeNode(secs);
|
nickjillings@1563
|
1121
|
nickjillings@1563
|
1122 hold.appendChild(date);
|
nickjillings@1563
|
1123 hold.appendChild(time);
|
nickjillings@1563
|
1124 return hold
|
nickjillings@1563
|
1125
|
nickjillings@1563
|
1126 }
|
nickjillings@1563
|
1127
|
nickjillings@1563
|
1128 function testWaitIndicator() {
|
nickjillings@1563
|
1129 if (audioEngineContext.checkAllReady() == false) {
|
nickjillings@1563
|
1130 var hold = document.createElement("div");
|
nickjillings@1563
|
1131 hold.id = "testWaitIndicator";
|
nickjillings@1563
|
1132 hold.className = "indicator-box";
|
nickjillings@1563
|
1133 hold.style.zIndex = 3;
|
nickjillings@1563
|
1134 var span = document.createElement("span");
|
nickjillings@1563
|
1135 span.textContent = "Please wait! Elements still loading";
|
nickjillings@1563
|
1136 hold.appendChild(span);
|
nickjillings@1563
|
1137 var blank = document.createElement('div');
|
nickjillings@1563
|
1138 blank.className = 'testHalt';
|
nickjillings@1563
|
1139 blank.id = "testHaltBlank";
|
nickjillings@1563
|
1140 var body = document.getElementsByTagName('body')[0];
|
nickjillings@1563
|
1141 body.appendChild(hold);
|
nickjillings@1563
|
1142 body.appendChild(blank);
|
nickjillings@1563
|
1143 testWaitTimerIntervalHolder = setInterval(function(){
|
nickjillings@1563
|
1144 var ready = audioEngineContext.checkAllReady();
|
nickjillings@1563
|
1145 if (ready) {
|
nickjillings@1563
|
1146 var elem = document.getElementById('testWaitIndicator');
|
nickjillings@1563
|
1147 var blank = document.getElementById('testHaltBlank');
|
nickjillings@1563
|
1148 var body = document.getElementsByTagName('body')[0];
|
nickjillings@1563
|
1149 body.removeChild(elem);
|
nickjillings@1563
|
1150 body.removeChild(blank);
|
nickjillings@1563
|
1151 clearInterval(testWaitTimerIntervalHolder);
|
nickjillings@1563
|
1152 }
|
nickjillings@1563
|
1153 },500,false);
|
nickjillings@1563
|
1154 }
|
nickjillings@1563
|
1155 }
|
nickjillings@1563
|
1156
|
nickjillings@1563
|
1157 var testWaitTimerIntervalHolder = null;
|
nickjillings@1563
|
1158
|
nickjillings@1563
|
1159 function Specification() {
|
nickjillings@1563
|
1160 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
nickjillings@1563
|
1161
|
nickjillings@1563
|
1162 this.interfaceType;
|
nickjillings@1563
|
1163 this.projectReturn;
|
nickjillings@1563
|
1164 this.randomiseOrder;
|
nickjillings@1563
|
1165 this.collectMetrics;
|
nickjillings@1563
|
1166 this.preTest;
|
nickjillings@1563
|
1167 this.postTest;
|
nickjillings@1563
|
1168 this.metrics =[];
|
nickjillings@1563
|
1169
|
nickjillings@1563
|
1170 this.audioHolders = [];
|
nickjillings@1563
|
1171
|
nickjillings@1563
|
1172 this.decode = function() {
|
nickjillings@1563
|
1173 // projectXML - DOM Parsed document
|
nickjillings@1563
|
1174 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
nickjillings@1563
|
1175 this.interfaceType = setupNode.getAttribute('interface');
|
nickjillings@1563
|
1176 this.projectReturn = setupNode.getAttribute('projectReturn');
|
nickjillings@1563
|
1177 if (setupNode.getAttribute('randomiseOrder') == "true") {
|
nickjillings@1563
|
1178 this.randomiseOrder = true;
|
nickjillings@1563
|
1179 } else {this.randomiseOrder = false;}
|
nickjillings@1563
|
1180 if (setupNode.getAttribute('collectMetrics') == "true") {
|
nickjillings@1563
|
1181 this.collectMetrics = true;
|
nickjillings@1563
|
1182 } else {this.collectMetrics = false;}
|
nickjillings@1563
|
1183 var metricCollection = setupNode.getElementsByTagName('Metric');
|
nickjillings@1563
|
1184
|
nickjillings@1563
|
1185 this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest'));
|
nickjillings@1563
|
1186 this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest'));
|
nickjillings@1563
|
1187
|
nickjillings@1563
|
1188 if (metricCollection.length > 0) {
|
nickjillings@1563
|
1189 metricCollection = metricCollection[0].getElementsByTagName('metricEnable');
|
nickjillings@1563
|
1190 for (var i=0; i<metricCollection.length; i++) {
|
nickjillings@1563
|
1191 this.metrics.push(new this.metricNode(metricCollection[i].textContent));
|
nickjillings@1563
|
1192 }
|
nickjillings@1563
|
1193 }
|
nickjillings@1563
|
1194
|
nickjillings@1563
|
1195 var audioHolders = projectXML.getElementsByTagName('audioHolder');
|
nickjillings@1563
|
1196 for (var i=0; i<audioHolders.length; i++) {
|
nickjillings@1563
|
1197 this.audioHolders.push(new this.audioHolderNode(this,audioHolders[i]));
|
nickjillings@1563
|
1198 }
|
nickjillings@1563
|
1199
|
nickjillings@1563
|
1200 };
|
nickjillings@1563
|
1201
|
nickjillings@1563
|
1202 this.prepostNode = function(type,Collection) {
|
nickjillings@1563
|
1203 this.type = type;
|
nickjillings@1563
|
1204 this.options = [];
|
nickjillings@1563
|
1205
|
nickjillings@1563
|
1206 this.OptionNode = function(child) {
|
nickjillings@1563
|
1207
|
nickjillings@1563
|
1208 this.childOption = function(element) {
|
nickjillings@1563
|
1209 this.type = 'option';
|
nickjillings@1563
|
1210 this.id = element.id;
|
nickjillings@1563
|
1211 this.name = element.getAttribute('name');
|
nickjillings@1563
|
1212 this.text = element.textContent;
|
nickjillings@1563
|
1213 };
|
nickjillings@1563
|
1214
|
nickjillings@1563
|
1215 this.type = child.nodeName;
|
nickjillings@1563
|
1216 if (child.nodeName == "question") {
|
nickjillings@1563
|
1217 this.id = child.id;
|
nickjillings@1563
|
1218 this.mandatory;
|
nickjillings@1563
|
1219 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;}
|
nickjillings@1563
|
1220 else {this.mandatory = false;}
|
nickjillings@1563
|
1221 this.question = child.textContent;
|
nickjillings@1563
|
1222 if (child.getAttribute('boxsize') == null) {
|
nickjillings@1563
|
1223 this.boxsize = 'normal';
|
nickjillings@1563
|
1224 } else {
|
nickjillings@1563
|
1225 this.boxsize = child.getAttribute('boxsize');
|
nickjillings@1563
|
1226 }
|
nickjillings@1563
|
1227 } else if (child.nodeName == "statement") {
|
nickjillings@1563
|
1228 this.statement = child.textContent;
|
nickjillings@1563
|
1229 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") {
|
nickjillings@1563
|
1230 var element = child.firstElementChild;
|
nickjillings@1563
|
1231 this.id = child.id;
|
nickjillings@1563
|
1232 if (element == null) {
|
nickjillings@1563
|
1233 console.log('Malformed' +child.nodeName+ 'entry');
|
nickjillings@1563
|
1234 this.statement = 'Malformed' +child.nodeName+ 'entry';
|
nickjillings@1563
|
1235 this.type = 'statement';
|
nickjillings@1563
|
1236 } else {
|
nickjillings@1563
|
1237 this.options = [];
|
nickjillings@1563
|
1238 while (element != null) {
|
nickjillings@1563
|
1239 if (element.nodeName == 'statement' && this.statement == undefined){
|
nickjillings@1563
|
1240 this.statement = element.textContent;
|
nickjillings@1563
|
1241 } else if (element.nodeName == 'option') {
|
nickjillings@1563
|
1242 this.options.push(new this.childOption(element));
|
nickjillings@1563
|
1243 }
|
nickjillings@1563
|
1244 element = element.nextElementSibling;
|
nickjillings@1563
|
1245 }
|
nickjillings@1563
|
1246 }
|
nickjillings@1563
|
1247 } else if (child.nodeName == "number") {
|
nickjillings@1563
|
1248 this.statement = child.textContent;
|
nickjillings@1563
|
1249 this.id = child.id;
|
nickjillings@1563
|
1250 this.min = child.getAttribute('min');
|
nickjillings@1563
|
1251 this.max = child.getAttribute('max');
|
nickjillings@1563
|
1252 this.step = child.getAttribute('step');
|
nickjillings@1563
|
1253 }
|
nickjillings@1563
|
1254 };
|
nickjillings@1563
|
1255
|
nickjillings@1563
|
1256 // On construction:
|
nickjillings@1563
|
1257 if (Collection.length != 0) {
|
nickjillings@1563
|
1258 Collection = Collection[0];
|
nickjillings@1563
|
1259 if (Collection.childElementCount != 0) {
|
nickjillings@1563
|
1260 var child = Collection.firstElementChild;
|
nickjillings@1563
|
1261 this.options.push(new this.OptionNode(child));
|
nickjillings@1563
|
1262 while (child.nextElementSibling != null) {
|
nickjillings@1563
|
1263 child = child.nextElementSibling;
|
nickjillings@1563
|
1264 this.options.push(new this.OptionNode(child));
|
nickjillings@1563
|
1265 }
|
nickjillings@1563
|
1266 }
|
nickjillings@1563
|
1267 }
|
nickjillings@1563
|
1268 };
|
nickjillings@1563
|
1269
|
nickjillings@1563
|
1270 this.metricNode = function(name) {
|
nickjillings@1563
|
1271 this.enabled = name;
|
nickjillings@1563
|
1272 };
|
nickjillings@1563
|
1273
|
nickjillings@1563
|
1274 this.audioHolderNode = function(parent,xml) {
|
nickjillings@1563
|
1275 this.type = 'audioHolder';
|
nickjillings@1563
|
1276 this.interfaceNode = function(DOM) {
|
nickjillings@1563
|
1277 var title = DOM.getElementsByTagName('title');
|
nickjillings@1563
|
1278 if (title.length == 0) {this.title = null;}
|
nickjillings@1563
|
1279 else {this.title = title[0].textContent;}
|
nickjillings@1563
|
1280
|
nickjillings@1563
|
1281 var scale = DOM.getElementsByTagName('scale');
|
nickjillings@1563
|
1282 this.scale = [];
|
nickjillings@1563
|
1283 for (var i=0; i<scale.length; i++) {
|
nickjillings@1563
|
1284 var arr = [null, null];
|
nickjillings@1563
|
1285 arr[0] = scale[i].getAttribute('position');
|
nickjillings@1563
|
1286 arr[1] = scale[i].textContent;
|
nickjillings@1563
|
1287 this.scale.push(arr);
|
nickjillings@1563
|
1288 }
|
nickjillings@1563
|
1289 };
|
nickjillings@1563
|
1290
|
nickjillings@1563
|
1291 this.audioElementNode = function(parent,xml) {
|
nickjillings@1563
|
1292 this.url = xml.getAttribute('url');
|
nickjillings@1563
|
1293 this.id = xml.id;
|
nickjillings@1563
|
1294 this.parent = parent;
|
nickjillings@1563
|
1295 };
|
nickjillings@1563
|
1296
|
nickjillings@1563
|
1297 this.commentQuestionNode = function(xml) {
|
nickjillings@1563
|
1298 this.childOption = function(element) {
|
nickjillings@1563
|
1299 this.type = 'option';
|
nickjillings@1563
|
1300 this.name = element.getAttribute('name');
|
nickjillings@1563
|
1301 this.text = element.textContent;
|
nickjillings@1563
|
1302 };
|
nickjillings@1563
|
1303 this.id = xml.id;
|
nickjillings@1563
|
1304 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;}
|
nickjillings@1563
|
1305 else {this.mandatory = false;}
|
nickjillings@1563
|
1306 this.type = xml.getAttribute('type');
|
nickjillings@1563
|
1307 if (this.type == undefined) {this.type = 'text';}
|
nickjillings@1563
|
1308 switch (this.type) {
|
nickjillings@1563
|
1309 case 'text':
|
nickjillings@1563
|
1310 this.question = xml.textContent;
|
nickjillings@1563
|
1311 break;
|
nickjillings@1563
|
1312 case 'radio':
|
nickjillings@1563
|
1313 var child = xml.firstElementChild;
|
nickjillings@1563
|
1314 this.options = [];
|
nickjillings@1563
|
1315 while (child != undefined) {
|
nickjillings@1563
|
1316 if (child.nodeName == 'statement' && this.statement == undefined) {
|
nickjillings@1563
|
1317 this.statement = child.textContent;
|
nickjillings@1563
|
1318 } else if (child.nodeName == 'option') {
|
nickjillings@1563
|
1319 this.options.push(new this.childOption(child));
|
nickjillings@1563
|
1320 }
|
nickjillings@1563
|
1321 child = child.nextElementSibling;
|
nickjillings@1563
|
1322 }
|
nickjillings@1563
|
1323 break;
|
nickjillings@1563
|
1324 case 'checkbox':
|
nickjillings@1563
|
1325 var child = xml.firstElementChild;
|
nickjillings@1563
|
1326 this.options = [];
|
nickjillings@1563
|
1327 while (child != undefined) {
|
nickjillings@1563
|
1328 if (child.nodeName == 'statement' && this.statement == undefined) {
|
nickjillings@1563
|
1329 this.statement = child.textContent;
|
nickjillings@1563
|
1330 } else if (child.nodeName == 'option') {
|
nickjillings@1563
|
1331 this.options.push(new this.childOption(child));
|
nickjillings@1563
|
1332 }
|
nickjillings@1563
|
1333 child = child.nextElementSibling;
|
nickjillings@1563
|
1334 }
|
nickjillings@1563
|
1335 break;
|
nickjillings@1563
|
1336 }
|
nickjillings@1563
|
1337 };
|
nickjillings@1563
|
1338
|
nickjillings@1563
|
1339 this.id = xml.id;
|
nickjillings@1563
|
1340 this.hostURL = xml.getAttribute('hostURL');
|
nickjillings@1563
|
1341 this.sampleRate = xml.getAttribute('sampleRate');
|
nickjillings@1563
|
1342 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
|
nickjillings@1563
|
1343 else {this.randomiseOrder = false;}
|
nickjillings@1563
|
1344 this.repeatCount = xml.getAttribute('repeatCount');
|
nickjillings@1563
|
1345 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
|
nickjillings@1563
|
1346 else {this.loop == false;}
|
nickjillings@1563
|
1347 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
|
nickjillings@1563
|
1348 else {this.elementComments = false;}
|
nickjillings@1563
|
1349
|
nickjillings@1563
|
1350 this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
|
nickjillings@1563
|
1351 this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest'));
|
nickjillings@1563
|
1352
|
nickjillings@1563
|
1353 this.interfaces = [];
|
nickjillings@1563
|
1354 var interfaceDOM = xml.getElementsByTagName('interface');
|
nickjillings@1563
|
1355 for (var i=0; i<interfaceDOM.length; i++) {
|
nickjillings@1563
|
1356 this.interfaces.push(new this.interfaceNode(interfaceDOM[i]));
|
nickjillings@1563
|
1357 }
|
nickjillings@1563
|
1358
|
nickjillings@1563
|
1359 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
|
nickjillings@1563
|
1360 if (this.commentBoxPrefix.length != 0) {
|
nickjillings@1563
|
1361 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
|
nickjillings@1563
|
1362 } else {
|
nickjillings@1563
|
1363 this.commentBoxPrefix = "Comment on track";
|
nickjillings@1563
|
1364 }
|
nickjillings@1563
|
1365
|
nickjillings@1563
|
1366 this.audioElements =[];
|
nickjillings@1563
|
1367 var audioElementsDOM = xml.getElementsByTagName('audioElements');
|
nickjillings@1563
|
1368 for (var i=0; i<audioElementsDOM.length; i++) {
|
nickjillings@1563
|
1369 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
|
nickjillings@1563
|
1370 }
|
nickjillings@1563
|
1371
|
nickjillings@1563
|
1372 this.commentQuestions = [];
|
nickjillings@1563
|
1373 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
|
nickjillings@1563
|
1374 for (var i=0; i<commentQuestionsDOM.length; i++) {
|
nickjillings@1563
|
1375 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
|
nickjillings@1563
|
1376 }
|
nickjillings@1563
|
1377 };
|
nickjillings@1563
|
1378 }
|
nickjillings@1563
|
1379
|
nickjillings@1563
|
1380 function Interface(specificationObject) {
|
nickjillings@1563
|
1381 // This handles the bindings between the interface and the audioEngineContext;
|
nickjillings@1563
|
1382 this.specification = specificationObject;
|
nickjillings@1563
|
1383 this.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1563
|
1384
|
nickjillings@1563
|
1385 // Bounded by interface!!
|
nickjillings@1563
|
1386 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
|
nickjillings@1563
|
1387 // For example, APE returns the slider position normalised in a <value> tag.
|
nickjillings@1563
|
1388 this.interfaceObjects = [];
|
nickjillings@1563
|
1389 this.interfaceObject = function(){};
|
nickjillings@1563
|
1390
|
nickjillings@1563
|
1391 this.commentBoxes = [];
|
nickjillings@1563
|
1392 this.elementCommentBox = function(audioObject) {
|
nickjillings@1563
|
1393 var element = audioObject.specification;
|
nickjillings@1563
|
1394 this.audioObject = audioObject;
|
nickjillings@1563
|
1395 this.id = audioObject.id;
|
nickjillings@1563
|
1396 var audioHolderObject = audioObject.specification.parent;
|
nickjillings@1563
|
1397 // Create document objects to hold the comment boxes
|
nickjillings@1563
|
1398 this.trackComment = document.createElement('div');
|
nickjillings@1563
|
1399 this.trackComment.className = 'comment-div';
|
nickjillings@1563
|
1400 this.trackComment.id = 'comment-div-'+audioObject.id;
|
nickjillings@1563
|
1401 // Create a string next to each comment asking for a comment
|
nickjillings@1563
|
1402 this.trackString = document.createElement('span');
|
nickjillings@1563
|
1403 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id;
|
nickjillings@1563
|
1404 // Create the HTML5 comment box 'textarea'
|
nickjillings@1563
|
1405 this.trackCommentBox = document.createElement('textarea');
|
nickjillings@1563
|
1406 this.trackCommentBox.rows = '4';
|
nickjillings@1563
|
1407 this.trackCommentBox.cols = '100';
|
nickjillings@1563
|
1408 this.trackCommentBox.name = 'trackComment'+audioObject.id;
|
nickjillings@1563
|
1409 this.trackCommentBox.className = 'trackComment';
|
nickjillings@1563
|
1410 var br = document.createElement('br');
|
nickjillings@1563
|
1411 // Add to the holder.
|
nickjillings@1563
|
1412 this.trackComment.appendChild(this.trackString);
|
nickjillings@1563
|
1413 this.trackComment.appendChild(br);
|
nickjillings@1563
|
1414 this.trackComment.appendChild(this.trackCommentBox);
|
nickjillings@1563
|
1415
|
nickjillings@1563
|
1416 this.exportXMLDOM = function() {
|
nickjillings@1563
|
1417 var root = document.createElement('comment');
|
nickjillings@1563
|
1418 if (this.audioObject.specification.parent.elementComments) {
|
nickjillings@1563
|
1419 var question = document.createElement('question');
|
nickjillings@1563
|
1420 question.textContent = this.trackString.textContent;
|
nickjillings@1563
|
1421 var response = document.createElement('response');
|
nickjillings@1563
|
1422 response.textContent = this.trackCommentBox.value;
|
nickjillings@1563
|
1423 root.appendChild(question);
|
nickjillings@1563
|
1424 root.appendChild(response);
|
nickjillings@1563
|
1425 }
|
nickjillings@1563
|
1426 return root;
|
nickjillings@1563
|
1427 };
|
nickjillings@1563
|
1428 };
|
nickjillings@1563
|
1429
|
nickjillings@1563
|
1430 this.commentQuestions = [];
|
nickjillings@1563
|
1431
|
nickjillings@1563
|
1432 this.commentBox = function(commentQuestion) {
|
nickjillings@1563
|
1433 this.specification = commentQuestion;
|
nickjillings@1563
|
1434 // Create document objects to hold the comment boxes
|
nickjillings@1563
|
1435 this.holder = document.createElement('div');
|
nickjillings@1563
|
1436 this.holder.className = 'comment-div';
|
nickjillings@1563
|
1437 // Create a string next to each comment asking for a comment
|
nickjillings@1563
|
1438 this.string = document.createElement('span');
|
nickjillings@1563
|
1439 this.string.innerHTML = commentQuestion.question;
|
nickjillings@1563
|
1440 // Create the HTML5 comment box 'textarea'
|
nickjillings@1563
|
1441 this.textArea = document.createElement('textarea');
|
nickjillings@1563
|
1442 this.textArea.rows = '4';
|
nickjillings@1563
|
1443 this.textArea.cols = '100';
|
nickjillings@1563
|
1444 this.textArea.className = 'trackComment';
|
nickjillings@1563
|
1445 var br = document.createElement('br');
|
nickjillings@1563
|
1446 // Add to the holder.
|
nickjillings@1563
|
1447 this.holder.appendChild(this.string);
|
nickjillings@1563
|
1448 this.holder.appendChild(br);
|
nickjillings@1563
|
1449 this.holder.appendChild(this.textArea);
|
nickjillings@1563
|
1450
|
nickjillings@1563
|
1451 this.exportXMLDOM = function() {
|
nickjillings@1563
|
1452 var root = document.createElement('comment');
|
nickjillings@1563
|
1453 root.id = this.specification.id;
|
nickjillings@1563
|
1454 root.setAttribute('type',this.specification.type);
|
nickjillings@1563
|
1455 root.textContent = this.textArea.value;
|
nickjillings@1563
|
1456 return root;
|
nickjillings@1563
|
1457 };
|
nickjillings@1563
|
1458 };
|
nickjillings@1563
|
1459
|
nickjillings@1563
|
1460 this.radioBox = function(commentQuestion) {
|
nickjillings@1563
|
1461 this.specification = commentQuestion;
|
nickjillings@1563
|
1462 // Create document objects to hold the comment boxes
|
nickjillings@1563
|
1463 this.holder = document.createElement('div');
|
nickjillings@1563
|
1464 this.holder.className = 'comment-div';
|
nickjillings@1563
|
1465 // Create a string next to each comment asking for a comment
|
nickjillings@1563
|
1466 this.string = document.createElement('span');
|
nickjillings@1563
|
1467 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1563
|
1468 var br = document.createElement('br');
|
nickjillings@1563
|
1469 // Add to the holder.
|
nickjillings@1563
|
1470 this.holder.appendChild(this.string);
|
nickjillings@1563
|
1471 this.holder.appendChild(br);
|
nickjillings@1563
|
1472 this.options = [];
|
nickjillings@1563
|
1473 this.inputs = document.createElement('div');
|
nickjillings@1563
|
1474 this.span = document.createElement('div');
|
nickjillings@1563
|
1475 this.inputs.align = 'center';
|
nickjillings@1563
|
1476 this.inputs.style.marginLeft = '12px';
|
nickjillings@1563
|
1477 this.span.style.marginLeft = '12px';
|
nickjillings@1563
|
1478 this.span.align = 'center';
|
nickjillings@1563
|
1479 this.span.style.marginTop = '15px';
|
nickjillings@1563
|
1480
|
nickjillings@1563
|
1481 var optCount = commentQuestion.options.length;
|
nickjillings@1563
|
1482 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px';
|
nickjillings@1563
|
1483 console.log(spanMargin);
|
nickjillings@1563
|
1484 for (var i=0; i<optCount; i++)
|
nickjillings@1563
|
1485 {
|
nickjillings@1563
|
1486 var div = document.createElement('div');
|
nickjillings@1563
|
1487 div.style.width = '100px';
|
nickjillings@1563
|
1488 div.style.float = 'left';
|
nickjillings@1563
|
1489 div.style.marginRight = spanMargin;
|
nickjillings@1563
|
1490 div.style.marginLeft = spanMargin;
|
nickjillings@1563
|
1491 var input = document.createElement('input');
|
nickjillings@1563
|
1492 input.type = 'radio';
|
nickjillings@1563
|
1493 input.name = commentQuestion.id;
|
nickjillings@1563
|
1494 input.setAttribute('setvalue',commentQuestion.options[i].name);
|
nickjillings@1563
|
1495 input.className = 'comment-radio';
|
nickjillings@1563
|
1496 div.appendChild(input);
|
nickjillings@1563
|
1497 this.inputs.appendChild(div);
|
nickjillings@1563
|
1498
|
nickjillings@1563
|
1499
|
nickjillings@1563
|
1500 div = document.createElement('div');
|
nickjillings@1563
|
1501 div.style.width = '100px';
|
nickjillings@1563
|
1502 div.style.float = 'left';
|
nickjillings@1563
|
1503 div.style.marginRight = spanMargin;
|
nickjillings@1563
|
1504 div.style.marginLeft = spanMargin;
|
nickjillings@1563
|
1505 div.align = 'center';
|
nickjillings@1563
|
1506 var span = document.createElement('span');
|
nickjillings@1563
|
1507 span.textContent = commentQuestion.options[i].text;
|
nickjillings@1563
|
1508 span.className = 'comment-radio-span';
|
nickjillings@1563
|
1509 div.appendChild(span);
|
nickjillings@1563
|
1510 this.span.appendChild(div);
|
nickjillings@1563
|
1511 this.options.push(input);
|
nickjillings@1563
|
1512 }
|
nickjillings@1563
|
1513 this.holder.appendChild(this.span);
|
nickjillings@1563
|
1514 this.holder.appendChild(this.inputs);
|
nickjillings@1563
|
1515
|
nickjillings@1563
|
1516 this.exportXMLDOM = function() {
|
nickjillings@1563
|
1517 var root = document.createElement('comment');
|
nickjillings@1563
|
1518 root.id = this.specification.id;
|
nickjillings@1563
|
1519 root.setAttribute('type',this.specification.type);
|
nickjillings@1563
|
1520 var question = document.createElement('question');
|
nickjillings@1563
|
1521 question.textContent = this.string.textContent;
|
nickjillings@1563
|
1522 var response = document.createElement('response');
|
nickjillings@1563
|
1523 var i=0;
|
nickjillings@1563
|
1524 while(this.options[i].checked == false) {
|
nickjillings@1563
|
1525 i++;
|
nickjillings@1563
|
1526 if (i >= this.options.length) {
|
nickjillings@1563
|
1527 break;
|
nickjillings@1563
|
1528 }
|
nickjillings@1563
|
1529 }
|
nickjillings@1563
|
1530 if (i >= this.options.length) {
|
nickjillings@1563
|
1531 response.textContent = 'null';
|
nickjillings@1563
|
1532 } else {
|
nickjillings@1563
|
1533 response.textContent = this.options[i].getAttribute('setvalue');
|
nickjillings@1563
|
1534 response.setAttribute('number',i);
|
nickjillings@1563
|
1535 }
|
nickjillings@1563
|
1536 console.log('Comment: '+question.textContent);
|
nickjillings@1563
|
1537 console.log('Response: '+response.textContent);
|
nickjillings@1563
|
1538 root.appendChild(question);
|
nickjillings@1563
|
1539 root.appendChild(response);
|
nickjillings@1563
|
1540 return root;
|
nickjillings@1563
|
1541 };
|
nickjillings@1563
|
1542 };
|
nickjillings@1563
|
1543
|
nickjillings@1563
|
1544 this.checkboxBox = function(commentQuestion) {
|
nickjillings@1563
|
1545 this.specification = commentQuestion;
|
nickjillings@1563
|
1546 // Create document objects to hold the comment boxes
|
nickjillings@1563
|
1547 this.holder = document.createElement('div');
|
nickjillings@1563
|
1548 this.holder.className = 'comment-div';
|
nickjillings@1563
|
1549 // Create a string next to each comment asking for a comment
|
nickjillings@1563
|
1550 this.string = document.createElement('span');
|
nickjillings@1563
|
1551 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1563
|
1552 var br = document.createElement('br');
|
nickjillings@1563
|
1553 // Add to the holder.
|
nickjillings@1563
|
1554 this.holder.appendChild(this.string);
|
nickjillings@1563
|
1555 this.holder.appendChild(br);
|
nickjillings@1563
|
1556 this.options = [];
|
nickjillings@1563
|
1557 this.inputs = document.createElement('div');
|
nickjillings@1563
|
1558 this.span = document.createElement('div');
|
nickjillings@1563
|
1559 this.inputs.align = 'center';
|
nickjillings@1563
|
1560 this.inputs.style.marginLeft = '12px';
|
nickjillings@1563
|
1561 this.span.style.marginLeft = '12px';
|
nickjillings@1563
|
1562 this.span.align = 'center';
|
nickjillings@1563
|
1563 this.span.style.marginTop = '15px';
|
nickjillings@1563
|
1564
|
nickjillings@1563
|
1565 var optCount = commentQuestion.options.length;
|
nickjillings@1563
|
1566 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px';
|
nickjillings@1563
|
1567 console.log(spanMargin);
|
nickjillings@1563
|
1568 for (var i=0; i<optCount; i++)
|
nickjillings@1563
|
1569 {
|
nickjillings@1563
|
1570 var div = document.createElement('div');
|
nickjillings@1563
|
1571 div.style.width = '100px';
|
nickjillings@1563
|
1572 div.style.float = 'left';
|
nickjillings@1563
|
1573 div.style.marginRight = spanMargin;
|
nickjillings@1563
|
1574 div.style.marginLeft = spanMargin;
|
nickjillings@1563
|
1575 var input = document.createElement('input');
|
nickjillings@1563
|
1576 input.type = 'checkbox';
|
nickjillings@1563
|
1577 input.name = commentQuestion.id;
|
nickjillings@1563
|
1578 input.setAttribute('setvalue',commentQuestion.options[i].name);
|
nickjillings@1563
|
1579 input.className = 'comment-radio';
|
nickjillings@1563
|
1580 div.appendChild(input);
|
nickjillings@1563
|
1581 this.inputs.appendChild(div);
|
nickjillings@1563
|
1582
|
nickjillings@1563
|
1583
|
nickjillings@1563
|
1584 div = document.createElement('div');
|
nickjillings@1563
|
1585 div.style.width = '100px';
|
nickjillings@1563
|
1586 div.style.float = 'left';
|
nickjillings@1563
|
1587 div.style.marginRight = spanMargin;
|
nickjillings@1563
|
1588 div.style.marginLeft = spanMargin;
|
nickjillings@1563
|
1589 div.align = 'center';
|
nickjillings@1563
|
1590 var span = document.createElement('span');
|
nickjillings@1563
|
1591 span.textContent = commentQuestion.options[i].text;
|
nickjillings@1563
|
1592 span.className = 'comment-radio-span';
|
nickjillings@1563
|
1593 div.appendChild(span);
|
nickjillings@1563
|
1594 this.span.appendChild(div);
|
nickjillings@1563
|
1595 this.options.push(input);
|
nickjillings@1563
|
1596 }
|
nickjillings@1563
|
1597 this.holder.appendChild(this.span);
|
nickjillings@1563
|
1598 this.holder.appendChild(this.inputs);
|
nickjillings@1563
|
1599
|
nickjillings@1563
|
1600 this.exportXMLDOM = function() {
|
nickjillings@1563
|
1601 var root = document.createElement('comment');
|
nickjillings@1563
|
1602 root.id = this.specification.id;
|
nickjillings@1563
|
1603 root.setAttribute('type',this.specification.type);
|
nickjillings@1563
|
1604 var question = document.createElement('question');
|
nickjillings@1563
|
1605 question.textContent = this.string.textContent;
|
nickjillings@1563
|
1606 root.appendChild(question);
|
nickjillings@1563
|
1607 console.log('Comment: '+question.textContent);
|
nickjillings@1563
|
1608 for (var i=0; i<this.options.length; i++) {
|
nickjillings@1563
|
1609 var response = document.createElement('response');
|
nickjillings@1563
|
1610 response.textContent = this.options[i].checked;
|
nickjillings@1563
|
1611 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
|
nickjillings@1563
|
1612 root.appendChild(response);
|
nickjillings@1563
|
1613 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
|
nickjillings@1563
|
1614 }
|
nickjillings@1563
|
1615 return root;
|
nickjillings@1563
|
1616 };
|
nickjillings@1563
|
1617 };
|
nickjillings@1563
|
1618
|
nickjillings@1563
|
1619 this.createCommentBox = function(audioObject) {
|
nickjillings@1563
|
1620 var node = new this.elementCommentBox(audioObject);
|
nickjillings@1563
|
1621 this.commentBoxes.push(node);
|
nickjillings@1563
|
1622 audioObject.commentDOM = node;
|
nickjillings@1563
|
1623 return node;
|
nickjillings@1563
|
1624 };
|
nickjillings@1563
|
1625
|
nickjillings@1563
|
1626 this.sortCommentBoxes = function() {
|
nickjillings@1563
|
1627 var holder = [];
|
nickjillings@1563
|
1628 while (this.commentBoxes.length > 0) {
|
nickjillings@1563
|
1629 var node = this.commentBoxes.pop(0);
|
nickjillings@1563
|
1630 holder[node.id] = node;
|
nickjillings@1563
|
1631 }
|
nickjillings@1563
|
1632 this.commentBoxes = holder;
|
nickjillings@1563
|
1633 };
|
nickjillings@1563
|
1634
|
nickjillings@1563
|
1635 this.showCommentBoxes = function(inject, sort) {
|
nickjillings@1563
|
1636 if (sort) {interfaceContext.sortCommentBoxes();}
|
nickjillings@1563
|
1637 for (var i=0; i<interfaceContext.commentBoxes.length; i++) {
|
nickjillings@1563
|
1638 inject.appendChild(this.commentBoxes[i].trackComment);
|
nickjillings@1563
|
1639 }
|
nickjillings@1563
|
1640 };
|
nickjillings@1563
|
1641
|
nickjillings@1563
|
1642 this.createCommentQuestion = function(element) {
|
nickjillings@1563
|
1643 var node;
|
nickjillings@1563
|
1644 if (element.type == 'text') {
|
nickjillings@1563
|
1645 node = new this.commentBox(element);
|
nickjillings@1563
|
1646 } else if (element.type == 'radio') {
|
nickjillings@1563
|
1647 node = new this.radioBox(element);
|
nickjillings@1563
|
1648 } else if (element.type == 'checkbox') {
|
nickjillings@1563
|
1649 node = new this.checkboxBox(element);
|
nickjillings@1563
|
1650 }
|
nickjillings@1563
|
1651 this.commentQuestions.push(node);
|
nickjillings@1563
|
1652 return node;
|
nickjillings@1563
|
1653 };
|
nickjillings@1564
|
1654
|
nickjillings@1564
|
1655 this.playhead = new function()
|
nickjillings@1564
|
1656 {
|
nickjillings@1564
|
1657 this.object = document.createElement('div');
|
nickjillings@1564
|
1658 this.object.className = 'playhead';
|
nickjillings@1564
|
1659 this.object.align = 'left';
|
nickjillings@1564
|
1660 var curTime = document.createElement('div');
|
nickjillings@1564
|
1661 curTime.style.width = '50px';
|
nickjillings@1564
|
1662 this.curTimeSpan = document.createElement('span');
|
nickjillings@1564
|
1663 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1564
|
1664 curTime.appendChild(this.curTimeSpan);
|
nickjillings@1564
|
1665 this.object.appendChild(curTime);
|
nickjillings@1564
|
1666 this.scrubberTrack = document.createElement('div');
|
nickjillings@1564
|
1667 this.scrubberTrack.className = 'playhead-scrub-track';
|
nickjillings@1564
|
1668
|
nickjillings@1564
|
1669 this.scrubberHead = document.createElement('div');
|
nickjillings@1564
|
1670 this.scrubberHead.id = 'playhead-scrubber';
|
nickjillings@1564
|
1671 this.scrubberTrack.appendChild(this.scrubberHead);
|
nickjillings@1564
|
1672 this.object.appendChild(this.scrubberTrack);
|
nickjillings@1564
|
1673
|
nickjillings@1564
|
1674 this.timePerPixel = 0;
|
nickjillings@1564
|
1675 this.maxTime = 0;
|
nickjillings@1564
|
1676
|
nickjillings@1564
|
1677 this.startPlay = function(maxTime) {
|
nickjillings@1564
|
1678 //maxTime must be in seconds
|
nickjillings@1564
|
1679 var width = 490; //500 - 10, 5 each side of the tracker head
|
nickjillings@1564
|
1680 this.timePerPixel = maxTime/490;
|
nickjillings@1564
|
1681 this.maxTime = maxTime;
|
nickjillings@1564
|
1682 if (maxTime < 60) {
|
nickjillings@1564
|
1683 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1564
|
1684 } else {
|
nickjillings@1564
|
1685 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1564
|
1686 }
|
nickjillings@1564
|
1687 };
|
nickjillings@1564
|
1688
|
nickjillings@1564
|
1689 this.update = function(time) {
|
nickjillings@1564
|
1690 // Update the playhead position, startPlay must be called
|
nickjillings@1564
|
1691 if (this.timePerPixel > 0) {
|
nickjillings@1564
|
1692 var width = 490;
|
nickjillings@1564
|
1693 var pix = Math.floor(width*time);
|
nickjillings@1564
|
1694 this.scrubberHead.style.left = pix+'px';
|
nickjillings@1564
|
1695 if (this.maxTime > 60.0) {
|
nickjillings@1564
|
1696 var secs = time%60;
|
nickjillings@1564
|
1697 var mins = Math.floor((time-secs)/60);
|
nickjillings@1564
|
1698 secs = secs.toString();
|
nickjillings@1564
|
1699 secs = secs.substr(0,2);
|
nickjillings@1564
|
1700 mins = mins.toString();
|
nickjillings@1564
|
1701 this.curTimeSpan.textContent = mins+':'+secs;
|
nickjillings@1564
|
1702 } else {
|
nickjillings@1564
|
1703 time = time.toString();
|
nickjillings@1564
|
1704 this.curTimeSpan.textContent = time.substr(0,4);
|
nickjillings@1564
|
1705 }
|
nickjillings@1564
|
1706 }
|
nickjillings@1564
|
1707 };
|
nickjillings@1564
|
1708 };
|
nickjillings@1563
|
1709 }
|
nickjillings@1563
|
1710
|