annotate core.js @ 1027:4e9ab4f92f20

Merge from branch "Dev_main"
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 10 Jun 2015 09:31:44 +0100
parents b94bb53ce4ac f13b6efc4513
children aca24f269c56
rev   line source
nicholas@1 1 /**
nicholas@1 2 * core.js
nicholas@1 3 *
nicholas@1 4 * Main script to run, calls all other core functions and manages loading/store to backend.
nicholas@1 5 * Also contains all global variables.
nicholas@1 6 */
nicholas@1 7
nicholas@1 8 /* create the web audio API context and store in audioContext*/
n@657 9 var audioContext; // Hold the browser web audio API
n@657 10 var projectXML; // Hold the parsed setup XML
n@911 11 var specification;
n@912 12 var interfaceContext;
nicholas@952 13 var popup; // Hold the interfacePopup object
nicholas@964 14 var testState;
n@669 15 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
n@657 16 var audioEngineContext; // The custome AudioEngine object
n@657 17 var projectReturn; // Hold the URL for the return
n@1007 18
n@656 19
n@681 20 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
n@681 21 AudioBufferSourceNode.prototype.owner = undefined;
nicholas@1 22
nicholas@1 23 window.onload = function() {
nicholas@1 24 // Function called once the browser has loaded all files.
nicholas@1 25 // This should perform any initial commands such as structure / loading documents
nicholas@1 26
nicholas@1 27 // Create a web audio API context
nicholas@705 28 // Fixed for cross-browser support
nicholas@705 29 var AudioContext = window.AudioContext || window.webkitAudioContext;
nicholas@7 30 audioContext = new AudioContext;
nicholas@1 31
nicholas@964 32 // Create test state
nicholas@964 33 testState = new stateMachine();
nicholas@964 34
nicholas@1 35 // Create the audio engine object
nicholas@1 36 audioEngineContext = new AudioEngine();
nicholas@952 37
nicholas@952 38 // Create the popup interface object
nicholas@952 39 popup = new interfacePopup();
n@911 40
n@911 41 // Create the specification object
n@911 42 specification = new Specification();
n@912 43
n@912 44 // Create the interface object
n@912 45 interfaceContext = new Interface(specification);
n@701 46 };
nicholas@1 47
nicholas@952 48 function interfacePopup() {
nicholas@952 49 // Creates an object to manage the popup
nicholas@952 50 this.popup = null;
nicholas@952 51 this.popupContent = null;
n@904 52 this.buttonProceed = null;
nicholas@952 53 this.popupOptions = null;
nicholas@952 54 this.currentIndex = null;
nicholas@952 55 this.responses = null;
n@911 56
nicholas@952 57 this.createPopup = function(){
nicholas@952 58 // Create popup window interface
nicholas@952 59 var insertPoint = document.getElementById("topLevelBody");
nicholas@952 60 var blank = document.createElement('div');
nicholas@952 61 blank.className = 'testHalt';
nicholas@952 62
nicholas@952 63 this.popup = document.createElement('div');
nicholas@952 64 this.popup.id = 'popupHolder';
nicholas@952 65 this.popup.className = 'popupHolder';
nicholas@952 66 this.popup.style.position = 'absolute';
nicholas@952 67 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
nicholas@952 68 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
nicholas@952 69
nicholas@952 70 this.popupContent = document.createElement('div');
nicholas@952 71 this.popupContent.id = 'popupContent';
nicholas@952 72 this.popupContent.style.marginTop = '25px';
nicholas@952 73 this.popupContent.align = 'center';
nicholas@952 74 this.popup.appendChild(this.popupContent);
nicholas@952 75
n@904 76 this.buttonProceed = document.createElement('button');
n@904 77 this.buttonProceed.className = 'popupButton';
n@904 78 this.buttonProceed.innerHTML = 'Next';
n@904 79 this.buttonProceed.onclick = function(){popup.proceedClicked();};
n@911 80 this.popup.style.zIndex = -1;
n@911 81 this.popup.style.visibility = 'hidden';
n@911 82 blank.style.zIndex = -2;
n@911 83 blank.style.visibility = 'hidden';
nicholas@952 84 insertPoint.appendChild(this.popup);
nicholas@952 85 insertPoint.appendChild(blank);
nicholas@952 86 };
nicholas@951 87
nicholas@952 88 this.showPopup = function(){
n@911 89 if (this.popup == null) {
nicholas@952 90 this.createPopup();
nicholas@952 91 }
nicholas@952 92 this.popup.style.zIndex = 3;
nicholas@952 93 this.popup.style.visibility = 'visible';
nicholas@952 94 var blank = document.getElementsByClassName('testHalt')[0];
nicholas@952 95 blank.style.zIndex = 2;
nicholas@952 96 blank.style.visibility = 'visible';
nicholas@952 97 };
nicholas@952 98
nicholas@952 99 this.hidePopup = function(){
nicholas@952 100 this.popup.style.zIndex = -1;
nicholas@952 101 this.popup.style.visibility = 'hidden';
nicholas@952 102 var blank = document.getElementsByClassName('testHalt')[0];
nicholas@952 103 blank.style.zIndex = -2;
nicholas@952 104 blank.style.visibility = 'hidden';
nicholas@952 105 };
nicholas@952 106
nicholas@952 107 this.postNode = function() {
nicholas@952 108 // This will take the node from the popupOptions and display it
nicholas@952 109 var node = this.popupOptions[this.currentIndex];
nicholas@952 110 this.popupContent.innerHTML = null;
n@911 111 if (node.type == 'statement') {
nicholas@952 112 var span = document.createElement('span');
n@911 113 span.textContent = node.statement;
nicholas@952 114 this.popupContent.appendChild(span);
n@911 115 } else if (node.type == 'question') {
nicholas@952 116 var span = document.createElement('span');
n@911 117 span.textContent = node.question;
nicholas@952 118 var textArea = document.createElement('textarea');
n@1024 119 switch (node.boxsize) {
n@1024 120 case 'small':
n@1024 121 textArea.cols = "20";
n@1024 122 textArea.rows = "1";
n@1024 123 break;
n@1024 124 case 'normal':
n@1024 125 textArea.cols = "30";
n@1024 126 textArea.rows = "2";
n@1024 127 break;
n@1024 128 case 'large':
n@1024 129 textArea.cols = "40";
n@1024 130 textArea.rows = "5";
n@1024 131 break;
n@1024 132 case 'huge':
n@1024 133 textArea.cols = "50";
n@1024 134 textArea.rows = "10";
n@1024 135 break;
n@1024 136 }
nicholas@952 137 var br = document.createElement('br');
nicholas@952 138 this.popupContent.appendChild(span);
nicholas@952 139 this.popupContent.appendChild(br);
nicholas@952 140 this.popupContent.appendChild(textArea);
n@1009 141 this.popupContent.childNodes[2].focus();
nicholas@918 142 } else if (node.type == 'checkbox') {
nicholas@918 143 var span = document.createElement('span');
nicholas@918 144 span.textContent = node.statement;
nicholas@918 145 this.popupContent.appendChild(span);
nicholas@918 146 var optHold = document.createElement('div');
nicholas@918 147 optHold.id = 'option-holder';
nicholas@918 148 optHold.align = 'left';
nicholas@918 149 for (var i=0; i<node.options.length; i++) {
nicholas@918 150 var option = node.options[i];
nicholas@918 151 var input = document.createElement('input');
nicholas@918 152 input.id = option.id;
nicholas@918 153 input.type = 'checkbox';
nicholas@918 154 var span = document.createElement('span');
nicholas@918 155 span.textContent = option.text;
nicholas@918 156 var hold = document.createElement('div');
nicholas@918 157 hold.setAttribute('name','option');
nicholas@918 158 hold.style.float = 'left';
nicholas@918 159 hold.style.padding = '4px';
nicholas@918 160 hold.appendChild(input);
nicholas@918 161 hold.appendChild(span);
nicholas@918 162 optHold.appendChild(hold);
nicholas@918 163 }
nicholas@918 164 this.popupContent.appendChild(optHold);
nicholas@919 165 } else if (node.type == 'radio') {
nicholas@919 166 var span = document.createElement('span');
nicholas@919 167 span.textContent = node.statement;
nicholas@919 168 this.popupContent.appendChild(span);
nicholas@919 169 var optHold = document.createElement('div');
nicholas@919 170 optHold.id = 'option-holder';
nicholas@919 171 optHold.align = 'none';
nicholas@919 172 optHold.style.float = 'left';
nicholas@919 173 optHold.style.width = "100%";
nicholas@919 174 for (var i=0; i<node.options.length; i++) {
nicholas@919 175 var option = node.options[i];
nicholas@919 176 var input = document.createElement('input');
nicholas@919 177 input.id = option.name;
nicholas@919 178 input.type = 'radio';
nicholas@919 179 input.name = node.id;
nicholas@919 180 var span = document.createElement('span');
nicholas@919 181 span.textContent = option.text;
nicholas@919 182 var hold = document.createElement('div');
nicholas@919 183 hold.setAttribute('name','option');
nicholas@919 184 hold.style.padding = '4px';
nicholas@919 185 hold.appendChild(input);
nicholas@919 186 hold.appendChild(span);
nicholas@919 187 optHold.appendChild(hold);
nicholas@919 188 }
nicholas@919 189 this.popupContent.appendChild(optHold);
n@903 190 } else if (node.type == 'number') {
n@903 191 var span = document.createElement('span');
n@903 192 span.textContent = node.statement;
n@903 193 this.popupContent.appendChild(span);
n@903 194 this.popupContent.appendChild(document.createElement('br'));
n@903 195 var input = document.createElement('input');
n@903 196 input.type = 'number';
n@903 197 if (node.min != null) {input.min = node.min;}
n@903 198 if (node.max != null) {input.max = node.max;}
n@903 199 if (node.step != null) {input.step = node.step;}
n@903 200 this.popupContent.appendChild(input);
nicholas@952 201 }
n@904 202 this.popupContent.appendChild(this.buttonProceed);
n@1009 203 };
nicholas@952 204
nicholas@952 205 this.initState = function(node) {
nicholas@952 206 //Call this with your preTest and postTest nodes when needed to
nicholas@952 207 // initialise the popup procedure.
n@911 208 this.popupOptions = node.options;
nicholas@952 209 if (this.popupOptions.length > 0) {
n@911 210 if (node.type == 'pretest') {
nicholas@952 211 this.responses = document.createElement('PreTest');
n@911 212 } else if (node.type == 'posttest') {
nicholas@952 213 this.responses = document.createElement('PostTest');
nicholas@952 214 } else {
nicholas@952 215 console.log ('WARNING - popup node neither pre or post!');
nicholas@952 216 this.responses = document.createElement('responses');
nicholas@952 217 }
nicholas@952 218 this.currentIndex = 0;
nicholas@952 219 this.showPopup();
nicholas@952 220 this.postNode();
n@911 221 } else {
n@911 222 advanceState();
nicholas@952 223 }
n@1009 224 };
nicholas@952 225
n@904 226 this.proceedClicked = function() {
nicholas@952 227 // Each time the popup button is clicked!
nicholas@952 228 var node = this.popupOptions[this.currentIndex];
n@911 229 if (node.type == 'question') {
nicholas@952 230 // Must extract the question data
nicholas@952 231 var textArea = $(popup.popupContent).find('textarea')[0];
n@911 232 if (node.mandatory == true && textArea.value.length == 0) {
nicholas@952 233 alert('This question is mandatory');
nicholas@952 234 return;
nicholas@952 235 } else {
nicholas@952 236 // Save the text content
nicholas@952 237 var hold = document.createElement('comment');
n@911 238 hold.id = node.id;
nicholas@952 239 hold.innerHTML = textArea.value;
n@902 240 console.log("Question: "+ node.question);
nicholas@953 241 console.log("Question Response: "+ textArea.value);
nicholas@952 242 this.responses.appendChild(hold);
nicholas@952 243 }
nicholas@918 244 } else if (node.type == 'checkbox') {
nicholas@918 245 // Must extract checkbox data
nicholas@918 246 var optHold = document.getElementById('option-holder');
nicholas@918 247 var hold = document.createElement('checkbox');
nicholas@918 248 console.log("Checkbox: "+ node.statement);
nicholas@919 249 hold.id = node.id;
nicholas@918 250 for (var i=0; i<optHold.childElementCount; i++) {
nicholas@918 251 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
nicholas@918 252 var statement = optHold.childNodes[i].getElementsByTagName('span')[0];
nicholas@918 253 var response = document.createElement('option');
n@902 254 response.setAttribute('name',input.id);
n@902 255 response.textContent = input.checked;
nicholas@918 256 hold.appendChild(response);
nicholas@918 257 console.log(input.id +': '+ input.checked);
nicholas@918 258 }
nicholas@918 259 this.responses.appendChild(hold);
nicholas@919 260 } else if (node.type == "radio") {
nicholas@919 261 var optHold = document.getElementById('option-holder');
nicholas@919 262 var hold = document.createElement('radio');
nicholas@919 263 var responseID = null;
nicholas@919 264 var i=0;
nicholas@919 265 while(responseID == null) {
nicholas@919 266 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
nicholas@919 267 if (input.checked == true) {
nicholas@919 268 responseID = i;
nicholas@919 269 }
nicholas@919 270 i++;
nicholas@919 271 }
nicholas@919 272 hold.id = node.id;
nicholas@919 273 hold.setAttribute('name',node.options[responseID].name);
nicholas@919 274 hold.textContent = node.options[responseID].text;
nicholas@919 275 this.responses.appendChild(hold);
n@903 276 } else if (node.type == "number") {
n@903 277 var input = this.popupContent.getElementsByTagName('input')[0];
n@903 278 if (node.mandatory == true && input.value.length == 0) {
n@904 279 alert('This question is mandatory. Please enter a number');
n@904 280 return;
n@904 281 }
n@904 282 var enteredNumber = Number(input.value);
n@904 283 if (enteredNumber == undefined) {
n@904 284 alert('Please enter a valid number');
n@904 285 return;
n@904 286 }
n@904 287 if (enteredNumber < node.min && node.min != null) {
n@904 288 alert('Number is below the minimum value of '+node.min);
n@904 289 return;
n@904 290 }
n@904 291 if (enteredNumber > node.max && node.max != null) {
n@904 292 alert('Number is above the maximum value of '+node.max);
n@903 293 return;
n@903 294 }
n@903 295 var hold = document.createElement('number');
n@903 296 hold.id = node.id;
n@903 297 hold.textContent = input.value;
n@903 298 this.responses.appendChild(hold);
nicholas@952 299 }
nicholas@952 300 this.currentIndex++;
nicholas@952 301 if (this.currentIndex < this.popupOptions.length) {
n@904 302 if(this.currentIndex+1 == this.popupOptions.length) {
n@904 303 this.buttonProceed.textContent = 'Submit';
n@904 304 }
nicholas@952 305 this.postNode();
nicholas@952 306 } else {
nicholas@952 307 // Reached the end of the popupOptions
nicholas@952 308 this.hidePopup();
nicholas@964 309 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) {
nicholas@964 310 testState.stateResults[testState.stateIndex] = this.responses;
nicholas@964 311 } else {
nicholas@964 312 testState.stateResults[testState.stateIndex].appendChild(this.responses);
nicholas@964 313 }
nicholas@952 314 advanceState();
nicholas@952 315 }
n@1009 316 };
nicholas@951 317 }
nicholas@951 318
nicholas@952 319 function advanceState()
nicholas@951 320 {
nicholas@964 321 // Just for complete clarity
nicholas@964 322 testState.advanceState();
nicholas@964 323 }
nicholas@964 324
nicholas@964 325 function stateMachine()
nicholas@964 326 {
nicholas@964 327 // Object prototype for tracking and managing the test state
nicholas@964 328 this.stateMap = [];
nicholas@964 329 this.stateIndex = null;
nicholas@964 330 this.currentStateMap = [];
nicholas@964 331 this.currentIndex = null;
nicholas@964 332 this.currentTestId = 0;
nicholas@964 333 this.stateResults = [];
nicholas@934 334 this.timerCallBackHolders = null;
nicholas@964 335 this.initialise = function(){
nicholas@964 336 if (this.stateMap.length > 0) {
nicholas@964 337 if(this.stateIndex != null) {
nicholas@964 338 console.log('NOTE - State already initialise');
nicholas@964 339 }
nicholas@964 340 this.stateIndex = -1;
nicholas@964 341 var that = this;
nicholas@964 342 for (var id=0; id<this.stateMap.length; id++){
n@911 343 var name = this.stateMap[id].type;
nicholas@964 344 var obj = document.createElement(name);
nicholas@917 345 if (name == 'audioHolder') {
n@930 346 obj.id = this.stateMap[id].id;
n@930 347 }
nicholas@964 348 this.stateResults.push(obj);
nicholas@964 349 }
nicholas@964 350 } else {
nicholas@964 351 conolse.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
nicholas@952 352 }
nicholas@964 353 };
nicholas@964 354 this.advanceState = function(){
nicholas@964 355 if (this.stateIndex == null) {
nicholas@964 356 this.initialise();
nicholas@964 357 }
nicholas@964 358 if (this.stateIndex == -1) {
nicholas@964 359 console.log('Starting test...');
nicholas@964 360 }
nicholas@964 361 if (this.currentIndex == null){
n@911 362 if (this.currentStateMap.type == "audioHolder") {
nicholas@964 363 // Save current page
nicholas@964 364 this.testPageCompleted(this.stateResults[this.stateIndex],this.currentStateMap,this.currentTestId);
nicholas@964 365 this.currentTestId++;
nicholas@964 366 }
nicholas@964 367 this.stateIndex++;
nicholas@964 368 if (this.stateIndex >= this.stateMap.length) {
nicholas@964 369 console.log('Test Completed');
n@912 370 createProjectSave(specification.projectReturn);
nicholas@964 371 } else {
nicholas@964 372 this.currentStateMap = this.stateMap[this.stateIndex];
n@911 373 if (this.currentStateMap.type == "audioHolder") {
nicholas@964 374 console.log('Loading test page');
nicholas@964 375 loadTest(this.currentStateMap);
nicholas@964 376 this.initialiseInnerState(this.currentStateMap);
n@911 377 } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") {
n@911 378 if (this.currentStateMap.options.length >= 1) {
nicholas@964 379 popup.initState(this.currentStateMap);
nicholas@964 380 } else {
nicholas@964 381 this.advanceState();
nicholas@964 382 }
nicholas@964 383 } else {
nicholas@964 384 this.advanceState();
nicholas@964 385 }
nicholas@964 386 }
nicholas@964 387 } else {
nicholas@964 388 this.advanceInnerState();
nicholas@964 389 }
nicholas@964 390 };
nicholas@964 391
nicholas@964 392 this.testPageCompleted = function(store, testXML, testId) {
nicholas@964 393 // Function called each time a test page has been completed
nicholas@964 394 // Can be used to over-rule default behaviour
nicholas@964 395
n@911 396 pageXMLSave(store, testXML);
n@906 397 };
nicholas@964 398
n@911 399 this.initialiseInnerState = function(node) {
nicholas@964 400 // Parses the received testXML for pre and post test options
nicholas@964 401 this.currentStateMap = [];
n@911 402 var preTest = node.preTest;
n@911 403 var postTest = node.postTest;
nicholas@964 404 if (preTest == undefined) {preTest = document.createElement("preTest");}
nicholas@964 405 if (postTest == undefined){postTest= document.createElement("postTest");}
nicholas@964 406 this.currentStateMap.push(preTest);
n@911 407 this.currentStateMap.push(node);
nicholas@964 408 this.currentStateMap.push(postTest);
nicholas@964 409 this.currentIndex = -1;
nicholas@964 410 this.advanceInnerState();
n@906 411 };
nicholas@964 412
nicholas@964 413 this.advanceInnerState = function() {
nicholas@964 414 this.currentIndex++;
nicholas@964 415 if (this.currentIndex >= this.currentStateMap.length) {
nicholas@964 416 this.currentIndex = null;
nicholas@964 417 this.currentStateMap = this.stateMap[this.stateIndex];
nicholas@964 418 this.advanceState();
nicholas@964 419 } else {
n@911 420 if (this.currentStateMap[this.currentIndex].type == "audioHolder") {
nicholas@964 421 console.log("Loading test page"+this.currentTestId);
n@911 422 } else if (this.currentStateMap[this.currentIndex].type == "pretest") {
nicholas@964 423 popup.initState(this.currentStateMap[this.currentIndex]);
n@911 424 } else if (this.currentStateMap[this.currentIndex].type == "posttest") {
nicholas@964 425 popup.initState(this.currentStateMap[this.currentIndex]);
nicholas@964 426 } else {
nicholas@964 427 this.advanceInnerState();
nicholas@964 428 }
nicholas@952 429 }
n@906 430 };
nicholas@964 431
nicholas@964 432 this.previousState = function(){};
nicholas@951 433 }
nicholas@951 434
nicholas@952 435 function testEnded(testId)
nicholas@951 436 {
nicholas@952 437 pageXMLSave(testId);
nicholas@952 438 if (testXMLSetups.length-1 > testId)
nicholas@952 439 {
nicholas@952 440 // Yes we have another test to perform
nicholas@952 441 testId = (Number(testId)+1);
nicholas@952 442 currentState = 'testRun-'+testId;
nicholas@952 443 loadTest(testId);
nicholas@952 444 } else {
nicholas@952 445 console.log('Testing Completed!');
nicholas@952 446 currentState = 'postTest';
nicholas@952 447 // Check for any post tests
nicholas@952 448 var xmlSetup = projectXML.find('setup');
nicholas@952 449 var postTest = xmlSetup.find('PostTest')[0];
nicholas@952 450 popup.initState(postTest);
nicholas@952 451 }
nicholas@951 452 }
nicholas@951 453
nicholas@1 454 function loadProjectSpec(url) {
nicholas@1 455 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
nicholas@1 456 // If url is null, request client to upload project XML document
nicholas@2 457 var r = new XMLHttpRequest();
nicholas@2 458 r.open('GET',url,true);
nicholas@2 459 r.onload = function() {
nicholas@2 460 loadProjectSpecCallback(r.response);
n@701 461 };
nicholas@2 462 r.send();
n@701 463 };
nicholas@2 464
nicholas@2 465 function loadProjectSpecCallback(response) {
nicholas@2 466 // Function called after asynchronous download of XML project specification
n@910 467 //var decode = $.parseXML(response);
n@910 468 //projectXML = $(decode);
nicholas@2 469
n@910 470 var parse = new DOMParser();
n@910 471 projectXML = parse.parseFromString(response,'text/xml');
n@905 472
n@911 473 // Build the specification
n@911 474 specification.decode();
n@906 475
n@911 476 testState.stateMap.push(specification.preTest);
n@906 477
n@906 478 // New check if we need to randomise the test order
n@911 479 if (specification.randomiseOrder)
n@911 480 {
n@911 481 specification.audioHolders = randomiseOrder(specification.audioHolders);
n@906 482 }
n@906 483
n@911 484 $(specification.audioHolders).each(function(index,elem){
n@906 485 testState.stateMap.push(elem);
n@906 486 });
n@906 487
n@911 488 testState.stateMap.push(specification.postTest);
n@906 489
n@906 490 // Obtain the metrics enabled
n@911 491 $(specification.metrics).each(function(index,node){
n@906 492 var enabled = node.textContent;
n@911 493 switch(node.enabled)
n@906 494 {
n@906 495 case 'testTimer':
n@906 496 sessionMetrics.prototype.enableTestTimer = true;
n@906 497 break;
n@906 498 case 'elementTimer':
n@906 499 sessionMetrics.prototype.enableElementTimer = true;
n@906 500 break;
n@906 501 case 'elementTracker':
n@906 502 sessionMetrics.prototype.enableElementTracker = true;
n@906 503 break;
n@906 504 case 'elementListenTracker':
n@906 505 sessionMetrics.prototype.enableElementListenTracker = true;
n@906 506 break;
n@906 507 case 'elementInitialPosition':
n@906 508 sessionMetrics.prototype.enableElementInitialPosition = true;
n@906 509 break;
n@906 510 case 'elementFlagListenedTo':
n@906 511 sessionMetrics.prototype.enableFlagListenedTo = true;
n@906 512 break;
n@906 513 case 'elementFlagMoved':
n@906 514 sessionMetrics.prototype.enableFlagMoved = true;
n@906 515 break;
n@906 516 case 'elementFlagComments':
n@906 517 sessionMetrics.prototype.enableFlagComments = true;
n@906 518 break;
n@906 519 }
n@906 520 });
n@906 521
n@906 522
n@906 523
n@701 524 // Detect the interface to use and load the relevant javascripts.
nicholas@2 525 var interfaceJS = document.createElement('script');
nicholas@2 526 interfaceJS.setAttribute("type","text/javascript");
n@911 527 if (specification.interfaceType == 'APE') {
nicholas@2 528 interfaceJS.setAttribute("src","ape.js");
n@657 529
n@657 530 // APE comes with a css file
n@657 531 var css = document.createElement('link');
n@657 532 css.rel = 'stylesheet';
n@657 533 css.type = 'text/css';
n@657 534 css.href = 'ape.css';
n@657 535
n@657 536 document.getElementsByTagName("head")[0].appendChild(css);
nicholas@2 537 }
nicholas@2 538 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
n@963 539
n@963 540 // Define window callbacks for interface
n@963 541 window.onresize = function(event){resizeWindow(event);};
nicholas@1 542 }
nicholas@1 543
nicholas@1 544 function createProjectSave(destURL) {
nicholas@1 545 // Save the data from interface into XML and send to destURL
nicholas@1 546 // If destURL is null then download XML in client
nicholas@7 547 // Now time to render file locally
nicholas@7 548 var xmlDoc = interfaceXMLSave();
nicholas@958 549 var parent = document.createElement("div");
nicholas@958 550 parent.appendChild(xmlDoc);
nicholas@958 551 var file = [parent.innerHTML];
nicholas@7 552 if (destURL == "null" || destURL == undefined) {
nicholas@7 553 var bb = new Blob(file,{type : 'application/xml'});
nicholas@7 554 var dnlk = window.URL.createObjectURL(bb);
nicholas@7 555 var a = document.createElement("a");
nicholas@7 556 a.hidden = '';
nicholas@7 557 a.href = dnlk;
nicholas@7 558 a.download = "save.xml";
nicholas@7 559 a.textContent = "Save File";
nicholas@7 560
nicholas@954 561 popup.showPopup();
nicholas@954 562 popup.popupContent.innerHTML = null;
n@912 563 popup.popupContent.appendChild(a);
nicholas@958 564 } else {
nicholas@958 565 var xmlhttp = new XMLHttpRequest;
nicholas@958 566 xmlhttp.open("POST",destURL,true);
nicholas@958 567 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
n@959 568 xmlhttp.onerror = function(){
n@959 569 console.log('Error saving file to server! Presenting download locally');
n@959 570 createProjectSave(null);
n@959 571 };
n@1012 572 xmlhttp.onreadystatechange = function() {
n@1012 573 console.log(xmlhttp.status);
n@1012 574 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
n@1012 575 createProjectSave(null);
n@1012 576 }
n@1012 577 };
nicholas@958 578 xmlhttp.send(file);
nicholas@7 579 }
nicholas@1 580 }
nicholas@1 581
nicholas@964 582 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
nicholas@964 583 function interfaceXMLSave(){
nicholas@964 584 // Create the XML string to be exported with results
nicholas@964 585 var xmlDoc = document.createElement("BrowserEvaluationResult");
nicholas@964 586 xmlDoc.appendChild(returnDateNode());
nicholas@964 587 for (var i=0; i<testState.stateResults.length; i++)
nicholas@964 588 {
nicholas@964 589 xmlDoc.appendChild(testState.stateResults[i]);
nicholas@964 590 }
nicholas@964 591
nicholas@964 592 return xmlDoc;
nicholas@964 593 }
nicholas@964 594
nicholas@1 595 function AudioEngine() {
nicholas@1 596
nicholas@1 597 // Create two output paths, the main outputGain and fooGain.
nicholas@1 598 // Output gain is default to 1 and any items for playback route here
nicholas@1 599 // Foo gain is used for analysis to ensure paths get processed, but are not heard
nicholas@1 600 // because web audio will optimise and any route which does not go to the destination gets ignored.
nicholas@1 601 this.outputGain = audioContext.createGain();
nicholas@1 602 this.fooGain = audioContext.createGain();
nicholas@1 603 this.fooGain.gain = 0;
nicholas@1 604
nicholas@7 605 // Use this to detect playback state: 0 - stopped, 1 - playing
nicholas@7 606 this.status = 0;
n@950 607 this.audioObjectsReady = false;
nicholas@7 608
nicholas@1 609 // Connect both gains to output
nicholas@1 610 this.outputGain.connect(audioContext.destination);
nicholas@1 611 this.fooGain.connect(audioContext.destination);
nicholas@1 612
n@673 613 // Create the timer Object
n@673 614 this.timer = new timer();
n@673 615 // Create session metrics
n@673 616 this.metric = new sessionMetrics(this);
n@673 617
n@681 618 this.loopPlayback = false;
n@681 619
nicholas@1 620 // Create store for new audioObjects
nicholas@1 621 this.audioObjects = [];
nicholas@1 622
n@950 623 this.play = function() {
n@950 624 // Start the timer and set the audioEngine state to playing (1)
n@950 625 if (this.status == 0) {
n@950 626 // Check if all audioObjects are ready
n@950 627 if (this.audioObjectsReady == false) {
n@950 628 this.audioObjectsReady = this.checkAllReady();
n@950 629 }
n@950 630 if (this.audioObjectsReady == true) {
n@950 631 this.timer.startTest();
nicholas@966 632 if (this.loopPlayback) {
nicholas@966 633 for(var i=0; i<this.audioObjects.length; i++) {
nicholas@966 634 this.audioObjects[i].play(this.timer.getTestTime()+1);
nicholas@966 635 }
nicholas@966 636 }
n@950 637 this.status = 1;
n@950 638 }
n@950 639 }
n@950 640 };
nicholas@1 641
n@950 642 this.stop = function() {
n@950 643 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1)
n@950 644 if (this.status == 1) {
n@950 645 for (var i=0; i<this.audioObjects.length; i++)
n@950 646 {
n@950 647 this.audioObjects[i].stop();
n@950 648 }
n@950 649 this.status = 0;
n@950 650 }
n@950 651 };
nicholas@8 652
nicholas@8 653
n@912 654 this.newTrack = function(element) {
nicholas@1 655 // Pull data from given URL into new audio buffer
nicholas@1 656 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
nicholas@7 657
nicholas@1 658 // Create the audioObject with ID of the new track length;
n@673 659 audioObjectId = this.audioObjects.length;
nicholas@1 660 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
nicholas@7 661
nicholas@7 662 // AudioObject will get track itself.
n@912 663 this.audioObjects[audioObjectId].specification = element;
n@912 664 this.audioObjects[audioObjectId].constructTrack(element.parent.hostURL + element.url);
n@909 665 return this.audioObjects[audioObjectId];
n@701 666 };
nicholas@1 667
n@950 668 this.newTestPage = function() {
n@950 669 this.state = 0;
n@950 670 this.audioObjectsReady = false;
n@950 671 this.metric.reset();
n@950 672 this.audioObjects = [];
n@950 673 };
n@950 674
nicholas@944 675 this.checkAllPlayed = function() {
nicholas@944 676 arr = [];
nicholas@944 677 for (var id=0; id<this.audioObjects.length; id++) {
nicholas@1002 678 if (this.audioObjects[id].metric.wasListenedTo == false) {
nicholas@944 679 arr.push(this.audioObjects[id].id);
nicholas@944 680 }
nicholas@944 681 }
nicholas@944 682 return arr;
nicholas@944 683 };
nicholas@944 684
n@950 685 this.checkAllReady = function() {
n@950 686 var ready = true;
n@950 687 for (var i=0; i<this.audioObjects.length; i++) {
n@950 688 if (this.audioObjects[i].state == 0) {
n@950 689 // Track not ready
n@950 690 console.log('WAIT -- audioObject '+i+' not ready yet!');
n@950 691 ready = false;
n@950 692 };
n@950 693 }
n@950 694 return ready;
n@950 695 };
n@950 696
nicholas@1 697 }
nicholas@1 698
nicholas@1 699 function audioObject(id) {
nicholas@1 700 // The main buffer object with common control nodes to the AudioEngine
nicholas@1 701
n@912 702 this.specification;
nicholas@1 703 this.id = id;
nicholas@1 704 this.state = 0; // 0 - no data, 1 - ready
n@708 705 this.url = null; // Hold the URL given for the output back to the results.
n@932 706 this.metric = new metricTracker(this);
nicholas@1 707
n@907 708 // Bindings for GUI
n@913 709 this.interfaceDOM = null;
n@907 710 this.commentDOM = null;
n@907 711
nicholas@1 712 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
n@681 713 this.bufferNode = undefined;
nicholas@1 714 this.outputGain = audioContext.createGain();
nicholas@1 715
nicholas@8 716 // Default output gain to be zero
nicholas@8 717 this.outputGain.gain.value = 0.0;
nicholas@8 718
nicholas@1 719 // Connect buffer to the audio graph
nicholas@1 720 this.outputGain.connect(audioEngineContext.outputGain);
nicholas@1 721
nicholas@1 722 // the audiobuffer is not designed for multi-start playback
nicholas@1 723 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
nicholas@1 724 this.buffer;
BrechtDeMan@969 725
nicholas@967 726 this.loopStart = function() {
nicholas@967 727 this.outputGain.gain.value = 1.0;
nicholas@967 728 this.metric.startListening(audioEngineContext.timer.getTestTime());
n@907 729 };
nicholas@967 730
nicholas@967 731 this.loopStop = function() {
nicholas@967 732 if (this.outputGain.gain.value != 0.0) {
nicholas@967 733 this.outputGain.gain.value = 0.0;
nicholas@967 734 this.metric.stopListening(audioEngineContext.timer.getTestTime());
nicholas@967 735 }
n@907 736 };
nicholas@967 737
nicholas@1 738 this.play = function(startTime) {
n@681 739 this.bufferNode = audioContext.createBufferSource();
nicholas@947 740 this.bufferNode.owner = this;
n@681 741 this.bufferNode.connect(this.outputGain);
n@681 742 this.bufferNode.buffer = this.buffer;
n@681 743 this.bufferNode.loop = audioEngineContext.loopPlayback;
nicholas@967 744 this.bufferNode.onended = function() {
nicholas@1002 745 // Safari does not like using 'this' to reference the calling object!
nicholas@1003 746 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime());
nicholas@1002 747 };
nicholas@947 748 if (this.bufferNode.loop == false) {
nicholas@967 749 this.metric.startListening(audioEngineContext.timer.getTestTime());
nicholas@947 750 }
nicholas@1 751 this.bufferNode.start(startTime);
n@701 752 };
nicholas@1 753
nicholas@1 754 this.stop = function() {
n@996 755 if (this.bufferNode != undefined)
n@996 756 {
n@996 757 this.bufferNode.stop(0);
n@996 758 this.bufferNode = undefined;
nicholas@967 759 this.metric.stopListening(audioEngineContext.timer.getTestTime());
n@996 760 }
n@701 761 };
n@1013 762
n@1013 763 this.getCurrentPosition = function() {
n@1013 764 var time = audioEngineContext.timer.getTestTime();
n@1013 765 if (this.bufferNode != undefined) {
n@1013 766 if (this.bufferNode.loop == true) {
n@1013 767 if (audioEngineContext.status == 1) {
n@1013 768 return time%this.buffer.duration;
n@1013 769 } else {
n@1013 770 return 0;
n@1013 771 }
n@1013 772 } else {
n@1013 773 if (this.metric.listenHold) {
n@1013 774 return time - this.metric.listenStart;
n@1013 775 } else {
n@1013 776 return 0;
n@1013 777 }
n@1013 778 }
n@1013 779 } else {
n@1013 780 return 0;
n@1013 781 }
n@1013 782 };
nicholas@8 783
nicholas@7 784 this.constructTrack = function(url) {
nicholas@7 785 var request = new XMLHttpRequest();
n@708 786 this.url = url;
nicholas@7 787 request.open('GET',url,true);
nicholas@7 788 request.responseType = 'arraybuffer';
nicholas@7 789
nicholas@7 790 var audioObj = this;
nicholas@7 791
nicholas@7 792 // Create callback to decode the data asynchronously
nicholas@7 793 request.onloadend = function() {
nicholas@7 794 audioContext.decodeAudioData(request.response, function(decodedData) {
nicholas@7 795 audioObj.buffer = decodedData;
nicholas@7 796 audioObj.state = 1;
nicholas@7 797 }, function(){
nicholas@7 798 // Should only be called if there was an error, but sometimes gets called continuously
nicholas@7 799 // Check here if the error is genuine
nicholas@7 800 if (audioObj.state == 0 || audioObj.buffer == undefined) {
nicholas@7 801 // Genuine error
nicholas@7 802 console.log('FATAL - Error loading buffer on '+audioObj.id);
nicholas@7 803 }
nicholas@7 804 });
n@701 805 };
nicholas@7 806 request.send();
n@701 807 };
nicholas@7 808
n@913 809 this.exportXMLDOM = function() {
n@913 810 var root = document.createElement('audioElement');
n@913 811 root.id = this.specification.id;
n@913 812 root.setAttribute('url',this.url);
n@913 813 root.appendChild(this.interfaceDOM.exportXMLDOM());
n@913 814 root.appendChild(this.commentDOM.exportXMLDOM());
n@913 815 root.appendChild(this.metric.exportXMLDOM());
n@913 816 return root;
n@913 817 };
n@673 818 }
n@673 819
n@673 820 function timer()
n@673 821 {
n@673 822 /* Timer object used in audioEngine to keep track of session timings
n@673 823 * Uses the timer of the web audio API, so sample resolution
n@673 824 */
n@673 825 this.testStarted = false;
n@673 826 this.testStartTime = 0;
n@673 827 this.testDuration = 0;
n@673 828 this.minimumTestTime = 0; // No minimum test time
n@673 829 this.startTest = function()
n@673 830 {
n@673 831 if (this.testStarted == false)
n@673 832 {
n@673 833 this.testStartTime = audioContext.currentTime;
n@673 834 this.testStarted = true;
n@673 835 this.updateTestTime();
n@676 836 audioEngineContext.metric.initialiseTest();
n@673 837 }
n@673 838 };
n@673 839 this.stopTest = function()
n@673 840 {
n@673 841 if (this.testStarted)
n@673 842 {
n@673 843 this.testDuration = this.getTestTime();
n@673 844 this.testStarted = false;
n@673 845 } else {
n@673 846 console.log('ERR: Test tried to end before beginning');
n@673 847 }
n@673 848 };
n@673 849 this.updateTestTime = function()
n@673 850 {
n@673 851 if (this.testStarted)
n@673 852 {
n@673 853 this.testDuration = audioContext.currentTime - this.testStartTime;
n@673 854 }
n@673 855 };
n@673 856 this.getTestTime = function()
n@673 857 {
n@673 858 this.updateTestTime();
n@673 859 return this.testDuration;
n@673 860 };
n@673 861 }
n@673 862
n@673 863 function sessionMetrics(engine)
n@673 864 {
n@673 865 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
n@673 866 */
n@673 867 this.engine = engine;
n@673 868 this.lastClicked = -1;
n@673 869 this.data = -1;
n@950 870 this.reset = function() {
n@950 871 this.lastClicked = -1;
n@950 872 this.data = -1;
n@950 873 };
n@676 874 this.initialiseTest = function(){};
n@673 875 }
n@673 876
n@932 877 function metricTracker(caller)
n@673 878 {
n@673 879 /* Custom object to track and collect metric data
n@673 880 * Used only inside the audioObjects object.
n@673 881 */
n@673 882
n@673 883 this.listenedTimer = 0;
n@673 884 this.listenStart = 0;
nicholas@947 885 this.listenHold = false;
n@675 886 this.initialPosition = -1;
n@673 887 this.movementTracker = [];
n@1013 888 this.listenTracker =[];
n@673 889 this.wasListenedTo = false;
n@673 890 this.wasMoved = false;
n@673 891 this.hasComments = false;
n@932 892 this.parent = caller;
n@673 893
n@673 894 this.initialised = function(position)
n@673 895 {
n@675 896 if (this.initialPosition == -1) {
n@675 897 this.initialPosition = position;
n@675 898 }
n@673 899 };
n@673 900
n@673 901 this.moved = function(time,position)
n@673 902 {
n@673 903 this.wasMoved = true;
n@673 904 this.movementTracker[this.movementTracker.length] = [time, position];
n@673 905 };
n@673 906
nicholas@967 907 this.startListening = function(time)
n@673 908 {
nicholas@947 909 if (this.listenHold == false)
n@673 910 {
n@673 911 this.wasListenedTo = true;
n@673 912 this.listenStart = time;
nicholas@947 913 this.listenHold = true;
n@1013 914
n@1013 915 var evnt = document.createElement('event');
n@1013 916 var testTime = document.createElement('testTime');
n@1013 917 testTime.setAttribute('start',time);
n@1013 918 var bufferTime = document.createElement('bufferTime');
n@1013 919 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
n@1013 920 evnt.appendChild(testTime);
n@1013 921 evnt.appendChild(bufferTime);
n@1013 922 this.listenTracker.push(evnt);
n@1013 923
n@932 924 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
n@932 925 }
n@932 926 };
nicholas@967 927
nicholas@967 928 this.stopListening = function(time)
nicholas@967 929 {
nicholas@967 930 if (this.listenHold == true)
nicholas@967 931 {
n@1013 932 var diff = time - this.listenStart;
n@1013 933 this.listenedTimer += (diff);
n@673 934 this.listenStart = 0;
nicholas@947 935 this.listenHold = false;
n@1013 936
n@1013 937 var evnt = this.listenTracker[this.listenTracker.length-1];
n@1013 938 var testTime = evnt.getElementsByTagName('testTime')[0];
n@1013 939 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
n@1013 940 testTime.setAttribute('stop',time);
n@1013 941 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
n@1013 942 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
n@673 943 }
n@673 944 };
n@907 945
n@907 946 this.exportXMLDOM = function() {
n@907 947 var root = document.createElement('metric');
n@907 948 if (audioEngineContext.metric.enableElementTimer) {
n@907 949 var mElementTimer = document.createElement('metricresult');
n@907 950 mElementTimer.setAttribute('name','enableElementTimer');
n@907 951 mElementTimer.textContent = this.listenedTimer;
n@907 952 root.appendChild(mElementTimer);
n@907 953 }
n@907 954 if (audioEngineContext.metric.enableElementTracker) {
n@907 955 var elementTrackerFull = document.createElement('metricResult');
n@907 956 elementTrackerFull.setAttribute('name','elementTrackerFull');
n@907 957 for (var k=0; k<this.movementTracker.length; k++)
n@907 958 {
n@907 959 var timePos = document.createElement('timePos');
n@907 960 timePos.id = k;
n@907 961 var time = document.createElement('time');
n@907 962 time.textContent = this.movementTracker[k][0];
n@907 963 var position = document.createElement('position');
n@907 964 position.textContent = this.movementTracker[k][1];
n@907 965 timePos.appendChild(time);
n@907 966 timePos.appendChild(position);
n@907 967 elementTrackerFull.appendChild(timePos);
n@907 968 }
n@907 969 root.appendChild(elementTrackerFull);
n@907 970 }
n@907 971 if (audioEngineContext.metric.enableElementListenTracker) {
n@907 972 var elementListenTracker = document.createElement('metricResult');
n@907 973 elementListenTracker.setAttribute('name','elementListenTracker');
n@907 974 for (var k=0; k<this.listenTracker.length; k++) {
n@907 975 elementListenTracker.appendChild(this.listenTracker[k]);
n@907 976 }
n@907 977 root.appendChild(elementListenTracker);
n@907 978 }
n@907 979 if (audioEngineContext.metric.enableElementInitialPosition) {
n@907 980 var elementInitial = document.createElement('metricResult');
n@907 981 elementInitial.setAttribute('name','elementInitialPosition');
n@907 982 elementInitial.textContent = this.initialPosition;
n@907 983 root.appendChild(elementInitial);
n@907 984 }
n@907 985 if (audioEngineContext.metric.enableFlagListenedTo) {
n@907 986 var flagListenedTo = document.createElement('metricResult');
n@907 987 flagListenedTo.setAttribute('name','elementFlagListenedTo');
n@907 988 flagListenedTo.textContent = this.wasListenedTo;
n@907 989 root.appendChild(flagListenedTo);
n@907 990 }
n@907 991 if (audioEngineContext.metric.enableFlagMoved) {
n@907 992 var flagMoved = document.createElement('metricResult');
n@907 993 flagMoved.setAttribute('name','elementFlagMoved');
n@907 994 flagMoved.textContent = this.wasMoved;
n@907 995 root.appendChild(flagMoved);
n@907 996 }
n@907 997 if (audioEngineContext.metric.enableFlagComments) {
n@907 998 var flagComments = document.createElement('metricResult');
n@907 999 flagComments.setAttribute('name','elementFlagComments');
n@907 1000 if (this.parent.commentDOM == null)
n@907 1001 {flag.textContent = 'false';}
n@907 1002 else if (this.parent.commentDOM.textContent.length == 0)
n@907 1003 {flag.textContent = 'false';}
n@907 1004 else
n@907 1005 {flag.textContet = 'true';}
n@907 1006 root.appendChild(flagComments);
n@907 1007 }
n@907 1008
n@907 1009 return root;
n@907 1010 };
n@678 1011 }
n@678 1012
n@678 1013 function randomiseOrder(input)
n@678 1014 {
n@678 1015 // This takes an array of information and randomises the order
n@678 1016 var N = input.length;
n@678 1017 var K = N;
n@678 1018 var holdArr = [];
n@678 1019 for (var n=0; n<N; n++)
n@678 1020 {
n@678 1021 // First pick a random number
n@678 1022 var r = Math.random();
n@678 1023 // Multiply and floor by the number of elements left
n@678 1024 r = Math.floor(r*input.length);
n@678 1025 // Pick out that element and delete from the array
n@678 1026 holdArr.push(input.splice(r,1)[0]);
n@678 1027 }
n@678 1028 return holdArr;
n@961 1029 }
n@961 1030
n@961 1031 function returnDateNode()
n@961 1032 {
n@961 1033 // Create an XML Node for the Date and Time a test was conducted
n@961 1034 // Structure is
n@961 1035 // <datetime>
n@961 1036 // <date year="##" month="##" day="##">DD/MM/YY</date>
n@961 1037 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
n@961 1038 // </datetime>
n@961 1039 var dateTime = new Date();
n@961 1040 var year = document.createAttribute('year');
n@961 1041 var month = document.createAttribute('month');
n@961 1042 var day = document.createAttribute('day');
n@961 1043 var hour = document.createAttribute('hour');
n@961 1044 var minute = document.createAttribute('minute');
n@961 1045 var secs = document.createAttribute('secs');
n@961 1046
n@961 1047 year.nodeValue = dateTime.getFullYear();
n@961 1048 month.nodeValue = dateTime.getMonth()+1;
n@961 1049 day.nodeValue = dateTime.getDate();
n@961 1050 hour.nodeValue = dateTime.getHours();
n@961 1051 minute.nodeValue = dateTime.getMinutes();
n@961 1052 secs.nodeValue = dateTime.getSeconds();
n@961 1053
n@961 1054 var hold = document.createElement("datetime");
n@961 1055 var date = document.createElement("date");
n@961 1056 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
n@961 1057 var time = document.createElement("time");
n@961 1058 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
n@961 1059
n@961 1060 date.setAttributeNode(year);
n@961 1061 date.setAttributeNode(month);
n@961 1062 date.setAttributeNode(day);
n@961 1063 time.setAttributeNode(hour);
n@961 1064 time.setAttributeNode(minute);
n@961 1065 time.setAttributeNode(secs);
n@961 1066
n@961 1067 hold.appendChild(date);
n@961 1068 hold.appendChild(time);
n@961 1069 return hold
n@961 1070
nicholas@934 1071 }
nicholas@934 1072
nicholas@934 1073 function testWaitIndicator() {
n@1007 1074 if (audioEngineContext.checkAllReady() == false) {
n@1007 1075 var hold = document.createElement("div");
n@1007 1076 hold.id = "testWaitIndicator";
n@1007 1077 hold.className = "indicator-box";
nicholas@915 1078 hold.style.zIndex = 3;
n@1007 1079 var span = document.createElement("span");
n@1007 1080 span.textContent = "Please wait! Elements still loading";
n@1007 1081 hold.appendChild(span);
nicholas@915 1082 var blank = document.createElement('div');
nicholas@915 1083 blank.className = 'testHalt';
nicholas@915 1084 blank.id = "testHaltBlank";
n@1007 1085 var body = document.getElementsByTagName('body')[0];
n@1007 1086 body.appendChild(hold);
nicholas@915 1087 body.appendChild(blank);
n@1007 1088 testWaitTimerIntervalHolder = setInterval(function(){
n@1007 1089 var ready = audioEngineContext.checkAllReady();
n@1007 1090 if (ready) {
n@1007 1091 var elem = document.getElementById('testWaitIndicator');
nicholas@915 1092 var blank = document.getElementById('testHaltBlank');
n@1007 1093 var body = document.getElementsByTagName('body')[0];
n@1007 1094 body.removeChild(elem);
nicholas@915 1095 body.removeChild(blank);
n@1007 1096 clearInterval(testWaitTimerIntervalHolder);
n@1007 1097 }
n@1007 1098 },500,false);
n@1007 1099 }
nicholas@934 1100 }
nicholas@934 1101
n@1007 1102 var testWaitTimerIntervalHolder = null;
n@910 1103
n@910 1104 function Specification() {
n@910 1105 // Handles the decoding of the project specification XML into a simple JavaScript Object.
n@910 1106
n@910 1107 this.interfaceType;
n@910 1108 this.projectReturn;
n@910 1109 this.randomiseOrder;
n@910 1110 this.collectMetrics;
n@910 1111 this.preTest;
n@910 1112 this.postTest;
n@910 1113 this.metrics =[];
n@910 1114
n@910 1115 this.audioHolders = [];
n@910 1116
n@910 1117 this.decode = function() {
n@910 1118 // projectXML - DOM Parsed document
n@910 1119 var setupNode = projectXML.getElementsByTagName('setup')[0];
n@910 1120 this.interfaceType = setupNode.getAttribute('interface');
n@910 1121 this.projectReturn = setupNode.getAttribute('projectReturn');
n@910 1122 if (setupNode.getAttribute('randomiseOrder') == "true") {
n@910 1123 this.randomiseOrder = true;
n@914 1124 } else {this.randomiseOrder = false;}
n@910 1125 if (setupNode.getAttribute('collectMetrics') == "true") {
n@910 1126 this.collectMetrics = true;
n@914 1127 } else {this.collectMetrics = false;}
n@910 1128 var metricCollection = setupNode.getElementsByTagName('Metric');
n@910 1129
n@911 1130 this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest'));
n@911 1131 this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest'));
n@910 1132
n@910 1133 if (metricCollection.length > 0) {
n@910 1134 metricCollection = metricCollection[0].getElementsByTagName('metricEnable');
n@910 1135 for (var i=0; i<metricCollection.length; i++) {
n@911 1136 this.metrics.push(new this.metricNode(metricCollection[i].textContent));
n@910 1137 }
n@910 1138 }
n@910 1139
n@910 1140 var audioHolders = projectXML.getElementsByTagName('audioHolder');
n@910 1141 for (var i=0; i<audioHolders.length; i++) {
n@910 1142 this.audioHolders.push(new this.audioHolderNode(this,audioHolders[i]));
n@910 1143 }
n@910 1144
n@910 1145 };
n@910 1146
n@910 1147 this.prepostNode = function(type,Collection) {
n@910 1148 this.type = type;
n@910 1149 this.options = [];
n@910 1150
n@910 1151 this.OptionNode = function(child) {
nicholas@918 1152
nicholas@918 1153 this.childOption = function(element) {
nicholas@918 1154 this.type = 'option';
nicholas@918 1155 this.id = element.id;
nicholas@919 1156 this.name = element.getAttribute('name');
nicholas@918 1157 this.text = element.textContent;
n@1024 1158 };
nicholas@918 1159
n@910 1160 this.type = child.nodeName;
n@910 1161 if (child.nodeName == "question") {
n@910 1162 this.id = child.id;
n@910 1163 this.mandatory;
n@910 1164 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;}
n@910 1165 else {this.mandatory = false;}
n@910 1166 this.question = child.textContent;
n@1024 1167 if (child.getAttribute('boxsize') == null) {
n@1024 1168 this.boxsize = 'normal';
n@1024 1169 } else {
n@1024 1170 this.boxsize = child.getAttribute('boxsize');
n@1024 1171 }
n@910 1172 } else if (child.nodeName == "statement") {
n@911 1173 this.statement = child.textContent;
nicholas@919 1174 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") {
nicholas@918 1175 var element = child.firstElementChild;
nicholas@919 1176 this.id = child.id;
nicholas@918 1177 if (element == null) {
nicholas@919 1178 console.log('Malformed' +child.nodeName+ 'entry');
nicholas@919 1179 this.statement = 'Malformed' +child.nodeName+ 'entry';
nicholas@918 1180 this.type = 'statement';
nicholas@918 1181 } else {
nicholas@918 1182 this.options = [];
nicholas@918 1183 while (element != null) {
nicholas@918 1184 if (element.nodeName == 'statement' && this.statement == undefined){
nicholas@918 1185 this.statement = element.textContent;
nicholas@918 1186 } else if (element.nodeName == 'option') {
nicholas@918 1187 this.options.push(new this.childOption(element));
nicholas@918 1188 }
nicholas@918 1189 element = element.nextElementSibling;
nicholas@918 1190 }
nicholas@918 1191 }
n@903 1192 } else if (child.nodeName == "number") {
n@903 1193 this.statement = child.textContent;
n@903 1194 this.id = child.id;
n@903 1195 this.min = child.getAttribute('min');
n@903 1196 this.max = child.getAttribute('max');
n@903 1197 this.step = child.getAttribute('step');
n@910 1198 }
n@910 1199 };
n@910 1200
n@910 1201 // On construction:
n@910 1202 if (Collection.length != 0) {
n@910 1203 Collection = Collection[0];
nicholas@916 1204 if (Collection.childElementCount != 0) {
nicholas@916 1205 var child = Collection.firstElementChild;
n@910 1206 this.options.push(new this.OptionNode(child));
nicholas@916 1207 while (child.nextElementSibling != null) {
nicholas@916 1208 child = child.nextElementSibling;
nicholas@916 1209 this.options.push(new this.OptionNode(child));
nicholas@916 1210 }
n@910 1211 }
n@910 1212 }
n@910 1213 };
n@910 1214
n@910 1215 this.metricNode = function(name) {
n@910 1216 this.enabled = name;
n@910 1217 };
n@910 1218
n@910 1219 this.audioHolderNode = function(parent,xml) {
n@911 1220 this.type = 'audioHolder';
n@910 1221 this.interfaceNode = function(DOM) {
n@910 1222 var title = DOM.getElementsByTagName('title');
n@910 1223 if (title.length == 0) {this.title = null;}
n@910 1224 else {this.title = title[0].textContent;}
n@910 1225
n@910 1226 var scale = DOM.getElementsByTagName('scale');
n@910 1227 this.scale = [];
n@910 1228 for (var i=0; i<scale.length; i++) {
n@910 1229 var arr = [null, null];
n@910 1230 arr[0] = scale[i].getAttribute('position');
n@910 1231 arr[1] = scale[i].textContent;
n@910 1232 this.scale.push(arr);
n@910 1233 }
n@910 1234 };
n@910 1235
n@912 1236 this.audioElementNode = function(parent,xml) {
n@910 1237 this.url = xml.getAttribute('url');
n@910 1238 this.id = xml.id;
n@912 1239 this.parent = parent;
n@910 1240 };
n@910 1241
n@910 1242 this.commentQuestionNode = function(xml) {
n@1026 1243 this.childOption = function(element) {
n@1026 1244 this.type = 'option';
n@1026 1245 this.name = element.getAttribute('name');
n@1026 1246 this.text = element.textContent;
n@1026 1247 };
n@910 1248 this.id = xml.id;
n@910 1249 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;}
n@910 1250 else {this.mandatory = false;}
n@1026 1251 this.type = xml.getAttribute('type');
n@1026 1252 if (this.type == undefined) {this.type = 'text';}
n@1026 1253 switch (this.type) {
n@1026 1254 case 'text':
n@1026 1255 this.question = xml.textContent;
n@1026 1256 break;
n@1026 1257 case 'radio':
n@1026 1258 var child = xml.firstElementChild;
n@1026 1259 this.options = [];
n@1026 1260 while (child != undefined) {
n@1026 1261 if (child.nodeName == 'statement' && this.statement == undefined) {
n@1026 1262 this.statement = child.textContent;
n@1026 1263 } else if (child.nodeName == 'option') {
n@1026 1264 this.options.push(new this.childOption(child));
n@1026 1265 }
n@1026 1266 child = child.nextElementSibling;
n@1026 1267 }
n@902 1268 break;
n@902 1269 case 'checkbox':
n@902 1270 var child = xml.firstElementChild;
n@902 1271 this.options = [];
n@902 1272 while (child != undefined) {
n@902 1273 if (child.nodeName == 'statement' && this.statement == undefined) {
n@902 1274 this.statement = child.textContent;
n@902 1275 } else if (child.nodeName == 'option') {
n@902 1276 this.options.push(new this.childOption(child));
n@902 1277 }
n@902 1278 child = child.nextElementSibling;
n@902 1279 }
n@902 1280 break;
n@1026 1281 }
n@910 1282 };
n@910 1283
n@910 1284 this.id = xml.id;
n@910 1285 this.hostURL = xml.getAttribute('hostURL');
n@910 1286 this.sampleRate = xml.getAttribute('sampleRate');
n@910 1287 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
n@910 1288 else {this.randomiseOrder = false;}
n@910 1289 this.repeatCount = xml.getAttribute('repeatCount');
n@910 1290 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
n@910 1291 else {this.loop == false;}
n@910 1292 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
n@910 1293 else {this.elementComments = false;}
n@910 1294
n@911 1295 this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
n@911 1296 this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest'));
n@910 1297
n@910 1298 this.interfaces = [];
n@910 1299 var interfaceDOM = xml.getElementsByTagName('interface');
n@910 1300 for (var i=0; i<interfaceDOM.length; i++) {
n@910 1301 this.interfaces.push(new this.interfaceNode(interfaceDOM[i]));
n@910 1302 }
n@910 1303
n@910 1304 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
n@910 1305 if (this.commentBoxPrefix.length != 0) {
n@910 1306 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
n@910 1307 } else {
n@910 1308 this.commentBoxPrefix = "Comment on track";
n@910 1309 }
n@910 1310
n@910 1311 this.audioElements =[];
n@910 1312 var audioElementsDOM = xml.getElementsByTagName('audioElements');
n@910 1313 for (var i=0; i<audioElementsDOM.length; i++) {
n@912 1314 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
n@910 1315 }
n@910 1316
n@910 1317 this.commentQuestions = [];
n@910 1318 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
n@910 1319 for (var i=0; i<commentQuestionsDOM.length; i++) {
n@910 1320 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
n@910 1321 }
n@910 1322 };
n@910 1323 }
n@910 1324
n@912 1325 function Interface(specificationObject) {
n@910 1326 // This handles the bindings between the interface and the audioEngineContext;
n@912 1327 this.specification = specificationObject;
n@912 1328 this.insertPoint = document.getElementById("topLevelBody");
n@910 1329
n@912 1330 // Bounded by interface!!
n@912 1331 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
n@912 1332 // For example, APE returns the slider position normalised in a <value> tag.
n@912 1333 this.interfaceObjects = [];
n@912 1334 this.interfaceObject = function(){};
n@912 1335
n@912 1336 this.commentBoxes = [];
n@1026 1337 this.elementCommentBox = function(audioObject) {
n@912 1338 var element = audioObject.specification;
n@913 1339 this.audioObject = audioObject;
n@912 1340 this.id = audioObject.id;
n@912 1341 var audioHolderObject = audioObject.specification.parent;
n@912 1342 // Create document objects to hold the comment boxes
n@912 1343 this.trackComment = document.createElement('div');
n@912 1344 this.trackComment.className = 'comment-div';
n@912 1345 this.trackComment.id = 'comment-div-'+audioObject.id;
n@912 1346 // Create a string next to each comment asking for a comment
n@913 1347 this.trackString = document.createElement('span');
n@913 1348 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id;
n@912 1349 // Create the HTML5 comment box 'textarea'
n@913 1350 this.trackCommentBox = document.createElement('textarea');
n@913 1351 this.trackCommentBox.rows = '4';
n@913 1352 this.trackCommentBox.cols = '100';
n@913 1353 this.trackCommentBox.name = 'trackComment'+audioObject.id;
n@913 1354 this.trackCommentBox.className = 'trackComment';
n@912 1355 var br = document.createElement('br');
n@912 1356 // Add to the holder.
n@913 1357 this.trackComment.appendChild(this.trackString);
n@912 1358 this.trackComment.appendChild(br);
n@913 1359 this.trackComment.appendChild(this.trackCommentBox);
n@913 1360
n@913 1361 this.exportXMLDOM = function() {
n@913 1362 var root = document.createElement('comment');
n@913 1363 if (this.audioObject.specification.parent.elementComments) {
n@913 1364 var question = document.createElement('question');
n@913 1365 question.textContent = this.trackString.textContent;
n@913 1366 var response = document.createElement('response');
n@913 1367 response.textContent = this.trackCommentBox.value;
n@913 1368 root.appendChild(question);
n@913 1369 root.appendChild(response);
n@913 1370 }
n@913 1371 return root;
n@913 1372 };
n@912 1373 };
n@912 1374
n@1026 1375 this.commentQuestions = [];
n@1026 1376
n@1026 1377 this.commentBox = function(commentQuestion) {
n@1026 1378 this.specification = commentQuestion;
n@1026 1379 // Create document objects to hold the comment boxes
n@1026 1380 this.holder = document.createElement('div');
n@1026 1381 this.holder.className = 'comment-div';
n@1026 1382 // Create a string next to each comment asking for a comment
n@1026 1383 this.string = document.createElement('span');
n@1026 1384 this.string.innerHTML = commentQuestion.question;
n@1026 1385 // Create the HTML5 comment box 'textarea'
n@1026 1386 this.textArea = document.createElement('textarea');
n@1026 1387 this.textArea.rows = '4';
n@1026 1388 this.textArea.cols = '100';
n@1026 1389 this.textArea.className = 'trackComment';
n@1026 1390 var br = document.createElement('br');
n@1026 1391 // Add to the holder.
n@1026 1392 this.holder.appendChild(this.string);
n@1026 1393 this.holder.appendChild(br);
n@1026 1394 this.holder.appendChild(this.textArea);
n@1026 1395
n@1026 1396 this.exportXMLDOM = function() {
n@1026 1397 var root = document.createElement('comment');
n@1026 1398 root.id = this.specification.id;
n@1026 1399 root.setAttribute('type',this.specification.type);
n@1026 1400 root.textContent = this.textArea.value;
n@1026 1401 return root;
n@1026 1402 };
n@1026 1403 };
n@1026 1404
n@1026 1405 this.radioBox = function(commentQuestion) {
n@1026 1406 this.specification = commentQuestion;
n@1026 1407 // Create document objects to hold the comment boxes
n@1026 1408 this.holder = document.createElement('div');
n@1026 1409 this.holder.className = 'comment-div';
n@1026 1410 // Create a string next to each comment asking for a comment
n@1026 1411 this.string = document.createElement('span');
n@1026 1412 this.string.innerHTML = commentQuestion.statement;
n@1026 1413 var br = document.createElement('br');
n@1026 1414 // Add to the holder.
n@1026 1415 this.holder.appendChild(this.string);
n@1026 1416 this.holder.appendChild(br);
n@1026 1417 this.options = [];
n@1026 1418 this.inputs = document.createElement('div');
n@1026 1419 this.span = document.createElement('div');
n@1026 1420 this.inputs.align = 'center';
n@1026 1421 this.inputs.style.marginLeft = '12px';
n@1026 1422 this.span.style.marginLeft = '12px';
n@1026 1423 this.span.align = 'center';
n@1026 1424 this.span.style.marginTop = '15px';
n@1026 1425
n@1026 1426 var optCount = commentQuestion.options.length;
n@1026 1427 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px';
n@1026 1428 console.log(spanMargin);
n@1026 1429 for (var i=0; i<optCount; i++)
n@1026 1430 {
n@1026 1431 var div = document.createElement('div');
n@1026 1432 div.style.width = '100px';
n@1026 1433 div.style.float = 'left';
n@1026 1434 div.style.marginRight = spanMargin;
n@1026 1435 div.style.marginLeft = spanMargin;
n@1026 1436 var input = document.createElement('input');
n@1026 1437 input.type = 'radio';
n@1026 1438 input.name = commentQuestion.id;
n@1026 1439 input.setAttribute('setvalue',commentQuestion.options[i].name);
n@1026 1440 input.className = 'comment-radio';
n@1026 1441 div.appendChild(input);
n@1026 1442 this.inputs.appendChild(div);
n@1026 1443
n@1026 1444
n@1026 1445 div = document.createElement('div');
n@1026 1446 div.style.width = '100px';
n@1026 1447 div.style.float = 'left';
n@1026 1448 div.style.marginRight = spanMargin;
n@1026 1449 div.style.marginLeft = spanMargin;
n@1026 1450 div.align = 'center';
n@1026 1451 var span = document.createElement('span');
n@1026 1452 span.textContent = commentQuestion.options[i].text;
n@1026 1453 span.className = 'comment-radio-span';
n@1026 1454 div.appendChild(span);
n@1026 1455 this.span.appendChild(div);
n@1026 1456 this.options.push(input);
n@1026 1457 }
n@1026 1458 this.holder.appendChild(this.span);
n@1026 1459 this.holder.appendChild(this.inputs);
n@1026 1460
n@1026 1461 this.exportXMLDOM = function() {
n@1026 1462 var root = document.createElement('comment');
n@1026 1463 root.id = this.specification.id;
n@1026 1464 root.setAttribute('type',this.specification.type);
n@1026 1465 var question = document.createElement('question');
n@1026 1466 question.textContent = this.string.textContent;
n@1026 1467 var response = document.createElement('response');
n@1026 1468 var i=0;
n@1026 1469 while(this.options[i].checked == false) {
n@1026 1470 i++;
n@1026 1471 if (i >= this.options.length) {
n@1026 1472 break;
n@1026 1473 }
n@1026 1474 }
n@1026 1475 if (i >= this.options.length) {
n@1026 1476 response.textContent = 'null';
n@1026 1477 } else {
n@1026 1478 response.textContent = this.options[i].getAttribute('setvalue');
n@1026 1479 response.setAttribute('number',i);
n@1026 1480 }
n@902 1481 console.log('Comment: '+question.textContent);
n@902 1482 console.log('Response: '+response.textContent);
n@1026 1483 root.appendChild(question);
n@1026 1484 root.appendChild(response);
n@1026 1485 return root;
n@1026 1486 };
n@1026 1487 };
n@1026 1488
n@902 1489 this.checkboxBox = function(commentQuestion) {
n@902 1490 this.specification = commentQuestion;
n@902 1491 // Create document objects to hold the comment boxes
n@902 1492 this.holder = document.createElement('div');
n@902 1493 this.holder.className = 'comment-div';
n@902 1494 // Create a string next to each comment asking for a comment
n@902 1495 this.string = document.createElement('span');
n@902 1496 this.string.innerHTML = commentQuestion.statement;
n@902 1497 var br = document.createElement('br');
n@902 1498 // Add to the holder.
n@902 1499 this.holder.appendChild(this.string);
n@902 1500 this.holder.appendChild(br);
n@902 1501 this.options = [];
n@902 1502 this.inputs = document.createElement('div');
n@902 1503 this.span = document.createElement('div');
n@902 1504 this.inputs.align = 'center';
n@902 1505 this.inputs.style.marginLeft = '12px';
n@902 1506 this.span.style.marginLeft = '12px';
n@902 1507 this.span.align = 'center';
n@902 1508 this.span.style.marginTop = '15px';
n@902 1509
n@902 1510 var optCount = commentQuestion.options.length;
n@902 1511 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px';
n@902 1512 console.log(spanMargin);
n@902 1513 for (var i=0; i<optCount; i++)
n@902 1514 {
n@902 1515 var div = document.createElement('div');
n@902 1516 div.style.width = '100px';
n@902 1517 div.style.float = 'left';
n@902 1518 div.style.marginRight = spanMargin;
n@902 1519 div.style.marginLeft = spanMargin;
n@902 1520 var input = document.createElement('input');
n@902 1521 input.type = 'checkbox';
n@902 1522 input.name = commentQuestion.id;
n@902 1523 input.setAttribute('setvalue',commentQuestion.options[i].name);
n@902 1524 input.className = 'comment-radio';
n@902 1525 div.appendChild(input);
n@902 1526 this.inputs.appendChild(div);
n@902 1527
n@902 1528
n@902 1529 div = document.createElement('div');
n@902 1530 div.style.width = '100px';
n@902 1531 div.style.float = 'left';
n@902 1532 div.style.marginRight = spanMargin;
n@902 1533 div.style.marginLeft = spanMargin;
n@902 1534 div.align = 'center';
n@902 1535 var span = document.createElement('span');
n@902 1536 span.textContent = commentQuestion.options[i].text;
n@902 1537 span.className = 'comment-radio-span';
n@902 1538 div.appendChild(span);
n@902 1539 this.span.appendChild(div);
n@902 1540 this.options.push(input);
n@902 1541 }
n@902 1542 this.holder.appendChild(this.span);
n@902 1543 this.holder.appendChild(this.inputs);
n@902 1544
n@902 1545 this.exportXMLDOM = function() {
n@902 1546 var root = document.createElement('comment');
n@902 1547 root.id = this.specification.id;
n@902 1548 root.setAttribute('type',this.specification.type);
n@902 1549 var question = document.createElement('question');
n@902 1550 question.textContent = this.string.textContent;
n@902 1551 root.appendChild(question);
n@902 1552 console.log('Comment: '+question.textContent);
n@902 1553 for (var i=0; i<this.options.length; i++) {
n@902 1554 var response = document.createElement('response');
n@902 1555 response.textContent = this.options[i].checked;
n@902 1556 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
n@902 1557 root.appendChild(response);
n@902 1558 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
n@902 1559 }
n@902 1560 return root;
n@902 1561 };
n@902 1562 };
n@1026 1563
n@912 1564 this.createCommentBox = function(audioObject) {
n@1026 1565 var node = new this.elementCommentBox(audioObject);
n@912 1566 this.commentBoxes.push(node);
n@912 1567 audioObject.commentDOM = node;
n@912 1568 return node;
n@912 1569 };
n@912 1570
n@912 1571 this.sortCommentBoxes = function() {
n@912 1572 var holder = [];
n@912 1573 while (this.commentBoxes.length > 0) {
n@912 1574 var node = this.commentBoxes.pop(0);
n@912 1575 holder[node.id] = node;
n@912 1576 }
n@912 1577 this.commentBoxes = holder;
n@912 1578 };
n@912 1579
n@912 1580 this.showCommentBoxes = function(inject, sort) {
n@912 1581 if (sort) {interfaceContext.sortCommentBoxes();}
n@912 1582 for (var i=0; i<interfaceContext.commentBoxes.length; i++) {
n@912 1583 inject.appendChild(this.commentBoxes[i].trackComment);
n@912 1584 }
n@912 1585 };
n@1026 1586
n@1026 1587 this.createCommentQuestion = function(element) {
n@1026 1588 var node;
n@1026 1589 if (element.type == 'text') {
n@1026 1590 node = new this.commentBox(element);
n@1026 1591 } else if (element.type == 'radio') {
n@1026 1592 node = new this.radioBox(element);
n@902 1593 } else if (element.type == 'checkbox') {
n@902 1594 node = new this.checkboxBox(element);
n@1026 1595 }
n@1026 1596 this.commentQuestions.push(node);
n@1026 1597 return node;
n@1026 1598 };
n@910 1599 }
n@910 1600