annotate ape.js @ 1734:6b062200a412

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