annotate ape.js @ 671:9ea50bbcaf9a

Added customised scale - NEED TO ENTER INTO DOCUMENTATION!
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 10 Apr 2015 19:09:21 +0100
parents 77c974fd7e60
children d4e55184f776
rev   line source
n@656 1 /**
n@656 2 * ape.js
n@656 3 * Create the APE interface
n@656 4 */
n@656 5
n@656 6 /*
n@656 7 *
n@656 8 * WARNING!!!
n@656 9 *
n@656 10 * YOU ARE VIEWING THE DEV VERSION. THERE IS NO GUARANTEE THIS WILL BE FULLY FUNCTIONAL
n@656 11 *
n@656 12 * WARNING!!!
n@656 13 *
n@656 14 */
n@656 15
n@662 16 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
n@662 17 // preTest - In preTest state
n@662 18 // testRun-ID - In test running, test Id number at the end 'testRun-2'
n@662 19 // testRunPost-ID - Post test of test ID
n@662 20 // testRunPre-ID - Pre-test of test ID
n@662 21 // postTest - End of test, final submission!
n@662 22
n@656 23
n@656 24 // Once this is loaded and parsed, begin execution
n@656 25 loadInterface(projectXML);
n@656 26
n@656 27 function loadInterface(xmlDoc) {
n@656 28
n@656 29 // Get the dimensions of the screen available to the page
n@656 30 var width = window.innerWidth;
n@656 31 var height = window.innerHeight;
n@656 32
n@656 33 // The injection point into the HTML page
n@656 34 var insertPoint = document.getElementById("topLevelBody");
n@656 35 var testContent = document.createElement('div');
n@656 36 testContent.id = 'testContent';
n@656 37
n@656 38
n@656 39 // Decode parts of the xmlDoc that are needed
n@656 40 // xmlDoc MUST already be parsed by jQuery!
n@656 41 var xmlSetup = xmlDoc.find('setup');
n@656 42 // Should put in an error function here incase of malprocessed or malformed XML
n@656 43
n@658 44 // Extract the different test XML DOM trees
n@668 45 var audioHolders = xmlDoc.find('audioHolder');
n@668 46 audioHolders.each(function(index,element) {
n@668 47 var repeatN = element.attributes['repeatCount'].value;
n@668 48 for (var r=0; r<=repeatN; r++) {
n@668 49 testXMLSetups[testXMLSetups.length] = element;
n@668 50 }
n@668 51 });
n@668 52
n@668 53 // New check if we need to randomise the test order
n@669 54 var randomise = xmlSetup[0].attributes['randomiseOrder'];
n@669 55 if (randomise != undefined) {
n@668 56 randomise = Boolean(randomise.value);
n@668 57 } else {
n@668 58 randomise = false;
n@668 59 }
n@668 60 if (randomise)
n@668 61 {
n@668 62 // TODO: Implement Randomisation!!
n@668 63 }
n@668 64
n@658 65
n@656 66 // Create the top div for the Title element
n@656 67 var titleAttr = xmlSetup[0].attributes['title'];
n@656 68 var title = document.createElement('div');
n@656 69 title.className = "title";
n@656 70 title.align = "center";
n@656 71 var titleSpan = document.createElement('span');
n@656 72
n@656 73 // Set title to that defined in XML, else set to default
n@656 74 if (titleAttr != undefined) {
n@656 75 titleSpan.innerHTML = titleAttr.value;
n@656 76 } else {
n@656 77 titleSpan.innerHTML = 'APE Tool';
n@656 78 }
n@656 79 // Insert the titleSpan element into the title div element.
n@656 80 title.appendChild(titleSpan);
n@656 81
n@671 82 var pagetitle = document.createElement('div');
n@671 83 pagetitle.className = "pageTitle";
n@671 84 pagetitle.align = "center";
n@671 85 var titleSpan = document.createElement('span');
n@671 86 titleSpan.id = "pageTitle";
n@671 87 pagetitle.appendChild(titleSpan);
n@671 88
n@656 89 // Store the return URL path in global projectReturn
n@656 90 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
n@656 91
n@656 92 // Create Interface buttons!
n@656 93 var interfaceButtons = document.createElement('div');
n@656 94 interfaceButtons.id = 'interface-buttons';
n@656 95
n@656 96 // MANUAL DOWNLOAD POINT
n@656 97 // If project return is null, this MUST be specified as the location to create the download link
n@656 98 var downloadPoint = document.createElement('div');
n@656 99 downloadPoint.id = 'download-point';
n@656 100
n@656 101 // Create playback start/stop points
n@656 102 var playback = document.createElement("button");
n@656 103 playback.innerHTML = 'Start';
n@656 104 // onclick function. Check if it is playing or not, call the correct function in the
n@656 105 // audioEngine, change the button text to reflect the next state.
n@656 106 playback.onclick = function() {
n@656 107 if (audioEngineContext.status == 0) {
n@656 108 audioEngineContext.play();
n@656 109 this.innerHTML = 'Stop';
n@656 110 } else {
n@656 111 audioEngineContext.stop();
n@656 112 this.innerHTML = 'Start';
n@656 113 }
n@656 114 };
n@656 115 // Create Submit (save) button
n@656 116 var submit = document.createElement("button");
n@656 117 submit.innerHTML = 'Submit';
n@667 118 submit.onclick = buttonSubmitClick;
n@656 119 // Append the interface buttons into the interfaceButtons object.
n@656 120 interfaceButtons.appendChild(playback);
n@656 121 interfaceButtons.appendChild(submit);
n@656 122 interfaceButtons.appendChild(downloadPoint);
n@656 123
n@656 124 // Now create the slider and HTML5 canvas boxes
n@656 125
n@656 126 // Create the div box to center align
n@656 127 var sliderBox = document.createElement('div');
n@656 128 sliderBox.className = 'sliderCanvasDiv';
n@656 129 sliderBox.id = 'sliderCanvasHolder';
n@656 130 sliderBox.align = 'center';
n@656 131
n@656 132 // Create the slider box to hold the slider elements
n@656 133 var canvas = document.createElement('div');
n@656 134 canvas.id = 'slider';
n@656 135 // Must have a known EXACT width, as this is used later to determine the ratings
n@656 136 canvas.style.width = width - 100 +"px";
n@656 137 canvas.align = "left";
n@656 138 sliderBox.appendChild(canvas);
n@656 139
n@671 140 // Create the div to hold any scale objects
n@671 141 var scale = document.createElement('div');
n@671 142 scale.className = 'sliderScale';
n@671 143 scale.id = 'sliderScaleHolder';
n@671 144 scale.align = 'left';
n@671 145 sliderBox.appendChild(scale);
n@671 146
n@656 147 // Global parent for the comment boxes on the page
n@656 148 var feedbackHolder = document.createElement('div');
n@658 149 feedbackHolder.id = 'feedbackHolder';
n@656 150
n@662 151 testContent.style.zIndex = 1;
n@662 152 insertPoint.innerHTML = null; // Clear the current schema
n@662 153
n@656 154 // Create pre and post test questions
n@662 155 var blank = document.createElement('div');
n@662 156 blank.className = 'testHalt';
n@656 157
n@662 158 var popupHolder = document.createElement('div');
n@662 159 popupHolder.id = 'popupHolder';
n@662 160 popupHolder.className = 'popupHolder';
n@662 161 popupHolder.style.position = 'absolute';
n@662 162 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
n@662 163 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
n@662 164 insertPoint.appendChild(popupHolder);
n@662 165 insertPoint.appendChild(blank);
n@662 166 hidePopup();
n@656 167
n@660 168 var preTest = xmlSetup.find('PreTest');
n@660 169 var postTest = xmlSetup.find('PostTest');
n@656 170 preTest = preTest[0];
n@656 171 postTest = postTest[0];
n@662 172
n@662 173 currentState = 'preTest';
n@656 174
n@656 175 // Create Pre-Test Box
n@656 176 if (preTest != undefined && preTest.children.length >= 1)
n@656 177 {
n@662 178 showPopup();
n@663 179 preTestPopupStart(preTest);
n@656 180 }
n@662 181
n@662 182 // Inject into HTML
n@662 183 testContent.appendChild(title); // Insert the title
n@671 184 testContent.appendChild(pagetitle);
n@662 185 testContent.appendChild(interfaceButtons);
n@662 186 testContent.appendChild(sliderBox);
n@662 187 testContent.appendChild(feedbackHolder);
n@662 188 insertPoint.appendChild(testContent);
n@656 189
n@660 190 // Load the full interface
n@663 191
n@656 192 }
n@656 193
n@663 194 function loadTest(id)
n@658 195 {
n@658 196 // Used to load a specific test page
n@663 197 var textXML = testXMLSetups[id];
n@658 198
n@658 199 var feedbackHolder = document.getElementById('feedbackHolder');
n@658 200 var canvas = document.getElementById('slider');
n@658 201 feedbackHolder.innerHTML = null;
n@658 202 canvas.innerHTML = null;
n@671 203
n@671 204 // Setup question title
n@671 205 var interfaceObj = $(textXML).find('interface');
n@671 206 var titleNode = interfaceObj.find('title');
n@671 207 if (titleNode[0] != undefined)
n@671 208 {
n@671 209 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
n@671 210 }
n@671 211 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@671 212 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
n@671 213 // TODO: AUTOMATE ABOVE!!
n@671 214 var scale = document.getElementById('sliderScaleHolder');
n@671 215 scale.innerHTML = null;
n@671 216 interfaceObj.find('scale').each(function(index,scaleObj){
n@671 217 var position = Number(scaleObj.attributes['position'].value)*0.01;
n@671 218 var pixelPosition = (position*positionScale)+offset;
n@671 219 var scaleDOM = document.createElement('span');
n@671 220 scaleDOM.textContent = scaleObj.textContent;
n@671 221 scale.appendChild(scaleDOM);
n@671 222 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@671 223 });
n@658 224
n@658 225 // Extract the hostURL attribute. If not set, create an empty string.
n@658 226 var hostURL = textXML.attributes['hostURL'];
n@658 227 if (hostURL == undefined) {
n@658 228 hostURL = "";
n@658 229 } else {
n@658 230 hostURL = hostURL.value;
n@658 231 }
n@658 232 // Extract the sampleRate. If set, convert the string to a Number.
n@658 233 var hostFs = textXML.attributes['sampleRate'];
n@658 234 if (hostFs != undefined) {
n@658 235 hostFs = Number(hostFs.value);
n@658 236 }
n@658 237
n@658 238 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@658 239 if (hostFs != undefined) {
n@658 240 if (Number(hostFs) != audioContext.sampleRate) {
n@658 241 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
n@658 242 alert(errStr);
n@658 243 return;
n@658 244 }
n@658 245 }
n@669 246
n@670 247 currentTestHolder = document.createElement('audioHolder');
n@670 248 currentTestHolder.id = textXML.id;
n@670 249 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
n@670 250 var currentPreTestHolder = document.createElement('preTest');
n@670 251 var currentPostTestHolder = document.createElement('postTest');
n@670 252 currentTestHolder.appendChild(currentPreTestHolder);
n@670 253 currentTestHolder.appendChild(currentPostTestHolder);
n@670 254
n@669 255 var randomise = textXML.attributes['randomiseOrder'];
n@669 256 if (randomise != undefined) {randomise = randomise.value;}
n@669 257 else {randomise = false;}
n@669 258
n@658 259 var audioElements = $(textXML).find('audioElements');
n@658 260 audioElements.each(function(index,element){
n@669 261 // Find any blind-repeats
n@669 262 // Not implemented yet, but just incase
n@669 263 currentTrackOrder[index] = element;
n@669 264 });
n@669 265 if (randomise) {
n@669 266 // TODO: Randomise order
n@669 267 }
n@669 268
n@669 269 // Find all the audioElements from the audioHolder
n@669 270 $(currentTrackOrder).each(function(index,element){
n@658 271 // Find URL of track
n@658 272 // In this jQuery loop, variable 'this' holds the current audioElement.
n@658 273
n@658 274 // Now load each audio sample. First create the new track by passing the full URL
n@658 275 var trackURL = hostURL + this.attributes['url'].value;
n@658 276 audioEngineContext.newTrack(trackURL);
n@658 277 // Create document objects to hold the comment boxes
n@658 278 var trackComment = document.createElement('div');
n@661 279 trackComment.className = 'comment-div';
n@658 280 // Create a string next to each comment asking for a comment
n@658 281 var trackString = document.createElement('span');
n@658 282 trackString.innerHTML = 'Comment on track '+index;
n@658 283 // Create the HTML5 comment box 'textarea'
n@658 284 var trackCommentBox = document.createElement('textarea');
n@658 285 trackCommentBox.rows = '4';
n@658 286 trackCommentBox.cols = '100';
n@658 287 trackCommentBox.name = 'trackComment'+index;
n@658 288 trackCommentBox.className = 'trackComment';
n@658 289 var br = document.createElement('br');
n@658 290 // Add to the holder.
n@658 291 trackComment.appendChild(trackString);
n@658 292 trackComment.appendChild(br);
n@658 293 trackComment.appendChild(trackCommentBox);
n@658 294 feedbackHolder.appendChild(trackComment);
n@658 295
n@658 296 // Create a slider per track
n@658 297
n@658 298 var trackSliderObj = document.createElement('div');
n@658 299 trackSliderObj.className = 'track-slider';
n@658 300 trackSliderObj.id = 'track-slider-'+index;
n@658 301 // Distribute it randomnly
n@658 302 var w = window.innerWidth - 100;
n@658 303 w = Math.random()*w;
n@658 304 trackSliderObj.style.left = Math.floor(w)+50+'px';
n@658 305 trackSliderObj.innerHTML = '<span>'+index+'</span>';
n@658 306 trackSliderObj.draggable = true;
n@658 307 trackSliderObj.ondragend = dragEnd;
n@658 308
n@658 309 // Onclick, switch playback to that track
n@658 310 trackSliderObj.onclick = function() {
n@658 311 // Get the track ID from the object ID
n@658 312 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
n@658 313 audioEngineContext.selectedTrack(id);
n@658 314 };
n@658 315
n@658 316 canvas.appendChild(trackSliderObj);
n@658 317 });
n@663 318
n@663 319 // Now process any pre-test commands
n@663 320
n@668 321 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
n@663 322 if (preTest.children.length > 0)
n@663 323 {
n@663 324 currentState = 'testRunPre-'+id;
n@663 325 preTestPopupStart(preTest);
n@663 326 showPopup();
n@663 327 } else {
n@663 328 currentState = 'testRun-'+id;
n@663 329 }
n@663 330 }
n@663 331
n@663 332 function preTestPopupStart(preTest)
n@663 333 {
n@663 334 var popupHolder = document.getElementById('popupHolder');
n@663 335 popupHolder.innerHTML = null;
n@663 336 // Parse the first box
n@663 337 var preTestOption = document.createElement('div');
n@663 338 preTestOption.id = 'preTest';
n@663 339 preTestOption.style.marginTop = '25px';
n@663 340 preTestOption.align = "center";
n@663 341 var child = preTest.children[0];
n@663 342 if (child.nodeName == 'statement')
n@663 343 {
n@663 344 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@663 345 } else if (child.nodeName == 'question')
n@663 346 {
n@663 347 var questionId = child.attributes['id'].value;
n@663 348 var textHold = document.createElement('span');
n@663 349 textHold.innerHTML = child.innerHTML;
n@663 350 textHold.id = questionId + 'response';
n@663 351 var textEnter = document.createElement('textarea');
n@663 352 preTestOption.appendChild(textHold);
n@663 353 preTestOption.appendChild(textEnter);
n@663 354 }
n@663 355 var nextButton = document.createElement('button');
n@663 356 nextButton.className = 'popupButton';
n@663 357 nextButton.value = '0';
n@663 358 nextButton.innerHTML = 'Next';
n@663 359 nextButton.onclick = popupButtonClick;
n@663 360
n@663 361 popupHolder.appendChild(preTestOption);
n@663 362 popupHolder.appendChild(nextButton);
n@658 363 }
n@658 364
n@662 365 function popupButtonClick()
n@662 366 {
n@662 367 // Global call from the 'Next' button click
n@662 368 if (currentState == 'preTest')
n@662 369 {
n@662 370 // At the start of the preTest routine!
n@663 371 var xmlTree = projectXML.find('setup');
n@663 372 var preTest = xmlTree.find('PreTest')[0];
n@663 373 this.value = preTestButtonClick(preTest,this.value);
n@663 374 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 375 {
n@663 376 //Specific test pre-test
n@663 377 var testId = currentState.substr(11,currentState.length-10);
n@668 378 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
n@663 379 this.value = preTestButtonClick(preTest,this.value);
n@666 380 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 381 {
n@666 382 // Specific test post-test
n@666 383 var testId = currentState.substr(12,currentState.length-11);
n@668 384 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
n@666 385 this.value = preTestButtonClick(preTest,this.value);
n@665 386 } else if (currentState == 'postTest')
n@665 387 {
n@665 388 // At the end of the test, running global post test
n@665 389 var xmlTree = projectXML.find('setup');
n@665 390 var PostTest = xmlTree.find('PostTest')[0];
n@665 391 this.value = preTestButtonClick(PostTest,this.value);
n@662 392 }
n@662 393 }
n@662 394
n@663 395 function preTestButtonClick(preTest,index)
n@658 396 {
n@658 397 // Called on click of pre-test button
n@660 398 // Need to find and parse preTest again!
n@660 399 var preTestOption = document.getElementById('preTest');
n@660 400 // Check if current state is a question!
n@662 401 if (preTest.children[index].nodeName == 'question') {
n@662 402 var questionId = preTest.children[index].attributes['id'].value;
n@660 403 var questionHold = document.createElement('comment');
n@660 404 var questionResponse = document.getElementById(questionId + 'response');
n@660 405 questionHold.id = questionId;
n@660 406 questionHold.innerHTML = questionResponse.value;
n@670 407 postPopupResponse(questionHold);
n@660 408 }
n@662 409 index++;
n@662 410 if (index < preTest.children.length)
n@660 411 {
n@660 412 // More to process
n@662 413 var child = preTest.children[index];
n@660 414 if (child.nodeName == 'statement')
n@660 415 {
n@660 416 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
n@660 417 } else if (child.nodeName == 'question')
n@660 418 {
n@660 419 var textHold = document.createElement('span');
n@660 420 textHold.innerHTML = child.innerHTML;
n@660 421 var textEnter = document.createElement('textarea');
n@660 422 textEnter.id = child.attributes['id'].value + 'response';
n@660 423 var br = document.createElement('br');
n@660 424 preTestOption.innerHTML = null;
n@660 425 preTestOption.appendChild(textHold);
n@660 426 preTestOption.appendChild(br);
n@660 427 preTestOption.appendChild(textEnter);
n@660 428 }
n@660 429 } else {
n@660 430 // Time to clear
n@661 431 preTestOption.innerHTML = null;
n@667 432 if (currentState != 'postTest') {
n@667 433 hidePopup();
n@667 434 // Progress the state!
n@667 435 advanceState();
n@667 436 } else {
n@667 437 a = createProjectSave(projectReturn);
n@667 438 preTestOption.appendChild(a);
n@667 439 }
n@660 440 }
n@662 441 return index;
n@660 442 }
n@660 443
n@670 444 function postPopupResponse(response)
n@670 445 {
n@670 446 if (currentState == 'preTest') {
n@670 447 preTestQuestions.appendChild(response);
n@670 448 } else if (currentState == 'postTest') {
n@670 449 postTestQuestions.appendChild(response);
n@670 450 } else {
n@670 451 // Inside a specific test
n@670 452 if (currentState.substr(0,10) == 'testRunPre') {
n@670 453 // Pre Test
n@670 454 var store = $(currentTestHolder).find('preTest');
n@670 455 } else {
n@670 456 // Post Test
n@670 457 var store = $(currentTestHolder).find('postTest');
n@670 458 }
n@670 459 store[0].appendChild(response);
n@670 460 }
n@670 461 }
n@670 462
n@660 463 function showPopup()
n@660 464 {
n@661 465 var popupHolder = document.getElementById('popupHolder');
n@662 466 popupHolder.style.zIndex = 3;
n@661 467 popupHolder.style.visibility = 'visible';
n@661 468 var blank = document.getElementsByClassName('testHalt')[0];
n@661 469 blank.style.zIndex = 2;
n@661 470 blank.style.visibility = 'visible';
n@660 471 }
n@660 472
n@660 473 function hidePopup()
n@660 474 {
n@661 475 var popupHolder = document.getElementById('popupHolder');
n@661 476 popupHolder.style.zIndex = -1;
n@661 477 popupHolder.style.visibility = 'hidden';
n@661 478 var blank = document.getElementsByClassName('testHalt')[0];
n@661 479 blank.style.zIndex = -2;
n@661 480 blank.style.visibility = 'hidden';
n@658 481 }
n@658 482
n@656 483 function dragEnd(ev) {
n@656 484 // Function call when a div has been dropped
n@657 485 var slider = document.getElementById('slider');
n@656 486 if (ev.x >= 50 && ev.x < window.innerWidth-50) {
n@656 487 this.style.left = (ev.x)+'px';
n@656 488 } else {
n@656 489 if (ev.x<50) {
n@656 490 this.style.left = '50px';
n@656 491 } else {
n@656 492 this.style.left = window.innerWidth-50 + 'px';
n@656 493 }
n@656 494 }
n@656 495 }
n@656 496
n@663 497 function advanceState()
n@663 498 {
n@663 499 console.log(currentState);
n@663 500 if (currentState == 'preTest')
n@663 501 {
n@663 502 // End of pre-test, begin the test
n@663 503 loadTest(0);
n@663 504 } else if (currentState.substr(0,10) == 'testRunPre')
n@663 505 {
n@663 506 // Start the test
n@663 507 var testId = currentState.substr(11,currentState.length-10);
n@663 508 currentState = 'testRun-'+testId;
n@666 509 } else if (currentState.substr(0,11) == 'testRunPost')
n@666 510 {
n@668 511 var testId = currentState.substr(12,currentState.length-11);
n@666 512 testEnded(testId);
n@664 513 } else if (currentState.substr(0,7) == 'testRun')
n@664 514 {
n@664 515 var testId = currentState.substr(8,currentState.length-7);
n@664 516 // Check if we have any post tests to perform
n@668 517 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
n@664 518 if (postXML.children.length > 0)
n@664 519 {
n@666 520 currentState = 'testRunPost-'+testId;
n@666 521 showPopup();
n@666 522 preTestPopupStart(postXML);
n@664 523 }
n@666 524 else {
n@664 525
n@664 526
n@666 527 // No post tests, check if we have another test to perform instead
n@666 528 testEnded(testId);
n@664 529 }
n@663 530 }
n@663 531 console.log(currentState);
n@663 532 }
n@663 533
n@666 534 function testEnded(testId)
n@666 535 {
n@669 536 pageXMLSave(testId);
n@666 537 if (testXMLSetups.length-1 > testId)
n@666 538 {
n@666 539 // Yes we have another test to perform
n@668 540 testId = (Number(testId)+1);
n@668 541 currentState = 'testRun-'+testId;
n@668 542 loadTest(testId);
n@666 543 } else {
n@666 544 console.log('Testing Completed!');
n@666 545 currentState = 'postTest';
n@666 546 // Check for any post tests
n@666 547 var xmlSetup = projectXML.find('setup');
n@666 548 var postTest = xmlSetup.find('PostTest')[0];
n@666 549 showPopup();
n@666 550 preTestPopupStart(postTest);
n@666 551 }
n@666 552 }
n@666 553
n@664 554 function buttonSubmitClick()
n@664 555 {
n@664 556 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
n@664 557 if (currentState.substr(0,7) == 'testRun')
n@664 558 {
n@664 559 advanceState();
n@664 560 }
n@664 561 }
n@664 562
n@668 563 function pageXMLSave(testId)
n@668 564 {
n@668 565 // Saves a specific test page
n@670 566 var xmlDoc = currentTestHolder;
n@669 567 var trackSliderObjects = document.getElementsByClassName('track-slider');
n@669 568 var commentObjects = document.getElementsByClassName('comment-div');
n@669 569 var rateMin = 50;
n@669 570 var rateMax = window.innerWidth-50;
n@669 571 for (var i=0; i<trackSliderObjects.length; i++)
n@669 572 {
n@669 573 var audioElement = document.createElement('audioElement');
n@669 574 audioElement.id = currentTrackOrder[i].attributes['id'].value;
n@669 575 audioElement.url = currentTrackOrder[i].attributes['url'].value;
n@669 576 var value = document.createElement("value");
n@669 577 var rate = Number(trackSliderObjects[i].style.left.substr(0,trackSliderObjects[i].style.left.length-2));
n@669 578 rate = (rate-rateMin)/rateMax;
n@669 579 value.innerHTML = Math.floor(rate*100);
n@669 580 var comment = document.createElement("comment");
n@669 581 var question = document.createElement("question");
n@669 582 var response = document.createElement("response");
n@669 583 question.textContent = commentObjects[i].children[0].textContent;
n@669 584 response.textContent = commentObjects[i].children[2].value;
n@669 585 comment.appendChild(question);
n@669 586 comment.appendChild(response);
n@669 587 audioElement.appendChild(value);
n@669 588 audioElement.appendChild(comment);
n@669 589 xmlDoc.appendChild(audioElement);
n@669 590 }
n@669 591 testResultsHolders[testId] = xmlDoc;
n@668 592 }
n@668 593
n@656 594 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
n@656 595 function interfaceXMLSave(){
n@656 596 // Create the XML string to be exported with results
n@656 597 var xmlDoc = document.createElement("BrowserEvaluationResult");
n@669 598 for (var i=0; i<testResultsHolders.length; i++)
n@656 599 {
n@669 600 xmlDoc.appendChild(testResultsHolders[i]);
n@656 601 }
n@656 602 // Append Pre/Post Questions
n@656 603 xmlDoc.appendChild(preTestQuestions);
n@656 604 xmlDoc.appendChild(postTestQuestions);
n@656 605
n@656 606 return xmlDoc;
n@656 607 }
n@656 608