annotate core.js @ 895:e2e39f867db3

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