annotate ape.js @ 906:6d37dd0f1dc7

Moved non interface specific code from loadInterface in ape.js to core.js
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 04 Jun 2015 10:43:06 +0100
parents b64ddb277eb0
children 1b6f4304dedc
rev   line source
n@905 1 /**
n@905 2 * ape.js
n@905 3 * Create the APE interface
n@905 4 */
n@905 5
n@905 6 // preTest - In preTest state
n@905 7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
n@905 8 // testRunPost-ID - Post test of test ID
n@905 9 // testRunPre-ID - Pre-test of test ID
n@905 10 // postTest - End of test, final submission!
n@905 11
n@905 12
n@905 13 // Once this is loaded and parsed, begin execution
n@905 14 loadInterface(projectXML);
n@905 15
n@905 16 function loadInterface(xmlDoc) {
n@905 17
n@905 18 // Get the dimensions of the screen available to the page
n@905 19 var width = window.innerWidth;
n@905 20 var height = window.innerHeight;
n@905 21
n@905 22 // The injection point into the HTML page
n@905 23 var insertPoint = document.getElementById("topLevelBody");
n@905 24 var testContent = document.createElement('div');
n@905 25
n@905 26 testContent.id = 'testContent';
n@905 27
n@905 28
n@905 29 // Decode parts of the xmlDoc that are needed
n@905 30 // xmlDoc MUST already be parsed by jQuery!
n@905 31 var xmlSetup = xmlDoc.find('setup');
n@905 32 // Should put in an error function here incase of malprocessed or malformed XML
n@906 33
n@905 34
n@905 35 // Create APE specific metric functions
n@905 36 audioEngineContext.metric.initialiseTest = function()
n@905 37 {
n@905 38 };
n@905 39
n@905 40 audioEngineContext.metric.sliderMoveStart = function(id)
n@905 41 {
n@905 42 if (this.data == -1)
n@905 43 {
n@905 44 this.data = id;
n@905 45 } else {
n@905 46 console.log('ERROR: Metric tracker detecting two moves!');
n@905 47 this.data = -1;
n@905 48 }
n@905 49 };
n@905 50 audioEngineContext.metric.sliderMoved = function()
n@905 51 {
n@905 52 var time = audioEngineContext.timer.getTestTime();
n@905 53 var id = this.data;
n@905 54 this.data = -1;
n@905 55 var position = convSliderPosToRate(id);
n@905 56 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
n@905 57 if (audioEngineContext.timer.testStarted)
n@905 58 {
n@905 59 audioEngineContext.audioObjects[id].metric.moved(time,position);
n@905 60 }
n@905 61 };
n@905 62
n@905 63 audioEngineContext.metric.sliderPlayed = function(id)
n@905 64 {
n@905 65 var time = audioEngineContext.timer.getTestTime();
n@905 66 if (audioEngineContext.timer.testStarted)
n@905 67 {
n@905 68 if (this.lastClicked >= 0)
n@905 69 {
n@905 70 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
n@905 71 }
n@905 72 this.lastClicked = id;
n@905 73 audioEngineContext.audioObjects[id].metric.listening(time);
n@905 74 }
n@905 75 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
n@905 76 };
n@905 77
n@905 78 // Create the top div for the Title element
n@905 79 var titleAttr = xmlSetup[0].attributes['title'];
n@905 80 var title = document.createElement('div');
n@905 81 title.className = "title";
n@905 82 title.align = "center";
n@905 83 var titleSpan = document.createElement('span');
n@905 84
n@905 85 // Set title to that defined in XML, else set to default
n@905 86 if (titleAttr != undefined) {
n@905 87 titleSpan.innerHTML = titleAttr.value;
n@905 88 } else {
n@905 89 titleSpan.innerHTML = 'Listening test';
n@905 90 }
n@905 91 // Insert the titleSpan element into the title div element.
n@905 92 title.appendChild(titleSpan);
n@905 93
n@905 94 var pagetitle = document.createElement('div');
n@905 95 pagetitle.className = "pageTitle";
n@905 96 pagetitle.align = "center";
n@905 97 var titleSpan = document.createElement('span');
n@905 98 titleSpan.id = "pageTitle";
n@905 99 pagetitle.appendChild(titleSpan);
n@905 100
n@905 101 // Store the return URL path in global projectReturn
n@905 102 projectReturn = xmlSetup[0].attributes['projectReturn'];
n@905 103 if (projectReturn == undefined) {
n@905 104 console.log("WARNING - projectReturn not specified! Will assume null.");
n@905 105 projectReturn = "null";
n@905 106 } else {
n@905 107 projectReturn = projectReturn.value;
n@905 108 }
n@905 109
n@905 110 // Create Interface buttons!
n@905 111 var interfaceButtons = document.createElement('div');
n@905 112 interfaceButtons.id = 'interface-buttons';
n@905 113
n@905 114 // MANUAL DOWNLOAD POINT
n@905 115 // If project return is null, this MUST be specified as the location to create the download link
n@905 116 var downloadPoint = document.createElement('div');
n@905 117 downloadPoint.id = 'download-point';
n@905 118
n@905 119 // Create playback start/stop points
n@905 120 var playback = document.createElement("button");
n@905 121 playback.innerHTML = 'Stop';
n@905 122 playback.id = 'playback-button';
n@905 123 // onclick function. Check if it is playing or not, call the correct function in the
n@905 124 // audioEngine, change the button text to reflect the next state.
n@905 125 playback.onclick = function() {
n@905 126 if (audioEngineContext.status == 1) {
n@905 127 audioEngineContext.stop();
n@905 128 this.innerHTML = 'Stop';
n@905 129 var time = audioEngineContext.timer.getTestTime();
n@905 130 console.log('Stopped at ' + time); // DEBUG/SAFETY
n@905 131 }
n@905 132 };
n@905 133 // Create Submit (save) button
n@905 134 var submit = document.createElement("button");
n@905 135 submit.innerHTML = 'Submit';
n@905 136 submit.onclick = buttonSubmitClick;
n@905 137 submit.id = 'submit-button';
n@905 138 // Append the interface buttons into the interfaceButtons object.
n@905 139 interfaceButtons.appendChild(playback);
n@905 140 interfaceButtons.appendChild(submit);
n@905 141 interfaceButtons.appendChild(downloadPoint);
n@905 142
n@905 143 // Now create the slider and HTML5 canvas boxes
n@905 144
n@905 145 // Create the div box to center align
n@905 146 var sliderBox = document.createElement('div');
n@905 147 sliderBox.className = 'sliderCanvasDiv';
n@905 148 sliderBox.id = 'sliderCanvasHolder';
n@905 149
n@905 150 // Create the slider box to hold the slider elements
n@905 151 var canvas = document.createElement('div');
n@905 152 canvas.id = 'slider';
n@905 153 canvas.align = "left";
n@905 154 canvas.addEventListener('dragover',function(event){
n@905 155 event.preventDefault();
n@905 156 return false;
n@905 157 },false);
n@905 158 var sliderMargin = document.createAttribute('marginsize');
n@905 159 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
n@905 160 // Must have a known EXACT width, as this is used later to determine the ratings
n@905 161 var w = (Number(sliderMargin.nodeValue)+8)*2;
n@905 162 canvas.style.width = width - w +"px";
n@905 163 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
n@905 164 canvas.setAttributeNode(sliderMargin);
n@905 165 sliderBox.appendChild(canvas);
n@905 166
n@905 167 // Create the div to hold any scale objects
n@905 168 var scale = document.createElement('div');
n@905 169 scale.className = 'sliderScale';
n@905 170 scale.id = 'sliderScaleHolder';
n@905 171 scale.align = 'left';
n@905 172 sliderBox.appendChild(scale);
n@905 173
n@905 174 // Global parent for the comment boxes on the page
n@905 175 var feedbackHolder = document.createElement('div');
n@905 176 feedbackHolder.id = 'feedbackHolder';
n@905 177
n@905 178 testContent.style.zIndex = 1;
n@905 179 insertPoint.innerHTML = null; // Clear the current schema
n@905 180
n@905 181 // Inject into HTML
n@905 182 testContent.appendChild(title); // Insert the title
n@905 183 testContent.appendChild(pagetitle);
n@905 184 testContent.appendChild(interfaceButtons);
n@905 185 testContent.appendChild(sliderBox);
n@905 186 testContent.appendChild(feedbackHolder);
n@905 187 insertPoint.appendChild(testContent);
n@905 188
n@905 189 // Load the full interface
n@905 190 testState.initialise();
n@905 191 testState.advanceState();
n@905 192
n@905 193 }
n@905 194
n@905 195 function loadTest(textXML)
n@905 196 {
n@905 197
n@905 198 // Reset audioEngineContext.Metric globals for new test
n@905 199 audioEngineContext.newTestPage();
n@905 200
n@905 201 var id = textXML.id;
n@905 202
n@905 203 var feedbackHolder = document.getElementById('feedbackHolder');
n@905 204 var canvas = document.getElementById('slider');
n@905 205 feedbackHolder.innerHTML = null;
n@905 206 canvas.innerHTML = null;
n@905 207
n@905 208 // Setup question title
n@905 209 var interfaceObj = $(textXML).find('interface');
n@905 210 var titleNode = interfaceObj.find('title');
n@905 211 if (titleNode[0] != undefined)
n@905 212 {
n@905 213 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
n@905 214 }
n@905 215 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@905 216 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
n@905 217 var scale = document.getElementById('sliderScaleHolder');
n@905 218 scale.innerHTML = null;
n@905 219 interfaceObj.find('scale').each(function(index,scaleObj){
n@905 220 var value = document.createAttribute('value');
n@905 221 var position = Number(scaleObj.attributes['position'].value)*0.01;
n@905 222 value.nodeValue = position;
n@905 223 var pixelPosition = (position*positionScale)+offset;
n@905 224 var scaleDOM = document.createElement('span');
n@905 225 scaleDOM.textContent = scaleObj.textContent;
n@905 226 scale.appendChild(scaleDOM);
n@905 227 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@905 228 scaleDOM.setAttributeNode(value);
n@905 229 });
n@905 230
n@905 231 var commentBoxPrefix = interfaceObj.find('commentBoxPrefix');
n@905 232 if (commentBoxPrefix.length != 0) {
n@905 233 commentBoxPrefix = commentBoxPrefix[0].textContent;
n@905 234 } else {
n@905 235 commentBoxPrefix = "Comment on track";
n@905 236 }
n@905 237
n@905 238 // Extract the hostURL attribute. If not set, create an empty string.
n@905 239 var hostURL = textXML.attributes['hostURL'];
n@905 240 if (hostURL == undefined) {
n@905 241 hostURL = "";
n@905 242 } else {
n@905 243 hostURL = hostURL.value;
n@905 244 }
n@905 245 // Extract the sampleRate. If set, convert the string to a Number.
n@905 246 var hostFs = textXML.attributes['sampleRate'];
n@905 247 if (hostFs != undefined) {
n@905 248 hostFs = Number(hostFs.value);
n@905 249 }
n@905 250
n@905 251 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@905 252 if (hostFs != undefined) {
n@905 253 if (Number(hostFs) != audioContext.sampleRate) {
n@905 254 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@905 255 alert(errStr);
n@905 256 return;
n@905 257 }
n@905 258 }
n@905 259
n@905 260 var commentShow = textXML.attributes['elementComments'];
n@905 261 if (commentShow != undefined) {
n@905 262 if (commentShow.value == 'false') {commentShow = false;}
n@905 263 else {commentShow = true;}
n@905 264 } else {commentShow = true;}
n@905 265
n@905 266 var loopPlayback = textXML.attributes['loop'];
n@905 267 if (loopPlayback != undefined)
n@905 268 {
n@905 269 loopPlayback = loopPlayback.value;
n@905 270 if (loopPlayback == 'true') {
n@905 271 loopPlayback = true;
n@905 272 } else {
n@905 273 loopPlayback = false;
n@905 274 }
n@905 275 } else {
n@905 276 loopPlayback = false;
n@905 277 }
n@905 278 audioEngineContext.loopPlayback = loopPlayback;
n@905 279 // Create AudioEngine bindings for playback
n@905 280 if (loopPlayback) {
n@905 281 audioEngineContext.selectedTrack = function(id) {
n@905 282 for (var i=0; i<this.audioObjects.length; i++)
n@905 283 {
n@905 284 if (id == i) {
n@905 285 this.audioObjects[i].loopStart();
n@905 286 } else {
n@905 287 this.audioObjects[i].loopStop();
n@905 288 }
n@905 289 }
n@905 290 };
n@905 291 } else {
n@905 292 audioEngineContext.selectedTrack = function(id) {
n@905 293 for (var i=0; i<this.audioObjects.length; i++)
n@905 294 {
n@905 295 this.audioObjects[i].outputGain.gain.value = 0.0;
n@905 296 this.audioObjects[i].stop();
n@905 297 }
n@905 298 if (this.status == 1) {
n@905 299 this.audioObjects[id].outputGain.gain.value = 1.0;
n@905 300 this.audioObjects[id].play(audioContext.currentTime+0.01);
n@905 301 }
n@905 302 };
n@905 303 }
n@905 304
n@905 305 currentTestHolder = document.createElement('audioHolder');
n@905 306 currentTestHolder.id = textXML.id;
n@905 307 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
n@905 308
n@905 309 var randomise = textXML.attributes['randomiseOrder'];
n@905 310 if (randomise != undefined) {randomise = randomise.value;}
n@905 311 else {randomise = false;}
n@905 312
n@905 313 var audioElements = $(textXML).find('audioElements');
n@905 314 currentTrackOrder = [];
n@905 315 audioElements.each(function(index,element){
n@905 316 // Find any blind-repeats
n@905 317 // Not implemented yet, but just in case
n@905 318 currentTrackOrder[index] = element;
n@905 319 });
n@905 320 if (randomise) {
n@905 321 currentTrackOrder = randomiseOrder(currentTrackOrder);
n@905 322 }
n@905 323
n@905 324 // Delete any previous audioObjects associated with the audioEngine
n@905 325 audioEngineContext.audioObjects = [];
n@905 326
n@905 327 // Find all the audioElements from the audioHolder
n@905 328 $(currentTrackOrder).each(function(index,element){
n@905 329 // Find URL of track
n@905 330 // In this jQuery loop, variable 'this' holds the current audioElement.
n@905 331
n@905 332 // Now load each audio sample. First create the new track by passing the full URL
n@905 333 var trackURL = hostURL + this.attributes['url'].value;
n@905 334 audioEngineContext.newTrack(trackURL);
n@905 335
n@905 336 if (commentShow) {
n@905 337 // Create document objects to hold the comment boxes
n@905 338 var trackComment = document.createElement('div');
n@905 339 trackComment.className = 'comment-div';
n@905 340 trackComment.id = 'comment-div-'+index;
n@905 341 // Create a string next to each comment asking for a comment
n@905 342 var trackString = document.createElement('span');
n@905 343 trackString.innerHTML = commentBoxPrefix+' '+index;
n@905 344 // Create the HTML5 comment box 'textarea'
n@905 345 var trackCommentBox = document.createElement('textarea');
n@905 346 trackCommentBox.rows = '4';
n@905 347 trackCommentBox.cols = '100';
n@905 348 trackCommentBox.name = 'trackComment'+index;
n@905 349 trackCommentBox.className = 'trackComment';
n@905 350 var br = document.createElement('br');
n@905 351 // Add to the holder.
n@905 352 trackComment.appendChild(trackString);
n@905 353 trackComment.appendChild(br);
n@905 354 trackComment.appendChild(trackCommentBox);
n@905 355 feedbackHolder.appendChild(trackComment);
n@905 356 }
n@905 357
n@905 358 // Create a slider per track
n@905 359
n@905 360 var trackSliderObj = document.createElement('div');
n@905 361 trackSliderObj.className = 'track-slider';
n@905 362 trackSliderObj.id = 'track-slider-'+index;
n@905 363
n@905 364 var trackSliderAOIndex = document.createAttribute('trackIndex');
n@905 365 trackSliderAOIndex.nodeValue = index;
n@905 366 trackSliderObj.setAttributeNode(trackSliderAOIndex);
n@905 367
n@905 368 // Distribute it randomnly
n@905 369 var w = window.innerWidth - (offset+8)*2;
n@905 370 w = Math.random()*w;
n@905 371 w = Math.floor(w+(offset+8));
n@905 372 trackSliderObj.style.left = w+'px';
n@905 373 trackSliderObj.innerHTML = '<span>'+index+'</span>';
n@905 374 trackSliderObj.draggable = true;
n@905 375 trackSliderObj.ondragend = dragEnd;
n@905 376 trackSliderObj.ondragstart = function()
n@905 377 {
n@905 378 var id = Number(event.srcElement.attributes['trackIndex'].value);
n@905 379 audioEngineContext.metric.sliderMoveStart(id);
n@905 380 };
n@905 381
n@905 382 // Onclick, switch playback to that track
n@905 383 trackSliderObj.onclick = function() {
n@905 384 // Start the test on first click, that way timings are more accurate.
n@905 385 audioEngineContext.play();
n@905 386 if (audioEngineContext.audioObjectsReady) {
n@905 387 // Cannot continue to issue play command until audioObjects reported as ready!
n@905 388 // Get the track ID from the object ID
n@905 389 var id = Number(event.srcElement.attributes['trackIndex'].value);
n@905 390 //audioEngineContext.metric.sliderPlayed(id);
n@905 391 audioEngineContext.selectedTrack(id);
n@905 392 // Currently playing track red, rest green
n@905 393
n@905 394 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
n@905 395 $('.track-slider').removeClass('track-slider-playing');
n@905 396 $(event.srcElement).addClass('track-slider-playing');
n@905 397 $('.comment-div').removeClass('comment-box-playing');
n@905 398 $('#comment-div-'+id).addClass('comment-box-playing');
n@905 399 }
n@905 400 };
n@905 401
n@905 402 canvas.appendChild(trackSliderObj);
n@905 403 audioEngineContext.audioObjects[index].metric.initialised(convSliderPosToRate(index));
n@905 404
n@905 405 });
n@905 406
n@905 407 // Append any commentQuestion boxes
n@905 408 var commentQuestions = $(textXML).find('CommentQuestion');
n@905 409 $(commentQuestions).each(function(index,element) {
n@905 410 // Create document objects to hold the comment boxes
n@905 411 var trackComment = document.createElement('div');
n@905 412 trackComment.className = 'comment-div commentQuestion';
n@905 413 trackComment.id = element.attributes['id'].value;
n@905 414 // Create a string next to each comment asking for a comment
n@905 415 var trackString = document.createElement('span');
n@905 416 trackString.innerHTML = element.textContent;
n@905 417 // Create the HTML5 comment box 'textarea'
n@905 418 var trackCommentBox = document.createElement('textarea');
n@905 419 trackCommentBox.rows = '4';
n@905 420 trackCommentBox.cols = '100';
n@905 421 trackCommentBox.name = 'commentQuestion'+index;
n@905 422 trackCommentBox.className = 'trackComment';
n@905 423 var br = document.createElement('br');
n@905 424 // Add to the holder.
n@905 425 trackComment.appendChild(trackString);
n@905 426 trackComment.appendChild(br);
n@905 427 trackComment.appendChild(trackCommentBox);
n@905 428 feedbackHolder.appendChild(trackComment);
n@905 429 });
n@905 430
n@905 431
n@905 432 testWaitIndicator();
n@905 433 }
n@905 434
n@905 435
n@905 436 function dragEnd(ev) {
n@905 437 // Function call when a div has been dropped
n@905 438 var slider = document.getElementById('slider');
n@905 439 var marginSize = Number(slider.attributes['marginsize'].value);
n@905 440 var w = slider.style.width;
n@905 441 w = Number(w.substr(0,w.length-2));
n@905 442 var x = ev.x;
n@905 443 if (x >= marginSize && x < w+marginSize) {
n@905 444 this.style.left = (x)+'px';
n@905 445 } else {
n@905 446 if (x<marginSize) {
n@905 447 this.style.left = marginSize+'px';
n@905 448 } else {
n@905 449 this.style.left = (w+marginSize) + 'px';
n@905 450 }
n@905 451 }
n@905 452 audioEngineContext.metric.sliderMoved();
n@905 453 }
n@905 454
n@905 455 function buttonSubmitClick() // TODO: Only when all songs have been played!
n@905 456 {
n@905 457 hasBeenPlayed = audioEngineContext.checkAllPlayed();
n@905 458 if (hasBeenPlayed.length == 0) {
n@905 459 if (audioEngineContext.status == 1) {
n@905 460 var playback = document.getElementById('playback-button');
n@905 461 playback.click();
n@905 462 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
n@905 463 } else
n@905 464 {
n@905 465 if (audioEngineContext.timer.testStarted == false)
n@905 466 {
n@905 467 alert('You have not started the test! Please press start to begin the test!');
n@905 468 return;
n@905 469 }
n@905 470 }
n@905 471 testState.advanceState();
n@905 472 } else // if a fragment has not been played yet
n@905 473 {
n@905 474 str = "";
n@905 475 if (hasBeenPlayed.length > 1) {
n@905 476 for (var i=0; i<hasBeenPlayed.length; i++) {
n@905 477 str = str + hasBeenPlayed[i];
n@905 478 if (i < hasBeenPlayed.length-2){
n@905 479 str += ", ";
n@905 480 } else if (i == hasBeenPlayed.length-2) {
n@905 481 str += " or ";
n@905 482 }
n@905 483 }
n@905 484 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
n@905 485 } else {
n@905 486 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
n@905 487 }
n@905 488 return;
n@905 489 }
n@905 490 }
n@905 491
n@905 492 function convSliderPosToRate(id)
n@905 493 {
n@905 494 var w = document.getElementById('slider').style.width;
n@905 495 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
n@905 496 var maxPix = w.substr(0,w.length-2);
n@905 497 var slider = document.getElementsByClassName('track-slider')[id];
n@905 498 var pix = slider.style.left;
n@905 499 pix = pix.substr(0,pix.length-2);
n@905 500 var rate = (pix-marginsize)/maxPix;
n@905 501 return rate;
n@905 502 }
n@905 503
n@905 504 function resizeWindow(event){
n@905 505 // Function called when the window has been resized.
n@905 506 // MANDATORY FUNCTION
n@905 507
n@905 508 // Store the slider marker values
n@905 509 var holdValues = [];
n@905 510 $(".track-slider").each(function(index,sliderObj){
n@905 511 holdValues.push(convSliderPosToRate(index));
n@905 512 });
n@905 513
n@905 514 var width = event.target.innerWidth;
n@905 515 var canvas = document.getElementById('sliderCanvasHolder');
n@905 516 var sliderDiv = canvas.children[0];
n@905 517 var sliderScaleDiv = canvas.children[1];
n@905 518 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
n@905 519 var w = (marginsize+8)*2;
n@905 520 sliderDiv.style.width = width - w + 'px';
n@905 521 var width = width - w;
n@905 522 // Move sliders into new position
n@905 523 $(".track-slider").each(function(index,sliderObj){
n@905 524 var pos = holdValues[index];
n@905 525 var pix = pos * width;
n@905 526 sliderObj.style.left = pix+marginsize+'px';
n@905 527 });
n@905 528
n@905 529 // Move scale labels
n@905 530 $(sliderScaleDiv.children).each(function(index,scaleObj){
n@905 531 var position = Number(scaleObj.attributes['value'].value);
n@905 532 var pixelPosition = (position*width)+marginsize;
n@905 533 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
n@905 534 });
n@905 535 }
n@905 536
n@905 537 function pageXMLSave(store, testXML, testId)
n@905 538 {
n@905 539 // Saves a specific test page
n@905 540 var xmlDoc = store;
n@905 541 // Check if any session wide metrics are enabled
n@905 542
n@905 543 var commentShow = testXML.attributes['elementComments'];
n@905 544 if (commentShow != undefined) {
n@905 545 if (commentShow.value == 'false') {commentShow = false;}
n@905 546 else {commentShow = true;}
n@905 547 } else {commentShow = true;}
n@905 548
n@905 549 var metric = document.createElement('metric');
n@905 550 if (audioEngineContext.metric.enableTestTimer)
n@905 551 {
n@905 552 var testTime = document.createElement('metricResult');
n@905 553 testTime.id = 'testTime';
n@905 554 testTime.textContent = audioEngineContext.timer.testDuration;
n@905 555 metric.appendChild(testTime);
n@905 556 }
n@905 557 xmlDoc.appendChild(metric);
n@905 558 var trackSliderObjects = document.getElementsByClassName('track-slider');
n@905 559 var commentObjects = document.getElementsByClassName('comment-div');
n@905 560 for (var i=0; i<trackSliderObjects.length; i++)
n@905 561 {
n@905 562 var audioElement = document.createElement('audioElement');
n@905 563 audioElement.id = currentTrackOrder[i].attributes['id'].value;
n@905 564 audioElement.url = currentTrackOrder[i].attributes['url'].value;
n@905 565 var value = document.createElement('value');
n@905 566 value.innerHTML = convSliderPosToRate(i);
n@905 567 if (commentShow) {
n@905 568 var comment = document.createElement("comment");
n@905 569 var question = document.createElement("question");
n@905 570 var response = document.createElement("response");
n@905 571 question.textContent = commentObjects[i].children[0].textContent;
n@905 572 response.textContent = commentObjects[i].children[2].value;
n@905 573 console.log('Comment ' + i + ': ' + commentObjects[i].children[2].value); // DEBUG/SAFETY
n@905 574 comment.appendChild(question);
n@905 575 comment.appendChild(response);
n@905 576 audioElement.appendChild(comment);
n@905 577 }
n@905 578 audioElement.appendChild(value);
n@905 579 // Check for any per element metrics
n@905 580 var metric = document.createElement('metric');
n@905 581 var elementMetric = audioEngineContext.audioObjects[i].metric;
n@905 582 if (audioEngineContext.metric.enableElementTimer) {
n@905 583 var elementTimer = document.createElement('metricResult');
n@905 584 elementTimer.id = 'elementTimer';
n@905 585 elementTimer.textContent = elementMetric.listenedTimer;
n@905 586 metric.appendChild(elementTimer);
n@905 587 }
n@905 588 if (audioEngineContext.metric.enableElementTracker) {
n@905 589 var elementTrackerFull = document.createElement('metricResult');
n@905 590 elementTrackerFull.id = 'elementTrackerFull';
n@905 591 var data = elementMetric.movementTracker;
n@905 592 for (var k=0; k<data.length; k++)
n@905 593 {
n@905 594 var timePos = document.createElement('timePos');
n@905 595 timePos.id = k;
n@905 596 var time = document.createElement('time');
n@905 597 time.textContent = data[k][0];
n@905 598 var position = document.createElement('position');
n@905 599 position.textContent = data[k][1];
n@905 600 timePos.appendChild(time);
n@905 601 timePos.appendChild(position);
n@905 602 elementTrackerFull.appendChild(timePos);
n@905 603 }
n@905 604 metric.appendChild(elementTrackerFull);
n@905 605 }
n@905 606 if (audioEngineContext.metric.enableElementListenTracker) {
n@905 607 var elementListenTracker = document.createElement('metricResult');
n@905 608 elementListenTracker.id = 'elementListenTracker';
n@905 609 var obj = elementMetric.listenTracker;
n@905 610 for (var k=0; k<obj.length; k++) {
n@905 611 elementListenTracker.appendChild(obj[k]);
n@905 612 }
n@905 613 metric.appendChild(elementListenTracker);
n@905 614 }
n@905 615 if (audioEngineContext.metric.enableElementInitialPosition) {
n@905 616 var elementInitial = document.createElement('metricResult');
n@905 617 elementInitial.id = 'elementInitialPosition';
n@905 618 elementInitial.textContent = elementMetric.initialPosition;
n@905 619 metric.appendChild(elementInitial);
n@905 620 }
n@905 621 if (audioEngineContext.metric.enableFlagListenedTo) {
n@905 622 var flagListenedTo = document.createElement('metricResult');
n@905 623 flagListenedTo.id = 'elementFlagListenedTo';
n@905 624 flagListenedTo.textContent = elementMetric.wasListenedTo;
n@905 625 metric.appendChild(flagListenedTo);
n@905 626 }
n@905 627 if (audioEngineContext.metric.enableFlagMoved) {
n@905 628 var flagMoved = document.createElement('metricResult');
n@905 629 flagMoved.id = 'elementFlagMoved';
n@905 630 flagMoved.textContent = elementMetric.wasMoved;
n@905 631 metric.appendChild(flagMoved);
n@905 632 }
n@905 633 if (audioEngineContext.metric.enableFlagComments) {
n@905 634 var flagComments = document.createElement('metricResult');
n@905 635 flagComments.id = 'elementFlagComments';
n@905 636 if (response.textContent.length == 0) {flag.textContent = 'false';}
n@905 637 else {flag.textContet = 'true';}
n@905 638 metric.appendChild(flagComments);
n@905 639 }
n@905 640 audioElement.appendChild(metric);
n@905 641 xmlDoc.appendChild(audioElement);
n@905 642 }
n@905 643 var commentQuestion = document.getElementsByClassName('commentQuestion');
n@905 644 for (var i=0; i<commentQuestion.length; i++)
n@905 645 {
n@905 646 var cqHolder = document.createElement('CommentQuestion');
n@905 647 var comment = document.createElement('comment');
n@905 648 var question = document.createElement('question');
n@905 649 cqHolder.id = commentQuestion[i].id;
n@905 650 comment.textContent = commentQuestion[i].children[2].value;
n@905 651 question.textContent = commentQuestion[i].children[0].textContent;
n@905 652 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY
n@905 653 cqHolder.appendChild(question);
n@905 654 cqHolder.appendChild(comment);
n@905 655 xmlDoc.appendChild(cqHolder);
n@905 656 }
n@905 657 store = xmlDoc;
n@905 658 }