annotate ape.js @ 2002:5627dbe56043

Fixed Bug 1204: Multiple clicks creates multiple instances.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Fri, 01 May 2015 16:07:15 +0100
parents b78148108626
children 355631b936d3
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@1981 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@2002 404 this.audioObjects[i].outputGain.gain.value = 0.0;
nickjillings@2002 405 this.audioObjects[i].stop();
nickjillings@1667 406 }
nickjillings@2002 407 this.audioObjects[id].outputGain.gain.value = 1.0;
nickjillings@2002 408 this.audioObjects[id].play(audioContext.currentTime+0.01);
nickjillings@1667 409 };
nickjillings@1667 410 }
nickjillings@1667 411
nickjillings@1656 412 currentTestHolder = document.createElement('audioHolder');
nickjillings@1656 413 currentTestHolder.id = textXML.id;
nickjillings@1656 414 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
nickjillings@1656 415 var currentPreTestHolder = document.createElement('preTest');
nickjillings@1656 416 var currentPostTestHolder = document.createElement('postTest');
nickjillings@1656 417 currentTestHolder.appendChild(currentPreTestHolder);
nickjillings@1656 418 currentTestHolder.appendChild(currentPostTestHolder);
nickjillings@1656 419
nickjillings@1655 420 var randomise = textXML.attributes['randomiseOrder'];
nickjillings@1655 421 if (randomise != undefined) {randomise = randomise.value;}
nickjillings@1655 422 else {randomise = false;}
nickjillings@1655 423
nickjillings@1644 424 var audioElements = $(textXML).find('audioElements');
nickjillings@1668 425 currentTrackOrder = [];
nickjillings@1644 426 audioElements.each(function(index,element){
nickjillings@1655 427 // Find any blind-repeats
nickjillings@1655 428 // Not implemented yet, but just incase
nickjillings@1655 429 currentTrackOrder[index] = element;
nickjillings@1655 430 });
nickjillings@1655 431 if (randomise) {
nickjillings@1664 432 currentTrackOrder = randomiseOrder(currentTrackOrder);
nickjillings@1655 433 }
nickjillings@1655 434
nickjillings@1668 435 // Delete any previous audioObjects associated with the audioEngine
nickjillings@1668 436 audioEngineContext.audioObjects = [];
nickjillings@1668 437
nickjillings@1697 438 // Find all the audioElements from the audioHolder
nickjillings@1655 439 $(currentTrackOrder).each(function(index,element){
nickjillings@1688 440 // Find URL of track
nickjillings@1697 441 // In this jQuery loop, variable 'this' holds the current audioElement.
nickjillings@1697 442
nickjillings@1697 443 // Now load each audio sample. First create the new track by passing the full URL
nickjillings@1688 444 var trackURL = hostURL + this.attributes['url'].value;
nickjillings@1688 445 audioEngineContext.newTrack(trackURL);
nickjillings@1675 446
nickjillings@1675 447 if (commentShow) {
nickjillings@1675 448 // Create document objects to hold the comment boxes
nickjillings@1675 449 var trackComment = document.createElement('div');
nickjillings@1675 450 trackComment.className = 'comment-div';
nickjillings@1675 451 // Create a string next to each comment asking for a comment
nickjillings@1675 452 var trackString = document.createElement('span');
nickjillings@1675 453 trackString.innerHTML = 'Comment on track '+index;
nickjillings@1675 454 // Create the HTML5 comment box 'textarea'
nickjillings@1675 455 var trackCommentBox = document.createElement('textarea');
nickjillings@1675 456 trackCommentBox.rows = '4';
nickjillings@1675 457 trackCommentBox.cols = '100';
nickjillings@1675 458 trackCommentBox.name = 'trackComment'+index;
nickjillings@1675 459 trackCommentBox.className = 'trackComment';
nickjillings@1675 460 var br = document.createElement('br');
nickjillings@1675 461 // Add to the holder.
nickjillings@1675 462 trackComment.appendChild(trackString);
nickjillings@1675 463 trackComment.appendChild(br);
nickjillings@1675 464 trackComment.appendChild(trackCommentBox);
nickjillings@1675 465 feedbackHolder.appendChild(trackComment);
nickjillings@1675 466 }
nickjillings@1697 467
nickjillings@1686 468 // Create a slider per track
nickjillings@1686 469
nickjillings@1686 470 var trackSliderObj = document.createElement('div');
nickjillings@1686 471 trackSliderObj.className = 'track-slider';
nickjillings@1686 472 trackSliderObj.id = 'track-slider-'+index;
nickjillings@1686 473 // Distribute it randomnly
nickjillings@1686 474 var w = window.innerWidth - 100;
nickjillings@1686 475 w = Math.random()*w;
nickjillings@1686 476 trackSliderObj.style.left = Math.floor(w)+50+'px';
nickjillings@1686 477 trackSliderObj.innerHTML = '<span>'+index+'</span>';
nickjillings@1686 478 trackSliderObj.draggable = true;
nickjillings@1686 479 trackSliderObj.ondragend = dragEnd;
nickjillings@1659 480 trackSliderObj.ondragstart = function()
nickjillings@1659 481 {
nickjillings@1659 482 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
nickjillings@1659 483 audioEngineContext.metric.sliderMoveStart(id);
nickjillings@1659 484 };
nickjillings@1689 485
nickjillings@1689 486 // Onclick, switch playback to that track
nickjillings@1689 487 trackSliderObj.onclick = function() {
nickjillings@1689 488 // Get the track ID from the object ID
nickjillings@1689 489 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
nickjillings@1659 490 audioEngineContext.metric.sliderPlayed(id);
nickjillings@1689 491 audioEngineContext.selectedTrack(id);
nickjillings@1696 492 };
nickjillings@1689 493
nickjillings@1686 494 canvas.appendChild(trackSliderObj);
nickjillings@1696 495 });
nickjillings@1684 496
nickjillings@1674 497 // Append any commentQuestion boxes
nickjillings@1674 498 var commentQuestions = $(textXML).find('CommentQuestion');
nickjillings@1674 499 $(commentQuestions).each(function(index,element) {
nickjillings@1674 500 // Create document objects to hold the comment boxes
nickjillings@1674 501 var trackComment = document.createElement('div');
nickjillings@1674 502 trackComment.className = 'comment-div commentQuestion';
nickjillings@1674 503 trackComment.id = element.attributes['id'].value;
nickjillings@1674 504 // Create a string next to each comment asking for a comment
nickjillings@1674 505 var trackString = document.createElement('span');
nickjillings@1674 506 trackString.innerHTML = element.textContent;
nickjillings@1674 507 // Create the HTML5 comment box 'textarea'
nickjillings@1674 508 var trackCommentBox = document.createElement('textarea');
nickjillings@1674 509 trackCommentBox.rows = '4';
nickjillings@1674 510 trackCommentBox.cols = '100';
nickjillings@1674 511 trackCommentBox.name = 'commentQuestion'+index;
nickjillings@1674 512 trackCommentBox.className = 'trackComment';
nickjillings@1674 513 var br = document.createElement('br');
nickjillings@1674 514 // Add to the holder.
nickjillings@1674 515 trackComment.appendChild(trackString);
nickjillings@1674 516 trackComment.appendChild(br);
nickjillings@1674 517 trackComment.appendChild(trackCommentBox);
nickjillings@1674 518 feedbackHolder.appendChild(trackComment);
nickjillings@1674 519 });
nickjillings@1683 520
nickjillings@1649 521 // Now process any pre-test commands
nickjillings@1702 522
nickjillings@1654 523 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
nickjillings@1649 524 if (preTest.children.length > 0)
nickjillings@1649 525 {
nickjillings@1649 526 currentState = 'testRunPre-'+id;
nickjillings@1649 527 preTestPopupStart(preTest);
nickjillings@1649 528 showPopup();
nickjillings@1649 529 } else {
nickjillings@1649 530 currentState = 'testRun-'+id;
nickjillings@1649 531 }
nickjillings@1649 532 }
nickjillings@1649 533
nickjillings@1649 534 function preTestPopupStart(preTest)
nickjillings@1649 535 {
nickjillings@1649 536 var popupHolder = document.getElementById('popupHolder');
nickjillings@1649 537 popupHolder.innerHTML = null;
nickjillings@1649 538 // Parse the first box
nickjillings@1649 539 var preTestOption = document.createElement('div');
nickjillings@1649 540 preTestOption.id = 'preTest';
nickjillings@1649 541 preTestOption.style.marginTop = '25px';
nickjillings@1649 542 preTestOption.align = "center";
nickjillings@1649 543 var child = preTest.children[0];
nickjillings@1649 544 if (child.nodeName == 'statement')
nickjillings@1649 545 {
nickjillings@1649 546 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
nickjillings@1649 547 } else if (child.nodeName == 'question')
nickjillings@1649 548 {
nickjillings@1649 549 var questionId = child.attributes['id'].value;
nickjillings@1649 550 var textHold = document.createElement('span');
nickjillings@1649 551 textHold.innerHTML = child.innerHTML;
nickjillings@1649 552 textHold.id = questionId + 'response';
nickjillings@1649 553 var textEnter = document.createElement('textarea');
nickjillings@1649 554 preTestOption.appendChild(textHold);
nickjillings@1649 555 preTestOption.appendChild(textEnter);
nickjillings@1649 556 }
nickjillings@1649 557 var nextButton = document.createElement('button');
nickjillings@1649 558 nextButton.className = 'popupButton';
nickjillings@1649 559 nextButton.value = '0';
nickjillings@1649 560 nextButton.innerHTML = 'Next';
nickjillings@1649 561 nextButton.onclick = popupButtonClick;
nickjillings@1702 562
nickjillings@1649 563 popupHolder.appendChild(preTestOption);
nickjillings@1649 564 popupHolder.appendChild(nextButton);
nickjillings@1644 565 }
nickjillings@1644 566
nickjillings@1648 567 function popupButtonClick()
nickjillings@1648 568 {
nickjillings@1648 569 // Global call from the 'Next' button click
nickjillings@1648 570 if (currentState == 'preTest')
nickjillings@1702 571 {
nickjillings@1648 572 // At the start of the preTest routine!
nickjillings@1649 573 var xmlTree = projectXML.find('setup');
nickjillings@1649 574 var preTest = xmlTree.find('PreTest')[0];
nickjillings@1649 575 this.value = preTestButtonClick(preTest,this.value);
nickjillings@1649 576 } else if (currentState.substr(0,10) == 'testRunPre')
nickjillings@1649 577 {
nickjillings@1649 578 //Specific test pre-test
nickjillings@1649 579 var testId = currentState.substr(11,currentState.length-10);
nickjillings@1654 580 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
nickjillings@1649 581 this.value = preTestButtonClick(preTest,this.value);
nickjillings@1652 582 } else if (currentState.substr(0,11) == 'testRunPost')
nickjillings@1652 583 {
nickjillings@1652 584 // Specific test post-test
nickjillings@1652 585 var testId = currentState.substr(12,currentState.length-11);
nickjillings@1654 586 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
nickjillings@1652 587 this.value = preTestButtonClick(preTest,this.value);
nickjillings@1651 588 } else if (currentState == 'postTest')
nickjillings@1651 589 {
nickjillings@1651 590 // At the end of the test, running global post test
nickjillings@1651 591 var xmlTree = projectXML.find('setup');
nickjillings@1651 592 var PostTest = xmlTree.find('PostTest')[0];
nickjillings@1651 593 this.value = preTestButtonClick(PostTest,this.value);
nickjillings@1702 594 }
nickjillings@1648 595 }
nickjillings@1648 596
nickjillings@1649 597 function preTestButtonClick(preTest,index)
nickjillings@1644 598 {
nickjillings@1644 599 // Called on click of pre-test button
nickjillings@1646 600 // Need to find and parse preTest again!
nickjillings@1646 601 var preTestOption = document.getElementById('preTest');
nickjillings@1646 602 // Check if current state is a question!
nickjillings@1648 603 if (preTest.children[index].nodeName == 'question') {
nickjillings@1648 604 var questionId = preTest.children[index].attributes['id'].value;
nickjillings@1646 605 var questionHold = document.createElement('comment');
nickjillings@1646 606 var questionResponse = document.getElementById(questionId + 'response');
nickjillings@1673 607 var mandatory = preTest.children[index].attributes['mandatory'];
nickjillings@1673 608 if (mandatory != undefined){
nickjillings@1673 609 if (mandatory.value == 'true') {mandatory = true;}
nickjillings@1673 610 else {mandatory = false;}
nickjillings@1673 611 } else {mandatory = false;}
nickjillings@1673 612 if (mandatory == true && questionResponse.value.length == 0) {
nickjillings@1673 613 return index;
nickjillings@1673 614 }
nickjillings@1646 615 questionHold.id = questionId;
nickjillings@1646 616 questionHold.innerHTML = questionResponse.value;
nickjillings@1656 617 postPopupResponse(questionHold);
nickjillings@1646 618 }
nickjillings@1648 619 index++;
nickjillings@1648 620 if (index < preTest.children.length)
nickjillings@1702 621 {
nickjillings@1646 622 // More to process
nickjillings@1648 623 var child = preTest.children[index];
nickjillings@1702 624 if (child.nodeName == 'statement')
nickjillings@1702 625 {
nickjillings@1702 626 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
nickjillings@1702 627 } else if (child.nodeName == 'question')
nickjillings@1702 628 {
nickjillings@1702 629 var textHold = document.createElement('span');
nickjillings@1702 630 textHold.innerHTML = child.innerHTML;
nickjillings@1702 631 var textEnter = document.createElement('textarea');
nickjillings@1646 632 textEnter.id = child.attributes['id'].value + 'response';
nickjillings@1646 633 var br = document.createElement('br');
nickjillings@1646 634 preTestOption.innerHTML = null;
nickjillings@1702 635 preTestOption.appendChild(textHold);
nickjillings@1646 636 preTestOption.appendChild(br);
nickjillings@1702 637 preTestOption.appendChild(textEnter);
nickjillings@1702 638 }
nickjillings@1646 639 } else {
nickjillings@1646 640 // Time to clear
nickjillings@1647 641 preTestOption.innerHTML = null;
nickjillings@1653 642 if (currentState != 'postTest') {
nickjillings@1653 643 hidePopup();
nickjillings@1653 644 // Progress the state!
nickjillings@1653 645 advanceState();
nickjillings@1653 646 } else {
nickjillings@1653 647 a = createProjectSave(projectReturn);
nickjillings@1653 648 preTestOption.appendChild(a);
nickjillings@1653 649 }
nickjillings@1702 650 }
nickjillings@1648 651 return index;
nickjillings@1646 652 }
nickjillings@1702 653
nickjillings@1656 654 function postPopupResponse(response)
nickjillings@1656 655 {
nickjillings@1656 656 if (currentState == 'preTest') {
nickjillings@1656 657 preTestQuestions.appendChild(response);
nickjillings@1656 658 } else if (currentState == 'postTest') {
nickjillings@1656 659 postTestQuestions.appendChild(response);
nickjillings@1656 660 } else {
nickjillings@1656 661 // Inside a specific test
nickjillings@1656 662 if (currentState.substr(0,10) == 'testRunPre') {
nickjillings@1656 663 // Pre Test
nickjillings@1656 664 var store = $(currentTestHolder).find('preTest');
nickjillings@1656 665 } else {
nickjillings@1656 666 // Post Test
nickjillings@1656 667 var store = $(currentTestHolder).find('postTest');
nickjillings@1656 668 }
nickjillings@1656 669 store[0].appendChild(response);
nickjillings@1656 670 }
nickjillings@1656 671 }
nickjillings@1656 672
nickjillings@1646 673 function showPopup()
nickjillings@1646 674 {
nickjillings@1647 675 var popupHolder = document.getElementById('popupHolder');
nickjillings@1648 676 popupHolder.style.zIndex = 3;
nickjillings@1647 677 popupHolder.style.visibility = 'visible';
nickjillings@1647 678 var blank = document.getElementsByClassName('testHalt')[0];
nickjillings@1647 679 blank.style.zIndex = 2;
nickjillings@1647 680 blank.style.visibility = 'visible';
nickjillings@1646 681 }
nickjillings@1646 682
nickjillings@1646 683 function hidePopup()
nickjillings@1646 684 {
nickjillings@1647 685 var popupHolder = document.getElementById('popupHolder');
nickjillings@1647 686 popupHolder.style.zIndex = -1;
nickjillings@1647 687 popupHolder.style.visibility = 'hidden';
nickjillings@1647 688 var blank = document.getElementsByClassName('testHalt')[0];
nickjillings@1647 689 blank.style.zIndex = -2;
nickjillings@1647 690 blank.style.visibility = 'hidden';
nickjillings@1683 691 }
nickjillings@1686 692
nickjillings@1686 693 function dragEnd(ev) {
nickjillings@1686 694 // Function call when a div has been dropped
nickjillings@1643 695 var slider = document.getElementById('slider');
nickjillings@1661 696 var w = slider.style.width;
nickjillings@1661 697 w = Number(w.substr(0,w.length-2));
nickjillings@1661 698 var x = ev.x;
nickjillings@1661 699 if (x >= 42 && x < w+42) {
nickjillings@1661 700 this.style.left = (x)+'px';
nickjillings@1686 701 } else {
nickjillings@1661 702 if (x<42) {
nickjillings@1661 703 this.style.left = '42px';
nickjillings@1686 704 } else {
nickjillings@1661 705 this.style.left = (w+42) + 'px';
nickjillings@1686 706 }
nickjillings@1686 707 }
nickjillings@1659 708 audioEngineContext.metric.sliderMoved();
nickjillings@1642 709 }
nickjillings@1642 710
nickjillings@1649 711 function advanceState()
nickjillings@1649 712 {
nickjillings@1649 713 console.log(currentState);
nickjillings@1649 714 if (currentState == 'preTest')
nickjillings@1649 715 {
nickjillings@1649 716 // End of pre-test, begin the test
nickjillings@1649 717 loadTest(0);
nickjillings@1649 718 } else if (currentState.substr(0,10) == 'testRunPre')
nickjillings@1649 719 {
nickjillings@1649 720 // Start the test
nickjillings@1649 721 var testId = currentState.substr(11,currentState.length-10);
nickjillings@1649 722 currentState = 'testRun-'+testId;
nickjillings@1652 723 } else if (currentState.substr(0,11) == 'testRunPost')
nickjillings@1652 724 {
nickjillings@1654 725 var testId = currentState.substr(12,currentState.length-11);
nickjillings@1652 726 testEnded(testId);
nickjillings@1650 727 } else if (currentState.substr(0,7) == 'testRun')
nickjillings@1650 728 {
nickjillings@1650 729 var testId = currentState.substr(8,currentState.length-7);
nickjillings@1650 730 // Check if we have any post tests to perform
nickjillings@1654 731 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
nickjillings@1678 732 if (postXML == undefined) {
nickjillings@1678 733 testEnded(testId);
nickjillings@1678 734 }
nickjillings@1678 735 else if (postXML.children.length > 0)
nickjillings@1650 736 {
nickjillings@1652 737 currentState = 'testRunPost-'+testId;
nickjillings@1652 738 showPopup();
nickjillings@1652 739 preTestPopupStart(postXML);
nickjillings@1650 740 }
nickjillings@1652 741 else {
nickjillings@1650 742
nickjillings@1650 743
nickjillings@1652 744 // No post tests, check if we have another test to perform instead
nickjillings@1678 745
nickjillings@1650 746 }
nickjillings@1649 747 }
nickjillings@1649 748 console.log(currentState);
nickjillings@1649 749 }
nickjillings@1649 750
nickjillings@1652 751 function testEnded(testId)
nickjillings@1652 752 {
nickjillings@1655 753 pageXMLSave(testId);
nickjillings@1652 754 if (testXMLSetups.length-1 > testId)
nickjillings@1652 755 {
nickjillings@1652 756 // Yes we have another test to perform
nickjillings@1654 757 testId = (Number(testId)+1);
nickjillings@1654 758 currentState = 'testRun-'+testId;
nickjillings@1654 759 loadTest(testId);
nickjillings@1652 760 } else {
nickjillings@1652 761 console.log('Testing Completed!');
nickjillings@1652 762 currentState = 'postTest';
nickjillings@1652 763 // Check for any post tests
nickjillings@1652 764 var xmlSetup = projectXML.find('setup');
nickjillings@1652 765 var postTest = xmlSetup.find('PostTest')[0];
nickjillings@1652 766 showPopup();
nickjillings@1652 767 preTestPopupStart(postTest);
nickjillings@1652 768 }
nickjillings@1652 769 }
nickjillings@1652 770
nickjillings@1650 771 function buttonSubmitClick()
nickjillings@1650 772 {
nickjillings@1659 773 if (audioEngineContext.status == 1) {
nickjillings@1659 774 var playback = document.getElementById('playback-button');
nickjillings@1659 775 playback.click();
nickjillings@1650 776 // 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 777 } else
nickjillings@1665 778 {
nickjillings@1665 779 if (audioEngineContext.timer.testStarted == false)
nickjillings@1665 780 {
nickjillings@1665 781 alert('You have not started the test! Please press start to begin the test!');
nickjillings@1665 782 return;
nickjillings@1665 783 }
nickjillings@1659 784 }
nickjillings@1650 785 if (currentState.substr(0,7) == 'testRun')
nickjillings@1650 786 {
nickjillings@1659 787 audioEngineContext.timer.stopTest();
nickjillings@1650 788 advanceState();
nickjillings@1650 789 }
nickjillings@1650 790 }
nickjillings@1650 791
nickjillings@1661 792 function convSliderPosToRate(id)
nickjillings@1661 793 {
nickjillings@1661 794 var w = document.getElementById('slider').style.width;
nickjillings@1661 795 var maxPix = w.substr(0,w.length-2);
nickjillings@1661 796 var slider = document.getElementsByClassName('track-slider')[id];
nickjillings@1661 797 var pix = slider.style.left;
nickjillings@1661 798 pix = pix.substr(0,pix.length-2);
nickjillings@1661 799 var rate = (pix-42)/maxPix;
nickjillings@1661 800 return rate;
nickjillings@1661 801 }
nickjillings@1661 802
nickjillings@1654 803 function pageXMLSave(testId)
nickjillings@1654 804 {
nickjillings@1654 805 // Saves a specific test page
nickjillings@1656 806 var xmlDoc = currentTestHolder;
nickjillings@1660 807 // Check if any session wide metrics are enabled
nickjillings@1676 808
nickjillings@1676 809 var commentShow = testXMLSetups[testId].attributes['elementComments'];
nickjillings@1676 810 if (commentShow != undefined) {
nickjillings@1676 811 if (commentShow.value == 'false') {commentShow = false;}
nickjillings@1676 812 else {commentShow = true;}
nickjillings@1676 813 } else {commentShow = true;}
nickjillings@1676 814
nickjillings@1660 815 var metric = document.createElement('metric');
nickjillings@1660 816 if (audioEngineContext.metric.enableTestTimer)
nickjillings@1660 817 {
nickjillings@1660 818 var testTime = document.createElement('metricResult');
nickjillings@1660 819 testTime.id = 'testTime';
nickjillings@1660 820 testTime.textContent = audioEngineContext.timer.testDuration;
nickjillings@1660 821 metric.appendChild(testTime);
nickjillings@1660 822 }
nickjillings@1660 823 xmlDoc.appendChild(metric);
nickjillings@1655 824 var trackSliderObjects = document.getElementsByClassName('track-slider');
nickjillings@1655 825 var commentObjects = document.getElementsByClassName('comment-div');
nickjillings@1655 826 for (var i=0; i<trackSliderObjects.length; i++)
nickjillings@1655 827 {
nickjillings@1655 828 var audioElement = document.createElement('audioElement');
nickjillings@1655 829 audioElement.id = currentTrackOrder[i].attributes['id'].value;
nickjillings@1655 830 audioElement.url = currentTrackOrder[i].attributes['url'].value;
nickjillings@1661 831 var value = document.createElement('value');
nickjillings@1661 832 value.innerHTML = convSliderPosToRate(i);
nickjillings@1676 833 if (commentShow) {
nickjillings@1676 834 var comment = document.createElement("comment");
nickjillings@1676 835 var question = document.createElement("question");
nickjillings@1676 836 var response = document.createElement("response");
nickjillings@1676 837 question.textContent = commentObjects[i].children[0].textContent;
nickjillings@1676 838 response.textContent = commentObjects[i].children[2].value;
nickjillings@1676 839 comment.appendChild(question);
nickjillings@1676 840 comment.appendChild(response);
nickjillings@1676 841 audioElement.appendChild(comment);
nickjillings@1676 842 }
nickjillings@1655 843 audioElement.appendChild(value);
nickjillings@1660 844 // Check for any per element metrics
nickjillings@1660 845 var metric = document.createElement('metric');
nickjillings@1660 846 var elementMetric = audioEngineContext.audioObjects[i].metric;
nickjillings@1660 847 if (audioEngineContext.metric.enableElementTimer) {
nickjillings@1660 848 var elementTimer = document.createElement('metricResult');
nickjillings@1660 849 elementTimer.id = 'elementTimer';
nickjillings@1660 850 elementTimer.textContent = elementMetric.listenedTimer;
nickjillings@1660 851 metric.appendChild(elementTimer);
nickjillings@1660 852 }
nickjillings@1660 853 if (audioEngineContext.metric.enableElementTracker) {
nickjillings@1660 854 var elementTrackerFull = document.createElement('metricResult');
nickjillings@1660 855 elementTrackerFull.id = 'elementTrackerFull';
nickjillings@1660 856 var data = elementMetric.movementTracker;
nickjillings@1660 857 for (var k=0; k<data.length; k++)
nickjillings@1660 858 {
nickjillings@1660 859 var timePos = document.createElement('timePos');
nickjillings@1660 860 timePos.id = k;
nickjillings@1660 861 var time = document.createElement('time');
nickjillings@1660 862 time.textContent = data[k][0];
nickjillings@1660 863 var position = document.createElement('position');
nickjillings@1660 864 position.textContent = data[k][1];
nickjillings@1660 865 timePos.appendChild(time);
nickjillings@1660 866 timePos.appendChild(position);
nickjillings@1660 867 elementTrackerFull.appendChild(timePos);
nickjillings@1660 868 }
nickjillings@1660 869 metric.appendChild(elementTrackerFull);
nickjillings@1660 870 }
nickjillings@1660 871 if (audioEngineContext.metric.enableElementInitialPosition) {
nickjillings@1660 872 var elementInitial = document.createElement('metricResult');
nickjillings@1660 873 elementInitial.id = 'elementInitialPosition';
nickjillings@1660 874 elementInitial.textContent = elementMetric.initialPosition;
nickjillings@1660 875 metric.appendChild(elementInitial);
nickjillings@1660 876 }
nickjillings@1660 877 if (audioEngineContext.metric.enableFlagListenedTo) {
nickjillings@1660 878 var flagListenedTo = document.createElement('metricResult');
nickjillings@1660 879 flagListenedTo.id = 'elementFlagListenedTo';
nickjillings@1660 880 flagListenedTo.textContent = elementMetric.wasListenedTo;
nickjillings@1660 881 metric.appendChild(flagListenedTo);
nickjillings@1660 882 }
nickjillings@1660 883 if (audioEngineContext.metric.enableFlagMoved) {
nickjillings@1660 884 var flagMoved = document.createElement('metricResult');
nickjillings@1660 885 flagMoved.id = 'elementFlagMoved';
nickjillings@1660 886 flagMoved.textContent = elementMetric.wasMoved;
nickjillings@1660 887 metric.appendChild(flagMoved);
nickjillings@1660 888 }
nickjillings@1660 889 if (audioEngineContext.metric.enableFlagComments) {
nickjillings@1660 890 var flagComments = document.createElement('metricResult');
nickjillings@1660 891 flagComments.id = 'elementFlagComments';
nickjillings@1660 892 if (response.textContent.length == 0) {flag.textContent = 'false';}
nickjillings@1660 893 else {flag.textContet = 'true';}
nickjillings@1660 894 metric.appendChild(flagComments);
nickjillings@1660 895 }
nickjillings@1660 896 audioElement.appendChild(metric);
nickjillings@1655 897 xmlDoc.appendChild(audioElement);
nickjillings@1655 898 }
nickjillings@1674 899 var commentQuestion = document.getElementsByClassName('commentQuestion');
nickjillings@1674 900 for (var i=0; i<commentQuestion.length; i++)
nickjillings@1674 901 {
nickjillings@1674 902 var cqHolder = document.createElement('CommentQuestion');
nickjillings@1674 903 var comment = document.createElement('comment');
nickjillings@1674 904 var question = document.createElement('question');
nickjillings@1674 905 cqHolder.id = commentQuestion[i].id;
nickjillings@1674 906 comment.textContent = commentQuestion[i].children[2].value;
nickjillings@1674 907 question.textContent = commentQuestion[i].children[0].textContent;
nickjillings@1674 908 cqHolder.appendChild(question);
nickjillings@1674 909 cqHolder.appendChild(comment);
nickjillings@1674 910 xmlDoc.appendChild(cqHolder);
nickjillings@1674 911 }
nickjillings@1655 912 testResultsHolders[testId] = xmlDoc;
nickjillings@1686 913 }
nickjillings@1688 914
nickjillings@1688 915 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
nickjillings@1688 916 function interfaceXMLSave(){
nickjillings@1688 917 // Create the XML string to be exported with results
nickjillings@1688 918 var xmlDoc = document.createElement("BrowserEvaluationResult");
nickjillings@1655 919 for (var i=0; i<testResultsHolders.length; i++)
nickjillings@1688 920 {
nickjillings@1655 921 xmlDoc.appendChild(testResultsHolders[i]);
nickjillings@1688 922 }
nickjillings@1703 923 // Append Pre/Post Questions
nickjillings@1703 924 xmlDoc.appendChild(preTestQuestions);
nickjillings@1703 925 xmlDoc.appendChild(postTestQuestions);
nickjillings@1703 926
nickjillings@1688 927 return xmlDoc;
nickjillings@1676 928 }