nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@38
|
6 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
|
n@38
|
7 // preTest - In preTest state
|
n@38
|
8 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
9 // testRunPost-ID - Post test of test ID
|
n@38
|
10 // testRunPre-ID - Pre-test of test ID
|
n@38
|
11 // postTest - End of test, final submission!
|
n@38
|
12
|
n@32
|
13
|
b@102
|
14 // Create empty array to log whether different samples have been played
|
b@102
|
15 var hasBeenPlayed = []; // HERE?
|
b@102
|
16
|
b@102
|
17
|
nicholas@2
|
18 // Once this is loaded and parsed, begin execution
|
nicholas@2
|
19 loadInterface(projectXML);
|
nicholas@2
|
20
|
nicholas@2
|
21 function loadInterface(xmlDoc) {
|
nicholas@2
|
22
|
n@16
|
23 // Get the dimensions of the screen available to the page
|
nicholas@2
|
24 var width = window.innerWidth;
|
nicholas@2
|
25 var height = window.innerHeight;
|
nicholas@2
|
26
|
nicholas@2
|
27 // The injection point into the HTML page
|
nicholas@2
|
28 var insertPoint = document.getElementById("topLevelBody");
|
n@22
|
29 var testContent = document.createElement('div');
|
n@22
|
30 testContent.id = 'testContent';
|
nicholas@2
|
31
|
nicholas@7
|
32
|
nicholas@2
|
33 // Decode parts of the xmlDoc that are needed
|
nicholas@2
|
34 // xmlDoc MUST already be parsed by jQuery!
|
nicholas@2
|
35 var xmlSetup = xmlDoc.find('setup');
|
nicholas@2
|
36 // Should put in an error function here incase of malprocessed or malformed XML
|
nicholas@2
|
37
|
n@34
|
38 // Extract the different test XML DOM trees
|
n@50
|
39 var audioHolders = xmlDoc.find('audioHolder');
|
n@50
|
40 audioHolders.each(function(index,element) {
|
n@50
|
41 var repeatN = element.attributes['repeatCount'].value;
|
n@50
|
42 for (var r=0; r<=repeatN; r++) {
|
n@50
|
43 testXMLSetups[testXMLSetups.length] = element;
|
n@50
|
44 }
|
n@50
|
45 });
|
n@44
|
46
|
n@50
|
47 // New check if we need to randomise the test order
|
n@50
|
48 var randomise = xmlSetup[0].attributes['randomiseOrder'];
|
n@50
|
49 if (randomise != undefined) {
|
n@50
|
50 randomise = Boolean(randomise.value);
|
n@50
|
51 } else {
|
n@50
|
52 randomise = false;
|
n@50
|
53 }
|
n@50
|
54 if (randomise)
|
n@50
|
55 {
|
n@54
|
56 testXMLSetups = randomiseOrder(testXMLSetups);
|
n@50
|
57 }
|
n@44
|
58
|
n@50
|
59 // Obtain the metrics enabled
|
n@50
|
60 var metricNode = xmlSetup.find('Metric');
|
n@50
|
61 var metricNode = metricNode.find('metricEnable');
|
n@50
|
62 metricNode.each(function(index,node){
|
n@50
|
63 var enabled = node.textContent;
|
n@50
|
64 switch(enabled)
|
n@50
|
65 {
|
n@50
|
66 case 'testTimer':
|
n@50
|
67 sessionMetrics.prototype.enableTestTimer = true;
|
n@50
|
68 break;
|
n@50
|
69 case 'elementTimer':
|
n@50
|
70 sessionMetrics.prototype.enableElementTimer = true;
|
n@50
|
71 break;
|
n@50
|
72 case 'elementTracker':
|
n@50
|
73 sessionMetrics.prototype.enableElementTracker = true;
|
n@50
|
74 break;
|
n@50
|
75 case 'elementInitalPosition':
|
n@50
|
76 sessionMetrics.prototype.enableElementInitialPosition = true;
|
n@50
|
77 break;
|
n@50
|
78 case 'elementFlagListenedTo':
|
n@50
|
79 sessionMetrics.prototype.enableFlagListenedTo = true;
|
n@50
|
80 break;
|
n@50
|
81 case 'elementFlagMoved':
|
n@50
|
82 sessionMetrics.prototype.enableFlagMoved = true;
|
n@50
|
83 break;
|
n@50
|
84 case 'elementFlagComments':
|
n@50
|
85 sessionMetrics.prototype.enableFlagComments = true;
|
n@50
|
86 break;
|
n@50
|
87 }
|
n@50
|
88 });
|
n@34
|
89
|
n@52
|
90 // Create APE specific metric functions
|
n@52
|
91 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
92 {
|
n@52
|
93 var sliders = document.getElementsByClassName('track-slider');
|
n@52
|
94 for (var i=0; i<sliders.length; i++)
|
n@52
|
95 {
|
n@52
|
96 audioEngineContext.audioObjects[i].metric.initialised(convSliderPosToRate(i));
|
n@52
|
97 }
|
n@52
|
98 };
|
n@52
|
99
|
n@52
|
100 audioEngineContext.metric.sliderMoveStart = function(id)
|
n@52
|
101 {
|
n@52
|
102 if (this.data == -1)
|
n@52
|
103 {
|
n@52
|
104 this.data = id;
|
n@52
|
105 } else {
|
n@52
|
106 console.log('ERROR: Metric tracker detecting two moves!');
|
n@52
|
107 this.data = -1;
|
n@52
|
108 }
|
n@52
|
109 };
|
n@52
|
110 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
111 {
|
n@52
|
112 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
113 var id = this.data;
|
n@52
|
114 this.data = -1;
|
n@52
|
115 var position = convSliderPosToRate(id);
|
n@52
|
116 if (audioEngineContext.timer.testStarted)
|
n@52
|
117 {
|
n@52
|
118 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
119 }
|
n@52
|
120 };
|
n@52
|
121
|
n@52
|
122 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
123 {
|
n@52
|
124 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
125 if (audioEngineContext.timer.testStarted)
|
n@52
|
126 {
|
n@52
|
127 if (this.lastClicked >= 0)
|
n@52
|
128 {
|
n@52
|
129 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
130 }
|
n@52
|
131 this.lastClicked = id;
|
n@52
|
132 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
133 }
|
n@52
|
134 };
|
n@52
|
135
|
nicholas@2
|
136 // Create the top div for the Title element
|
nicholas@2
|
137 var titleAttr = xmlSetup[0].attributes['title'];
|
nicholas@2
|
138 var title = document.createElement('div');
|
nicholas@2
|
139 title.className = "title";
|
nicholas@2
|
140 title.align = "center";
|
nicholas@2
|
141 var titleSpan = document.createElement('span');
|
nicholas@2
|
142
|
nicholas@2
|
143 // Set title to that defined in XML, else set to default
|
nicholas@2
|
144 if (titleAttr != undefined) {
|
n@25
|
145 titleSpan.innerHTML = titleAttr.value;
|
nicholas@2
|
146 } else {
|
b@75
|
147 titleSpan.innerHTML = 'Listening test';
|
nicholas@2
|
148 }
|
nicholas@2
|
149 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
150 title.appendChild(titleSpan);
|
nicholas@2
|
151
|
n@47
|
152 var pagetitle = document.createElement('div');
|
n@47
|
153 pagetitle.className = "pageTitle";
|
n@47
|
154 pagetitle.align = "center";
|
n@47
|
155 var titleSpan = document.createElement('span');
|
n@47
|
156 titleSpan.id = "pageTitle";
|
n@47
|
157 pagetitle.appendChild(titleSpan);
|
n@47
|
158
|
nicholas@7
|
159 // Store the return URL path in global projectReturn
|
nicholas@7
|
160 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
|
nicholas@7
|
161
|
nicholas@7
|
162 // Create Interface buttons!
|
nicholas@7
|
163 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
164 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
165
|
nicholas@7
|
166 // MANUAL DOWNLOAD POINT
|
nicholas@7
|
167 // If project return is null, this MUST be specified as the location to create the download link
|
nicholas@7
|
168 var downloadPoint = document.createElement('div');
|
nicholas@7
|
169 downloadPoint.id = 'download-point';
|
nicholas@7
|
170
|
nicholas@7
|
171 // Create playback start/stop points
|
nicholas@7
|
172 var playback = document.createElement("button");
|
b@101
|
173 playback.innerHTML = 'Stop';
|
n@49
|
174 playback.id = 'playback-button';
|
n@16
|
175 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
176 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
177 playback.onclick = function() {
|
b@101
|
178 if (audioEngineContext.status == 1) {
|
b@101
|
179 audioEngineContext.stop();
|
n@25
|
180 this.innerHTML = 'Stop';
|
nicholas@7
|
181 }
|
n@16
|
182 };
|
nicholas@7
|
183 // Create Submit (save) button
|
nicholas@7
|
184 var submit = document.createElement("button");
|
n@25
|
185 submit.innerHTML = 'Submit';
|
n@43
|
186 submit.onclick = buttonSubmitClick;
|
n@49
|
187 submit.id = 'submit-button';
|
n@16
|
188 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
189 interfaceButtons.appendChild(playback);
|
nicholas@7
|
190 interfaceButtons.appendChild(submit);
|
nicholas@7
|
191 interfaceButtons.appendChild(downloadPoint);
|
nicholas@7
|
192
|
nicholas@2
|
193 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
194
|
n@16
|
195 // Create the div box to center align
|
nicholas@2
|
196 var sliderBox = document.createElement('div');
|
nicholas@2
|
197 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
198 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
199 sliderBox.align = 'center';
|
nicholas@2
|
200
|
n@16
|
201 // Create the slider box to hold the slider elements
|
nicholas@5
|
202 var canvas = document.createElement('div');
|
nicholas@2
|
203 canvas.id = 'slider';
|
n@16
|
204 // Must have a known EXACT width, as this is used later to determine the ratings
|
nicholas@5
|
205 canvas.style.width = width - 100 +"px";
|
nicholas@5
|
206 canvas.align = "left";
|
nicholas@2
|
207 sliderBox.appendChild(canvas);
|
n@16
|
208
|
n@47
|
209 // Create the div to hold any scale objects
|
n@47
|
210 var scale = document.createElement('div');
|
n@47
|
211 scale.className = 'sliderScale';
|
n@47
|
212 scale.id = 'sliderScaleHolder';
|
n@47
|
213 scale.align = 'left';
|
n@47
|
214 sliderBox.appendChild(scale);
|
n@47
|
215
|
n@16
|
216 // Global parent for the comment boxes on the page
|
nicholas@3
|
217 var feedbackHolder = document.createElement('div');
|
n@34
|
218 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
219
|
n@38
|
220 testContent.style.zIndex = 1;
|
n@38
|
221 insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
222
|
n@22
|
223 // Create pre and post test questions
|
n@38
|
224 var blank = document.createElement('div');
|
n@38
|
225 blank.className = 'testHalt';
|
n@22
|
226
|
n@38
|
227 var popupHolder = document.createElement('div');
|
n@38
|
228 popupHolder.id = 'popupHolder';
|
n@38
|
229 popupHolder.className = 'popupHolder';
|
n@38
|
230 popupHolder.style.position = 'absolute';
|
n@38
|
231 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
|
n@38
|
232 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
|
n@38
|
233 insertPoint.appendChild(popupHolder);
|
n@38
|
234 insertPoint.appendChild(blank);
|
n@38
|
235 hidePopup();
|
n@22
|
236
|
n@36
|
237 var preTest = xmlSetup.find('PreTest');
|
n@36
|
238 var postTest = xmlSetup.find('PostTest');
|
n@22
|
239 preTest = preTest[0];
|
n@22
|
240 postTest = postTest[0];
|
n@38
|
241
|
n@38
|
242 currentState = 'preTest';
|
n@22
|
243
|
n@22
|
244 // Create Pre-Test Box
|
n@22
|
245 if (preTest != undefined && preTest.children.length >= 1)
|
n@22
|
246 {
|
n@38
|
247 showPopup();
|
n@39
|
248 preTestPopupStart(preTest);
|
n@22
|
249 }
|
n@38
|
250
|
n@38
|
251 // Inject into HTML
|
n@38
|
252 testContent.appendChild(title); // Insert the title
|
n@47
|
253 testContent.appendChild(pagetitle);
|
n@38
|
254 testContent.appendChild(interfaceButtons);
|
n@38
|
255 testContent.appendChild(sliderBox);
|
n@38
|
256 testContent.appendChild(feedbackHolder);
|
n@38
|
257 insertPoint.appendChild(testContent);
|
n@22
|
258
|
n@36
|
259 // Load the full interface
|
n@39
|
260
|
nicholas@2
|
261 }
|
nicholas@5
|
262
|
n@39
|
263 function loadTest(id)
|
n@34
|
264 {
|
n@34
|
265 // Used to load a specific test page
|
n@39
|
266 var textXML = testXMLSetups[id];
|
n@34
|
267
|
n@34
|
268 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
269 var canvas = document.getElementById('slider');
|
n@34
|
270 feedbackHolder.innerHTML = null;
|
n@34
|
271 canvas.innerHTML = null;
|
n@47
|
272
|
n@47
|
273 // Setup question title
|
n@47
|
274 var interfaceObj = $(textXML).find('interface');
|
n@47
|
275 var titleNode = interfaceObj.find('title');
|
n@47
|
276 if (titleNode[0] != undefined)
|
n@47
|
277 {
|
n@47
|
278 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
|
n@47
|
279 }
|
n@47
|
280 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@47
|
281 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
|
n@47
|
282 // TODO: AUTOMATE ABOVE!!
|
n@47
|
283 var scale = document.getElementById('sliderScaleHolder');
|
n@47
|
284 scale.innerHTML = null;
|
n@47
|
285 interfaceObj.find('scale').each(function(index,scaleObj){
|
n@47
|
286 var position = Number(scaleObj.attributes['position'].value)*0.01;
|
n@47
|
287 var pixelPosition = (position*positionScale)+offset;
|
n@47
|
288 var scaleDOM = document.createElement('span');
|
n@47
|
289 scaleDOM.textContent = scaleObj.textContent;
|
n@47
|
290 scale.appendChild(scaleDOM);
|
n@47
|
291 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@47
|
292 });
|
n@34
|
293
|
n@34
|
294 // Extract the hostURL attribute. If not set, create an empty string.
|
n@34
|
295 var hostURL = textXML.attributes['hostURL'];
|
n@34
|
296 if (hostURL == undefined) {
|
n@34
|
297 hostURL = "";
|
n@34
|
298 } else {
|
n@34
|
299 hostURL = hostURL.value;
|
n@34
|
300 }
|
n@34
|
301 // Extract the sampleRate. If set, convert the string to a Number.
|
n@34
|
302 var hostFs = textXML.attributes['sampleRate'];
|
n@34
|
303 if (hostFs != undefined) {
|
n@34
|
304 hostFs = Number(hostFs.value);
|
n@34
|
305 }
|
n@34
|
306
|
n@34
|
307 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@34
|
308 if (hostFs != undefined) {
|
n@34
|
309 if (Number(hostFs) != audioContext.sampleRate) {
|
n@34
|
310 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
311 alert(errStr);
|
n@34
|
312 return;
|
n@34
|
313 }
|
n@34
|
314 }
|
n@45
|
315
|
nicholas@66
|
316 var commentShow = textXML.attributes['elementComments'];
|
nicholas@66
|
317 if (commentShow != undefined) {
|
nicholas@66
|
318 if (commentShow.value == 'false') {commentShow = false;}
|
nicholas@66
|
319 else {commentShow = true;}
|
nicholas@66
|
320 } else {commentShow = true;}
|
nicholas@66
|
321
|
n@57
|
322 var loopPlayback = textXML.attributes['loop'];
|
n@57
|
323 if (loopPlayback != undefined)
|
n@57
|
324 {
|
n@57
|
325 loopPlayback = loopPlayback.value;
|
n@57
|
326 if (loopPlayback == 'true') {
|
n@57
|
327 loopPlayback = true;
|
n@57
|
328 } else {
|
n@57
|
329 loopPlayback = false;
|
n@57
|
330 }
|
n@57
|
331 } else {
|
n@57
|
332 loopPlayback = false;
|
n@57
|
333 }
|
n@57
|
334 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
335
|
n@57
|
336 // Create AudioEngine bindings for playback
|
n@57
|
337 if (loopPlayback) {
|
n@57
|
338 audioEngineContext.play = function() {
|
n@57
|
339 // Send play command to all playback buffers for synchronised start
|
n@57
|
340 // Also start timer callbacks to detect if playback has finished
|
n@57
|
341 if (this.status == 0) {
|
n@57
|
342 this.timer.startTest();
|
n@57
|
343 // First get current clock
|
n@57
|
344 var timer = audioContext.currentTime;
|
n@57
|
345 // Add 3 seconds
|
n@57
|
346 timer += 3.0;
|
n@57
|
347 // Send play to all tracks
|
n@57
|
348 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
349 {
|
n@57
|
350 this.audioObjects[i].play(timer);
|
n@57
|
351 }
|
n@57
|
352 this.status = 1;
|
n@57
|
353 }
|
n@57
|
354 };
|
n@57
|
355
|
n@57
|
356 audioEngineContext.stop = function() {
|
n@57
|
357 // Send stop and reset command to all playback buffers
|
n@57
|
358 if (this.status == 1) {
|
n@57
|
359 if (this.loopPlayback) {
|
n@57
|
360 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
361 {
|
n@57
|
362 this.audioObjects[i].stop();
|
n@57
|
363 }
|
n@57
|
364 }
|
n@57
|
365 this.status = 0;
|
n@57
|
366 }
|
n@57
|
367 };
|
n@57
|
368
|
n@57
|
369 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
370 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
371 {
|
n@57
|
372 if (id == i) {
|
n@57
|
373 this.audioObjects[i].outputGain.gain.value = 1.0;
|
n@57
|
374 } else {
|
n@57
|
375 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@57
|
376 }
|
n@57
|
377 }
|
n@57
|
378 };
|
n@57
|
379 } else {
|
n@57
|
380 audioEngineContext.play = function() {
|
n@57
|
381 // Send play command to all playback buffers for synchronised start
|
n@57
|
382 // Also start timer callbacks to detect if playback has finished
|
n@57
|
383 if (this.status == 0) {
|
n@57
|
384 this.timer.startTest();
|
n@57
|
385 this.status = 1;
|
n@57
|
386 }
|
n@57
|
387 };
|
n@57
|
388
|
n@57
|
389 audioEngineContext.stop = function() {
|
n@57
|
390 // Send stop and reset command to all playback buffers
|
n@57
|
391 if (this.status == 1) {
|
n@57
|
392 if (this.loopPlayback) {
|
n@57
|
393 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
394 {
|
n@57
|
395 this.audioObjects[i].stop();
|
n@57
|
396 }
|
n@57
|
397 }
|
n@57
|
398 this.status = 0;
|
n@57
|
399 }
|
n@57
|
400 };
|
n@57
|
401
|
n@57
|
402 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
403 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
404 {
|
n@57
|
405 if (id == i) {
|
n@57
|
406 this.audioObjects[i].outputGain.gain.value = 1.0;
|
n@57
|
407 this.audioObjects[i].play(audioContext.currentTime+0.01);
|
n@57
|
408 } else {
|
n@57
|
409 this.audioObjects[i].outputGain.gain.value = 0.0;
|
d@80
|
410 this.audioObjects[i].stop();
|
n@57
|
411 }
|
n@57
|
412 }
|
n@57
|
413 };
|
n@57
|
414 }
|
n@57
|
415
|
n@46
|
416 currentTestHolder = document.createElement('audioHolder');
|
n@46
|
417 currentTestHolder.id = textXML.id;
|
n@46
|
418 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
|
n@46
|
419 var currentPreTestHolder = document.createElement('preTest');
|
n@46
|
420 var currentPostTestHolder = document.createElement('postTest');
|
n@46
|
421 currentTestHolder.appendChild(currentPreTestHolder);
|
n@46
|
422 currentTestHolder.appendChild(currentPostTestHolder);
|
n@46
|
423
|
n@45
|
424 var randomise = textXML.attributes['randomiseOrder'];
|
n@45
|
425 if (randomise != undefined) {randomise = randomise.value;}
|
n@45
|
426 else {randomise = false;}
|
n@45
|
427
|
n@34
|
428 var audioElements = $(textXML).find('audioElements');
|
nicholas@58
|
429 currentTrackOrder = [];
|
n@34
|
430 audioElements.each(function(index,element){
|
n@45
|
431 // Find any blind-repeats
|
b@100
|
432 // Not implemented yet, but just in case
|
n@45
|
433 currentTrackOrder[index] = element;
|
n@45
|
434 });
|
n@45
|
435 if (randomise) {
|
n@54
|
436 currentTrackOrder = randomiseOrder(currentTrackOrder);
|
n@45
|
437 }
|
n@45
|
438
|
nicholas@58
|
439 // Delete any previous audioObjects associated with the audioEngine
|
nicholas@58
|
440 audioEngineContext.audioObjects = [];
|
nicholas@58
|
441
|
n@45
|
442 // Find all the audioElements from the audioHolder
|
n@45
|
443 $(currentTrackOrder).each(function(index,element){
|
n@34
|
444 // Find URL of track
|
n@34
|
445 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
446
|
n@34
|
447 // Now load each audio sample. First create the new track by passing the full URL
|
n@34
|
448 var trackURL = hostURL + this.attributes['url'].value;
|
n@34
|
449 audioEngineContext.newTrack(trackURL);
|
nicholas@66
|
450
|
nicholas@66
|
451 if (commentShow) {
|
nicholas@66
|
452 // Create document objects to hold the comment boxes
|
nicholas@66
|
453 var trackComment = document.createElement('div');
|
nicholas@66
|
454 trackComment.className = 'comment-div';
|
nicholas@66
|
455 // Create a string next to each comment asking for a comment
|
nicholas@66
|
456 var trackString = document.createElement('span');
|
nicholas@66
|
457 trackString.innerHTML = 'Comment on track '+index;
|
nicholas@66
|
458 // Create the HTML5 comment box 'textarea'
|
nicholas@66
|
459 var trackCommentBox = document.createElement('textarea');
|
nicholas@66
|
460 trackCommentBox.rows = '4';
|
nicholas@66
|
461 trackCommentBox.cols = '100';
|
nicholas@66
|
462 trackCommentBox.name = 'trackComment'+index;
|
nicholas@66
|
463 trackCommentBox.className = 'trackComment';
|
nicholas@66
|
464 var br = document.createElement('br');
|
nicholas@66
|
465 // Add to the holder.
|
nicholas@66
|
466 trackComment.appendChild(trackString);
|
nicholas@66
|
467 trackComment.appendChild(br);
|
nicholas@66
|
468 trackComment.appendChild(trackCommentBox);
|
nicholas@66
|
469 feedbackHolder.appendChild(trackComment);
|
nicholas@66
|
470 }
|
n@34
|
471
|
n@34
|
472 // Create a slider per track
|
n@34
|
473
|
n@34
|
474 var trackSliderObj = document.createElement('div');
|
n@34
|
475 trackSliderObj.className = 'track-slider';
|
n@34
|
476 trackSliderObj.id = 'track-slider-'+index;
|
n@34
|
477 // Distribute it randomnly
|
n@34
|
478 var w = window.innerWidth - 100;
|
n@34
|
479 w = Math.random()*w;
|
n@34
|
480 trackSliderObj.style.left = Math.floor(w)+50+'px';
|
n@34
|
481 trackSliderObj.innerHTML = '<span>'+index+'</span>';
|
n@34
|
482 trackSliderObj.draggable = true;
|
n@34
|
483 trackSliderObj.ondragend = dragEnd;
|
n@49
|
484 trackSliderObj.ondragstart = function()
|
n@49
|
485 {
|
n@49
|
486 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
487 audioEngineContext.metric.sliderMoveStart(id);
|
n@49
|
488 };
|
n@34
|
489
|
n@34
|
490 // Onclick, switch playback to that track
|
n@34
|
491 trackSliderObj.onclick = function() {
|
n@34
|
492 // Get the track ID from the object ID
|
n@34
|
493 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
494 audioEngineContext.metric.sliderPlayed(id);
|
n@34
|
495 audioEngineContext.selectedTrack(id);
|
b@100
|
496 // Currently playing track red, rest green
|
b@100
|
497 document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
b@100
|
498 for (var i = 0; i<$(currentTrackOrder).length; i++)
|
b@100
|
499 {
|
b@102
|
500 if (i!=index) // Make all other sliders green
|
b@100
|
501 {
|
b@100
|
502 document.getElementById('track-slider-'+i).style.backgroundColor = "rgb(100,200,100)";
|
b@100
|
503 }
|
b@100
|
504
|
b@100
|
505 }
|
b@101
|
506 audioEngineContext.play();
|
b@102
|
507 hasBeenPlayed[index] = true; // mark as played
|
n@34
|
508 };
|
n@34
|
509
|
n@34
|
510 canvas.appendChild(trackSliderObj);
|
b@102
|
511
|
b@102
|
512 // Add corresponding element to array to check whether sound has been played
|
b@102
|
513 hasBeenPlayed.push(false);
|
n@34
|
514 });
|
n@39
|
515
|
nicholas@65
|
516 // Append any commentQuestion boxes
|
nicholas@65
|
517 var commentQuestions = $(textXML).find('CommentQuestion');
|
nicholas@65
|
518 $(commentQuestions).each(function(index,element) {
|
nicholas@65
|
519 // Create document objects to hold the comment boxes
|
nicholas@65
|
520 var trackComment = document.createElement('div');
|
nicholas@65
|
521 trackComment.className = 'comment-div commentQuestion';
|
nicholas@65
|
522 trackComment.id = element.attributes['id'].value;
|
nicholas@65
|
523 // Create a string next to each comment asking for a comment
|
nicholas@65
|
524 var trackString = document.createElement('span');
|
nicholas@65
|
525 trackString.innerHTML = element.textContent;
|
nicholas@65
|
526 // Create the HTML5 comment box 'textarea'
|
nicholas@65
|
527 var trackCommentBox = document.createElement('textarea');
|
nicholas@65
|
528 trackCommentBox.rows = '4';
|
nicholas@65
|
529 trackCommentBox.cols = '100';
|
nicholas@65
|
530 trackCommentBox.name = 'commentQuestion'+index;
|
nicholas@65
|
531 trackCommentBox.className = 'trackComment';
|
nicholas@65
|
532 var br = document.createElement('br');
|
nicholas@65
|
533 // Add to the holder.
|
nicholas@65
|
534 trackComment.appendChild(trackString);
|
nicholas@65
|
535 trackComment.appendChild(br);
|
nicholas@65
|
536 trackComment.appendChild(trackCommentBox);
|
nicholas@65
|
537 feedbackHolder.appendChild(trackComment);
|
nicholas@65
|
538 });
|
nicholas@65
|
539
|
n@39
|
540 // Now process any pre-test commands
|
n@39
|
541
|
n@44
|
542 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
|
n@39
|
543 if (preTest.children.length > 0)
|
n@39
|
544 {
|
n@39
|
545 currentState = 'testRunPre-'+id;
|
n@39
|
546 preTestPopupStart(preTest);
|
n@39
|
547 showPopup();
|
n@39
|
548 } else {
|
n@39
|
549 currentState = 'testRun-'+id;
|
n@39
|
550 }
|
n@39
|
551 }
|
n@39
|
552
|
n@39
|
553 function preTestPopupStart(preTest)
|
n@39
|
554 {
|
n@39
|
555 var popupHolder = document.getElementById('popupHolder');
|
n@39
|
556 popupHolder.innerHTML = null;
|
n@39
|
557 // Parse the first box
|
n@39
|
558 var preTestOption = document.createElement('div');
|
n@39
|
559 preTestOption.id = 'preTest';
|
n@39
|
560 preTestOption.style.marginTop = '25px';
|
n@39
|
561 preTestOption.align = "center";
|
n@39
|
562 var child = preTest.children[0];
|
n@39
|
563 if (child.nodeName == 'statement')
|
n@39
|
564 {
|
n@39
|
565 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@39
|
566 } else if (child.nodeName == 'question')
|
n@39
|
567 {
|
n@39
|
568 var questionId = child.attributes['id'].value;
|
n@39
|
569 var textHold = document.createElement('span');
|
n@39
|
570 textHold.innerHTML = child.innerHTML;
|
n@39
|
571 textHold.id = questionId + 'response';
|
n@39
|
572 var textEnter = document.createElement('textarea');
|
n@39
|
573 preTestOption.appendChild(textHold);
|
n@39
|
574 preTestOption.appendChild(textEnter);
|
n@39
|
575 }
|
n@39
|
576 var nextButton = document.createElement('button');
|
n@39
|
577 nextButton.className = 'popupButton';
|
n@39
|
578 nextButton.value = '0';
|
n@39
|
579 nextButton.innerHTML = 'Next';
|
n@39
|
580 nextButton.onclick = popupButtonClick;
|
n@39
|
581
|
n@39
|
582 popupHolder.appendChild(preTestOption);
|
n@39
|
583 popupHolder.appendChild(nextButton);
|
n@34
|
584 }
|
n@34
|
585
|
n@38
|
586 function popupButtonClick()
|
n@38
|
587 {
|
n@38
|
588 // Global call from the 'Next' button click
|
n@38
|
589 if (currentState == 'preTest')
|
n@38
|
590 {
|
n@38
|
591 // At the start of the preTest routine!
|
n@39
|
592 var xmlTree = projectXML.find('setup');
|
n@39
|
593 var preTest = xmlTree.find('PreTest')[0];
|
n@39
|
594 this.value = preTestButtonClick(preTest,this.value);
|
n@39
|
595 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
596 {
|
n@39
|
597 //Specific test pre-test
|
n@39
|
598 var testId = currentState.substr(11,currentState.length-10);
|
n@44
|
599 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
|
n@39
|
600 this.value = preTestButtonClick(preTest,this.value);
|
n@42
|
601 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
602 {
|
n@42
|
603 // Specific test post-test
|
n@42
|
604 var testId = currentState.substr(12,currentState.length-11);
|
n@44
|
605 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@42
|
606 this.value = preTestButtonClick(preTest,this.value);
|
n@41
|
607 } else if (currentState == 'postTest')
|
n@41
|
608 {
|
n@41
|
609 // At the end of the test, running global post test
|
n@41
|
610 var xmlTree = projectXML.find('setup');
|
n@41
|
611 var PostTest = xmlTree.find('PostTest')[0];
|
n@41
|
612 this.value = preTestButtonClick(PostTest,this.value);
|
n@38
|
613 }
|
n@38
|
614 }
|
n@38
|
615
|
n@39
|
616 function preTestButtonClick(preTest,index)
|
n@34
|
617 {
|
n@34
|
618 // Called on click of pre-test button
|
n@36
|
619 // Need to find and parse preTest again!
|
n@36
|
620 var preTestOption = document.getElementById('preTest');
|
n@36
|
621 // Check if current state is a question!
|
n@38
|
622 if (preTest.children[index].nodeName == 'question') {
|
n@38
|
623 var questionId = preTest.children[index].attributes['id'].value;
|
n@36
|
624 var questionHold = document.createElement('comment');
|
n@36
|
625 var questionResponse = document.getElementById(questionId + 'response');
|
nicholas@64
|
626 var mandatory = preTest.children[index].attributes['mandatory'];
|
nicholas@64
|
627 if (mandatory != undefined){
|
nicholas@64
|
628 if (mandatory.value == 'true') {mandatory = true;}
|
nicholas@64
|
629 else {mandatory = false;}
|
nicholas@64
|
630 } else {mandatory = false;}
|
nicholas@64
|
631 if (mandatory == true && questionResponse.value.length == 0) {
|
nicholas@64
|
632 return index;
|
nicholas@64
|
633 }
|
n@36
|
634 questionHold.id = questionId;
|
n@36
|
635 questionHold.innerHTML = questionResponse.value;
|
n@46
|
636 postPopupResponse(questionHold);
|
n@36
|
637 }
|
n@38
|
638 index++;
|
n@38
|
639 if (index < preTest.children.length)
|
n@36
|
640 {
|
n@36
|
641 // More to process
|
n@38
|
642 var child = preTest.children[index];
|
n@36
|
643 if (child.nodeName == 'statement')
|
n@36
|
644 {
|
n@36
|
645 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@36
|
646 } else if (child.nodeName == 'question')
|
n@36
|
647 {
|
n@36
|
648 var textHold = document.createElement('span');
|
n@36
|
649 textHold.innerHTML = child.innerHTML;
|
n@36
|
650 var textEnter = document.createElement('textarea');
|
n@36
|
651 textEnter.id = child.attributes['id'].value + 'response';
|
n@36
|
652 var br = document.createElement('br');
|
n@36
|
653 preTestOption.innerHTML = null;
|
n@36
|
654 preTestOption.appendChild(textHold);
|
n@36
|
655 preTestOption.appendChild(br);
|
n@36
|
656 preTestOption.appendChild(textEnter);
|
n@36
|
657 }
|
n@36
|
658 } else {
|
n@36
|
659 // Time to clear
|
n@37
|
660 preTestOption.innerHTML = null;
|
n@43
|
661 if (currentState != 'postTest') {
|
n@43
|
662 hidePopup();
|
n@43
|
663 // Progress the state!
|
n@43
|
664 advanceState();
|
n@43
|
665 } else {
|
n@43
|
666 a = createProjectSave(projectReturn);
|
n@43
|
667 preTestOption.appendChild(a);
|
n@43
|
668 }
|
n@36
|
669 }
|
n@38
|
670 return index;
|
n@36
|
671 }
|
n@36
|
672
|
n@46
|
673 function postPopupResponse(response)
|
n@46
|
674 {
|
n@46
|
675 if (currentState == 'preTest') {
|
n@46
|
676 preTestQuestions.appendChild(response);
|
n@46
|
677 } else if (currentState == 'postTest') {
|
n@46
|
678 postTestQuestions.appendChild(response);
|
n@46
|
679 } else {
|
n@46
|
680 // Inside a specific test
|
n@46
|
681 if (currentState.substr(0,10) == 'testRunPre') {
|
n@46
|
682 // Pre Test
|
n@46
|
683 var store = $(currentTestHolder).find('preTest');
|
n@46
|
684 } else {
|
n@46
|
685 // Post Test
|
n@46
|
686 var store = $(currentTestHolder).find('postTest');
|
n@46
|
687 }
|
n@46
|
688 store[0].appendChild(response);
|
n@46
|
689 }
|
n@46
|
690 }
|
n@46
|
691
|
n@36
|
692 function showPopup()
|
n@36
|
693 {
|
n@37
|
694 var popupHolder = document.getElementById('popupHolder');
|
n@38
|
695 popupHolder.style.zIndex = 3;
|
n@37
|
696 popupHolder.style.visibility = 'visible';
|
n@37
|
697 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
698 blank.style.zIndex = 2;
|
n@37
|
699 blank.style.visibility = 'visible';
|
n@36
|
700 }
|
n@36
|
701
|
n@36
|
702 function hidePopup()
|
n@36
|
703 {
|
n@37
|
704 var popupHolder = document.getElementById('popupHolder');
|
n@37
|
705 popupHolder.style.zIndex = -1;
|
n@37
|
706 popupHolder.style.visibility = 'hidden';
|
n@37
|
707 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
708 blank.style.zIndex = -2;
|
n@37
|
709 blank.style.visibility = 'hidden';
|
n@34
|
710 }
|
n@34
|
711
|
nicholas@5
|
712 function dragEnd(ev) {
|
nicholas@5
|
713 // Function call when a div has been dropped
|
n@33
|
714 var slider = document.getElementById('slider');
|
n@51
|
715 var w = slider.style.width;
|
n@51
|
716 w = Number(w.substr(0,w.length-2));
|
n@51
|
717 var x = ev.x;
|
n@51
|
718 if (x >= 42 && x < w+42) {
|
n@51
|
719 this.style.left = (x)+'px';
|
nicholas@5
|
720 } else {
|
n@51
|
721 if (x<42) {
|
n@51
|
722 this.style.left = '42px';
|
nicholas@5
|
723 } else {
|
n@51
|
724 this.style.left = (w+42) + 'px';
|
nicholas@5
|
725 }
|
nicholas@5
|
726 }
|
n@49
|
727 audioEngineContext.metric.sliderMoved();
|
nicholas@5
|
728 }
|
nicholas@7
|
729
|
n@39
|
730 function advanceState()
|
n@39
|
731 {
|
n@39
|
732 console.log(currentState);
|
n@39
|
733 if (currentState == 'preTest')
|
n@39
|
734 {
|
n@39
|
735 // End of pre-test, begin the test
|
n@39
|
736 loadTest(0);
|
n@39
|
737 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
738 {
|
n@39
|
739 // Start the test
|
n@39
|
740 var testId = currentState.substr(11,currentState.length-10);
|
n@39
|
741 currentState = 'testRun-'+testId;
|
n@42
|
742 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
743 {
|
n@44
|
744 var testId = currentState.substr(12,currentState.length-11);
|
n@42
|
745 testEnded(testId);
|
n@40
|
746 } else if (currentState.substr(0,7) == 'testRun')
|
n@40
|
747 {
|
n@40
|
748 var testId = currentState.substr(8,currentState.length-7);
|
n@40
|
749 // Check if we have any post tests to perform
|
n@44
|
750 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
|
nicholas@69
|
751 if (postXML == undefined) {
|
nicholas@69
|
752 testEnded(testId);
|
nicholas@69
|
753 }
|
nicholas@69
|
754 else if (postXML.children.length > 0)
|
n@40
|
755 {
|
n@42
|
756 currentState = 'testRunPost-'+testId;
|
n@42
|
757 showPopup();
|
n@42
|
758 preTestPopupStart(postXML);
|
n@40
|
759 }
|
n@42
|
760 else {
|
n@40
|
761
|
n@40
|
762
|
n@42
|
763 // No post tests, check if we have another test to perform instead
|
nicholas@69
|
764
|
n@40
|
765 }
|
n@39
|
766 }
|
n@39
|
767 console.log(currentState);
|
n@39
|
768 }
|
n@39
|
769
|
n@42
|
770 function testEnded(testId)
|
n@42
|
771 {
|
n@45
|
772 pageXMLSave(testId);
|
n@42
|
773 if (testXMLSetups.length-1 > testId)
|
n@42
|
774 {
|
n@42
|
775 // Yes we have another test to perform
|
n@44
|
776 testId = (Number(testId)+1);
|
n@44
|
777 currentState = 'testRun-'+testId;
|
n@44
|
778 loadTest(testId);
|
n@42
|
779 } else {
|
n@42
|
780 console.log('Testing Completed!');
|
n@42
|
781 currentState = 'postTest';
|
n@42
|
782 // Check for any post tests
|
n@42
|
783 var xmlSetup = projectXML.find('setup');
|
n@42
|
784 var postTest = xmlSetup.find('PostTest')[0];
|
n@42
|
785 showPopup();
|
n@42
|
786 preTestPopupStart(postTest);
|
n@42
|
787 }
|
n@42
|
788 }
|
n@42
|
789
|
b@101
|
790 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
n@40
|
791 {
|
b@102
|
792 if (hasBeenPlayed.indexOf(false)==-1)
|
b@102
|
793 {
|
b@102
|
794 if (audioEngineContext.status == 1) {
|
b@102
|
795 var playback = document.getElementById('playback-button');
|
b@102
|
796 playback.click();
|
b@102
|
797 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
b@102
|
798 } else
|
b@102
|
799 {
|
b@102
|
800 if (audioEngineContext.timer.testStarted == false)
|
b@102
|
801 {
|
b@102
|
802 alert('You have not started the test! Please press start to begin the test!');
|
b@102
|
803 return;
|
b@102
|
804 }
|
b@102
|
805 }
|
b@102
|
806 if (currentState.substr(0,7) == 'testRun')
|
b@102
|
807 {
|
b@102
|
808 hasBeenPlayed = []; // clear array to prepare for next test
|
b@102
|
809 audioEngineContext.timer.stopTest();
|
b@102
|
810 advanceState();
|
b@102
|
811 }
|
b@102
|
812 } else // if a fragment has not been played yet
|
b@102
|
813 {
|
b@102
|
814 alert('You have not played fragment ' + hasBeenPlayed.indexOf(false) + ' yet. Please listen, rate and comment all samples before submitting.');
|
b@102
|
815 return;
|
b@102
|
816 }
|
n@40
|
817 }
|
n@40
|
818
|
n@51
|
819 function convSliderPosToRate(id)
|
n@51
|
820 {
|
n@51
|
821 var w = document.getElementById('slider').style.width;
|
n@51
|
822 var maxPix = w.substr(0,w.length-2);
|
n@51
|
823 var slider = document.getElementsByClassName('track-slider')[id];
|
n@51
|
824 var pix = slider.style.left;
|
n@51
|
825 pix = pix.substr(0,pix.length-2);
|
n@51
|
826 var rate = (pix-42)/maxPix;
|
n@51
|
827 return rate;
|
n@51
|
828 }
|
n@51
|
829
|
n@44
|
830 function pageXMLSave(testId)
|
n@44
|
831 {
|
n@44
|
832 // Saves a specific test page
|
n@46
|
833 var xmlDoc = currentTestHolder;
|
n@50
|
834 // Check if any session wide metrics are enabled
|
nicholas@67
|
835
|
nicholas@67
|
836 var commentShow = testXMLSetups[testId].attributes['elementComments'];
|
nicholas@67
|
837 if (commentShow != undefined) {
|
nicholas@67
|
838 if (commentShow.value == 'false') {commentShow = false;}
|
nicholas@67
|
839 else {commentShow = true;}
|
nicholas@67
|
840 } else {commentShow = true;}
|
nicholas@67
|
841
|
n@50
|
842 var metric = document.createElement('metric');
|
n@50
|
843 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
844 {
|
n@50
|
845 var testTime = document.createElement('metricResult');
|
n@50
|
846 testTime.id = 'testTime';
|
n@50
|
847 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
848 metric.appendChild(testTime);
|
n@50
|
849 }
|
n@50
|
850 xmlDoc.appendChild(metric);
|
n@45
|
851 var trackSliderObjects = document.getElementsByClassName('track-slider');
|
n@45
|
852 var commentObjects = document.getElementsByClassName('comment-div');
|
n@45
|
853 for (var i=0; i<trackSliderObjects.length; i++)
|
n@45
|
854 {
|
n@45
|
855 var audioElement = document.createElement('audioElement');
|
n@45
|
856 audioElement.id = currentTrackOrder[i].attributes['id'].value;
|
n@45
|
857 audioElement.url = currentTrackOrder[i].attributes['url'].value;
|
n@51
|
858 var value = document.createElement('value');
|
n@51
|
859 value.innerHTML = convSliderPosToRate(i);
|
nicholas@67
|
860 if (commentShow) {
|
nicholas@67
|
861 var comment = document.createElement("comment");
|
nicholas@67
|
862 var question = document.createElement("question");
|
nicholas@67
|
863 var response = document.createElement("response");
|
nicholas@67
|
864 question.textContent = commentObjects[i].children[0].textContent;
|
nicholas@67
|
865 response.textContent = commentObjects[i].children[2].value;
|
nicholas@67
|
866 comment.appendChild(question);
|
nicholas@67
|
867 comment.appendChild(response);
|
nicholas@67
|
868 audioElement.appendChild(comment);
|
nicholas@67
|
869 }
|
n@45
|
870 audioElement.appendChild(value);
|
n@50
|
871 // Check for any per element metrics
|
n@50
|
872 var metric = document.createElement('metric');
|
n@50
|
873 var elementMetric = audioEngineContext.audioObjects[i].metric;
|
n@50
|
874 if (audioEngineContext.metric.enableElementTimer) {
|
n@50
|
875 var elementTimer = document.createElement('metricResult');
|
n@50
|
876 elementTimer.id = 'elementTimer';
|
n@50
|
877 elementTimer.textContent = elementMetric.listenedTimer;
|
n@50
|
878 metric.appendChild(elementTimer);
|
n@50
|
879 }
|
n@50
|
880 if (audioEngineContext.metric.enableElementTracker) {
|
n@50
|
881 var elementTrackerFull = document.createElement('metricResult');
|
n@50
|
882 elementTrackerFull.id = 'elementTrackerFull';
|
n@50
|
883 var data = elementMetric.movementTracker;
|
n@50
|
884 for (var k=0; k<data.length; k++)
|
n@50
|
885 {
|
n@50
|
886 var timePos = document.createElement('timePos');
|
n@50
|
887 timePos.id = k;
|
n@50
|
888 var time = document.createElement('time');
|
n@50
|
889 time.textContent = data[k][0];
|
n@50
|
890 var position = document.createElement('position');
|
n@50
|
891 position.textContent = data[k][1];
|
n@50
|
892 timePos.appendChild(time);
|
n@50
|
893 timePos.appendChild(position);
|
n@50
|
894 elementTrackerFull.appendChild(timePos);
|
n@50
|
895 }
|
n@50
|
896 metric.appendChild(elementTrackerFull);
|
n@50
|
897 }
|
n@50
|
898 if (audioEngineContext.metric.enableElementInitialPosition) {
|
n@50
|
899 var elementInitial = document.createElement('metricResult');
|
n@50
|
900 elementInitial.id = 'elementInitialPosition';
|
n@50
|
901 elementInitial.textContent = elementMetric.initialPosition;
|
n@50
|
902 metric.appendChild(elementInitial);
|
n@50
|
903 }
|
n@50
|
904 if (audioEngineContext.metric.enableFlagListenedTo) {
|
n@50
|
905 var flagListenedTo = document.createElement('metricResult');
|
n@50
|
906 flagListenedTo.id = 'elementFlagListenedTo';
|
n@50
|
907 flagListenedTo.textContent = elementMetric.wasListenedTo;
|
n@50
|
908 metric.appendChild(flagListenedTo);
|
n@50
|
909 }
|
n@50
|
910 if (audioEngineContext.metric.enableFlagMoved) {
|
n@50
|
911 var flagMoved = document.createElement('metricResult');
|
n@50
|
912 flagMoved.id = 'elementFlagMoved';
|
n@50
|
913 flagMoved.textContent = elementMetric.wasMoved;
|
n@50
|
914 metric.appendChild(flagMoved);
|
n@50
|
915 }
|
n@50
|
916 if (audioEngineContext.metric.enableFlagComments) {
|
n@50
|
917 var flagComments = document.createElement('metricResult');
|
n@50
|
918 flagComments.id = 'elementFlagComments';
|
n@50
|
919 if (response.textContent.length == 0) {flag.textContent = 'false';}
|
n@50
|
920 else {flag.textContet = 'true';}
|
n@50
|
921 metric.appendChild(flagComments);
|
n@50
|
922 }
|
n@50
|
923 audioElement.appendChild(metric);
|
n@45
|
924 xmlDoc.appendChild(audioElement);
|
n@45
|
925 }
|
nicholas@65
|
926 var commentQuestion = document.getElementsByClassName('commentQuestion');
|
nicholas@65
|
927 for (var i=0; i<commentQuestion.length; i++)
|
nicholas@65
|
928 {
|
nicholas@65
|
929 var cqHolder = document.createElement('CommentQuestion');
|
nicholas@65
|
930 var comment = document.createElement('comment');
|
nicholas@65
|
931 var question = document.createElement('question');
|
nicholas@65
|
932 cqHolder.id = commentQuestion[i].id;
|
nicholas@65
|
933 comment.textContent = commentQuestion[i].children[2].value;
|
nicholas@65
|
934 question.textContent = commentQuestion[i].children[0].textContent;
|
nicholas@65
|
935 cqHolder.appendChild(question);
|
nicholas@65
|
936 cqHolder.appendChild(comment);
|
nicholas@65
|
937 xmlDoc.appendChild(cqHolder);
|
nicholas@65
|
938 }
|
n@45
|
939 testResultsHolders[testId] = xmlDoc;
|
n@44
|
940 }
|
n@44
|
941
|
nicholas@7
|
942 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nicholas@7
|
943 function interfaceXMLSave(){
|
nicholas@7
|
944 // Create the XML string to be exported with results
|
nicholas@7
|
945 var xmlDoc = document.createElement("BrowserEvaluationResult");
|
n@45
|
946 for (var i=0; i<testResultsHolders.length; i++)
|
nicholas@7
|
947 {
|
n@45
|
948 xmlDoc.appendChild(testResultsHolders[i]);
|
nicholas@7
|
949 }
|
n@23
|
950 // Append Pre/Post Questions
|
n@23
|
951 xmlDoc.appendChild(preTestQuestions);
|
n@23
|
952 xmlDoc.appendChild(postTestQuestions);
|
n@23
|
953
|
nicholas@7
|
954 return xmlDoc;
|
nicholas@67
|
955 } |