nickjillings@1682: /** nickjillings@1682: * core.js nickjillings@1682: * nickjillings@1682: * Main script to run, calls all other core functions and manages loading/store to backend. nickjillings@1682: * Also contains all global variables. nickjillings@1682: */ nickjillings@1682: nickjillings@1682: /* create the web audio API context and store in audioContext*/ nickjillings@1643: var audioContext; // Hold the browser web audio API nickjillings@1643: var projectXML; // Hold the parsed setup XML nickjillings@1581: var specification; nickjillings@1582: var interfaceContext; nickjillings@1622: var popup; // Hold the interfacePopup object nickjillings@1634: var testState; nickjillings@1655: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order nickjillings@1643: var audioEngineContext; // The custome AudioEngine object nickjillings@1643: var projectReturn; // Hold the URL for the return nickjillings@2013: nickjillings@1642: nickjillings@1667: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it nickjillings@1667: AudioBufferSourceNode.prototype.owner = undefined; nickjillings@1682: nickjillings@1682: window.onload = function() { nickjillings@1682: // Function called once the browser has loaded all files. nickjillings@1682: // This should perform any initial commands such as structure / loading documents nickjillings@1682: nickjillings@1682: // Create a web audio API context nickjillings@1701: // Fixed for cross-browser support nickjillings@1701: var AudioContext = window.AudioContext || window.webkitAudioContext; nickjillings@1688: audioContext = new AudioContext; nickjillings@1682: nickjillings@1634: // Create test state nickjillings@1634: testState = new stateMachine(); nickjillings@1634: nickjillings@1682: // Create the audio engine object nickjillings@1682: audioEngineContext = new AudioEngine(); nickjillings@1622: nickjillings@1622: // Create the popup interface object nickjillings@1622: popup = new interfacePopup(); nickjillings@1581: nickjillings@1581: // Create the specification object nickjillings@1581: specification = new Specification(); nickjillings@1582: nickjillings@1582: // Create the interface object nickjillings@1582: interfaceContext = new Interface(specification); nickjillings@1697: }; nickjillings@1682: nickjillings@1622: function interfacePopup() { nickjillings@1622: // Creates an object to manage the popup nickjillings@1622: this.popup = null; nickjillings@1622: this.popupContent = null; nickjillings@1622: this.popupButton = null; nickjillings@1622: this.popupOptions = null; nickjillings@1622: this.currentIndex = null; nickjillings@1622: this.responses = null; nickjillings@1581: nickjillings@1622: this.createPopup = function(){ nickjillings@1622: // Create popup window interface nickjillings@1622: var insertPoint = document.getElementById("topLevelBody"); nickjillings@1622: var blank = document.createElement('div'); nickjillings@1622: blank.className = 'testHalt'; nickjillings@1622: nickjillings@1622: this.popup = document.createElement('div'); nickjillings@1622: this.popup.id = 'popupHolder'; nickjillings@1622: this.popup.className = 'popupHolder'; nickjillings@1622: this.popup.style.position = 'absolute'; nickjillings@1622: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; nickjillings@1622: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; nickjillings@1622: nickjillings@1622: this.popupContent = document.createElement('div'); nickjillings@1622: this.popupContent.id = 'popupContent'; nickjillings@1622: this.popupContent.style.marginTop = '25px'; nickjillings@1622: this.popupContent.align = 'center'; nickjillings@1622: this.popup.appendChild(this.popupContent); nickjillings@1622: nickjillings@1622: this.popupButton = document.createElement('button'); nickjillings@1622: this.popupButton.className = 'popupButton'; nickjillings@1622: this.popupButton.innerHTML = 'Next'; nickjillings@1622: this.popupButton.onclick = function(){popup.buttonClicked();}; nickjillings@1581: this.popup.style.zIndex = -1; nickjillings@1581: this.popup.style.visibility = 'hidden'; nickjillings@1581: blank.style.zIndex = -2; nickjillings@1581: blank.style.visibility = 'hidden'; nickjillings@1622: insertPoint.appendChild(this.popup); nickjillings@1622: insertPoint.appendChild(blank); nickjillings@1622: }; nickjillings@1621: nickjillings@1622: this.showPopup = function(){ nickjillings@1581: if (this.popup == null) { nickjillings@1622: this.createPopup(); nickjillings@1622: } nickjillings@1622: this.popup.style.zIndex = 3; nickjillings@1622: this.popup.style.visibility = 'visible'; nickjillings@1622: var blank = document.getElementsByClassName('testHalt')[0]; nickjillings@1622: blank.style.zIndex = 2; nickjillings@1622: blank.style.visibility = 'visible'; nickjillings@1622: }; nickjillings@1622: nickjillings@1622: this.hidePopup = function(){ nickjillings@1622: this.popup.style.zIndex = -1; nickjillings@1622: this.popup.style.visibility = 'hidden'; nickjillings@1622: var blank = document.getElementsByClassName('testHalt')[0]; nickjillings@1622: blank.style.zIndex = -2; nickjillings@1622: blank.style.visibility = 'hidden'; nickjillings@1622: }; nickjillings@1622: nickjillings@1622: this.postNode = function() { nickjillings@1622: // This will take the node from the popupOptions and display it nickjillings@1622: var node = this.popupOptions[this.currentIndex]; nickjillings@1622: this.popupContent.innerHTML = null; nickjillings@1581: if (node.type == 'statement') { nickjillings@1622: var span = document.createElement('span'); nickjillings@1581: span.textContent = node.statement; nickjillings@1622: this.popupContent.appendChild(span); nickjillings@1581: } else if (node.type == 'question') { nickjillings@1622: var span = document.createElement('span'); nickjillings@1581: span.textContent = node.question; nickjillings@1622: var textArea = document.createElement('textarea'); nickjillings@2030: switch (node.boxsize) { nickjillings@2030: case 'small': nickjillings@2030: textArea.cols = "20"; nickjillings@2030: textArea.rows = "1"; nickjillings@2030: break; nickjillings@2030: case 'normal': nickjillings@2030: textArea.cols = "30"; nickjillings@2030: textArea.rows = "2"; nickjillings@2030: break; nickjillings@2030: case 'large': nickjillings@2030: textArea.cols = "40"; nickjillings@2030: textArea.rows = "5"; nickjillings@2030: break; nickjillings@2030: case 'huge': nickjillings@2030: textArea.cols = "50"; nickjillings@2030: textArea.rows = "10"; nickjillings@2030: break; nickjillings@2030: } nickjillings@1622: var br = document.createElement('br'); nickjillings@1622: this.popupContent.appendChild(span); nickjillings@1622: this.popupContent.appendChild(br); nickjillings@1622: this.popupContent.appendChild(textArea); nickjillings@2015: this.popupContent.childNodes[2].focus(); nickjillings@1588: } else if (node.type == 'checkbox') { nickjillings@1588: var span = document.createElement('span'); nickjillings@1588: span.textContent = node.statement; nickjillings@1588: this.popupContent.appendChild(span); nickjillings@1588: var optHold = document.createElement('div'); nickjillings@1588: optHold.id = 'option-holder'; nickjillings@1588: optHold.align = 'left'; nickjillings@1588: for (var i=0; i 0) { nickjillings@1581: if (node.type == 'pretest') { nickjillings@1622: this.responses = document.createElement('PreTest'); nickjillings@1581: } else if (node.type == 'posttest') { nickjillings@1622: this.responses = document.createElement('PostTest'); nickjillings@1622: } else { nickjillings@1622: console.log ('WARNING - popup node neither pre or post!'); nickjillings@1622: this.responses = document.createElement('responses'); nickjillings@1622: } nickjillings@1622: this.currentIndex = 0; nickjillings@1622: this.showPopup(); nickjillings@1622: this.postNode(); nickjillings@1581: } else { nickjillings@1581: advanceState(); nickjillings@1622: } nickjillings@2015: }; nickjillings@1622: nickjillings@1622: this.buttonClicked = function() { nickjillings@1622: // Each time the popup button is clicked! nickjillings@1622: var node = this.popupOptions[this.currentIndex]; nickjillings@1581: if (node.type == 'question') { nickjillings@1622: // Must extract the question data nickjillings@1622: var textArea = $(popup.popupContent).find('textarea')[0]; nickjillings@1581: if (node.mandatory == true && textArea.value.length == 0) { nickjillings@1622: alert('This question is mandatory'); nickjillings@1622: return; nickjillings@1622: } else { nickjillings@1622: // Save the text content nickjillings@1622: var hold = document.createElement('comment'); nickjillings@1581: hold.id = node.id; nickjillings@1622: hold.innerHTML = textArea.value; nickjillings@1623: console.log("Question: "+ node.textContent); nickjillings@1623: console.log("Question Response: "+ textArea.value); nickjillings@1622: this.responses.appendChild(hold); nickjillings@1622: } nickjillings@1588: } else if (node.type == 'checkbox') { nickjillings@1588: // Must extract checkbox data nickjillings@1588: var optHold = document.getElementById('option-holder'); nickjillings@1588: var hold = document.createElement('checkbox'); nickjillings@1588: console.log("Checkbox: "+ node.statement); nickjillings@1589: hold.id = node.id; nickjillings@1588: for (var i=0; i 0) { nickjillings@1634: if(this.stateIndex != null) { nickjillings@1634: console.log('NOTE - State already initialise'); nickjillings@1634: } nickjillings@1634: this.stateIndex = -1; nickjillings@1634: var that = this; nickjillings@1634: for (var id=0; id= this.stateMap.length) { nickjillings@1634: console.log('Test Completed'); nickjillings@1582: createProjectSave(specification.projectReturn); nickjillings@1634: } else { nickjillings@1634: this.currentStateMap = this.stateMap[this.stateIndex]; nickjillings@1581: if (this.currentStateMap.type == "audioHolder") { nickjillings@1634: console.log('Loading test page'); nickjillings@1634: loadTest(this.currentStateMap); nickjillings@1634: this.initialiseInnerState(this.currentStateMap); nickjillings@1581: } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") { nickjillings@1581: if (this.currentStateMap.options.length >= 1) { nickjillings@1634: popup.initState(this.currentStateMap); nickjillings@1634: } else { nickjillings@1634: this.advanceState(); nickjillings@1634: } nickjillings@1634: } else { nickjillings@1634: this.advanceState(); nickjillings@1634: } nickjillings@1634: } nickjillings@1634: } else { nickjillings@1634: this.advanceInnerState(); nickjillings@1634: } nickjillings@1634: }; nickjillings@1634: nickjillings@1634: this.testPageCompleted = function(store, testXML, testId) { nickjillings@1634: // Function called each time a test page has been completed nickjillings@1634: // Can be used to over-rule default behaviour nickjillings@1634: nickjillings@1581: pageXMLSave(store, testXML); nickjillings@1576: }; nickjillings@1634: nickjillings@1581: this.initialiseInnerState = function(node) { nickjillings@1634: // Parses the received testXML for pre and post test options nickjillings@1634: this.currentStateMap = []; nickjillings@1581: var preTest = node.preTest; nickjillings@1581: var postTest = node.postTest; nickjillings@1634: if (preTest == undefined) {preTest = document.createElement("preTest");} nickjillings@1634: if (postTest == undefined){postTest= document.createElement("postTest");} nickjillings@1634: this.currentStateMap.push(preTest); nickjillings@1581: this.currentStateMap.push(node); nickjillings@1634: this.currentStateMap.push(postTest); nickjillings@1634: this.currentIndex = -1; nickjillings@1634: this.advanceInnerState(); nickjillings@1576: }; nickjillings@1634: nickjillings@1634: this.advanceInnerState = function() { nickjillings@1634: this.currentIndex++; nickjillings@1634: if (this.currentIndex >= this.currentStateMap.length) { nickjillings@1634: this.currentIndex = null; nickjillings@1634: this.currentStateMap = this.stateMap[this.stateIndex]; nickjillings@1634: this.advanceState(); nickjillings@1634: } else { nickjillings@1581: if (this.currentStateMap[this.currentIndex].type == "audioHolder") { nickjillings@1634: console.log("Loading test page"+this.currentTestId); nickjillings@1581: } else if (this.currentStateMap[this.currentIndex].type == "pretest") { nickjillings@1634: popup.initState(this.currentStateMap[this.currentIndex]); nickjillings@1581: } else if (this.currentStateMap[this.currentIndex].type == "posttest") { nickjillings@1634: popup.initState(this.currentStateMap[this.currentIndex]); nickjillings@1634: } else { nickjillings@1634: this.advanceInnerState(); nickjillings@1634: } nickjillings@1622: } nickjillings@1576: }; nickjillings@1634: nickjillings@1634: this.previousState = function(){}; nickjillings@1621: } nickjillings@1621: nickjillings@1622: function testEnded(testId) nickjillings@1621: { nickjillings@1622: pageXMLSave(testId); nickjillings@1622: if (testXMLSetups.length-1 > testId) nickjillings@1622: { nickjillings@1622: // Yes we have another test to perform nickjillings@1622: testId = (Number(testId)+1); nickjillings@1622: currentState = 'testRun-'+testId; nickjillings@1622: loadTest(testId); nickjillings@1622: } else { nickjillings@1622: console.log('Testing Completed!'); nickjillings@1622: currentState = 'postTest'; nickjillings@1622: // Check for any post tests nickjillings@1622: var xmlSetup = projectXML.find('setup'); nickjillings@1622: var postTest = xmlSetup.find('PostTest')[0]; nickjillings@1622: popup.initState(postTest); nickjillings@1622: } nickjillings@1621: } nickjillings@1621: nickjillings@1682: function loadProjectSpec(url) { nickjillings@1682: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data nickjillings@1682: // If url is null, request client to upload project XML document nickjillings@1683: var r = new XMLHttpRequest(); nickjillings@1683: r.open('GET',url,true); nickjillings@1683: r.onload = function() { nickjillings@1683: loadProjectSpecCallback(r.response); nickjillings@1697: }; nickjillings@1683: r.send(); nickjillings@1697: }; nickjillings@1683: nickjillings@1683: function loadProjectSpecCallback(response) { nickjillings@1683: // Function called after asynchronous download of XML project specification nickjillings@1580: //var decode = $.parseXML(response); nickjillings@1580: //projectXML = $(decode); nickjillings@1683: nickjillings@1580: var parse = new DOMParser(); nickjillings@1580: projectXML = parse.parseFromString(response,'text/xml'); nickjillings@1575: nickjillings@1581: // Build the specification nickjillings@1581: specification.decode(); nickjillings@1576: nickjillings@1581: testState.stateMap.push(specification.preTest); nickjillings@1576: nickjillings@1576: // New check if we need to randomise the test order nickjillings@1581: if (specification.randomiseOrder) nickjillings@1581: { nickjillings@1581: specification.audioHolders = randomiseOrder(specification.audioHolders); nickjillings@1576: } nickjillings@1576: nickjillings@1581: $(specification.audioHolders).each(function(index,elem){ nickjillings@1576: testState.stateMap.push(elem); nickjillings@1576: }); nickjillings@1576: nickjillings@1581: testState.stateMap.push(specification.postTest); nickjillings@1576: nickjillings@1576: // Obtain the metrics enabled nickjillings@1581: $(specification.metrics).each(function(index,node){ nickjillings@1576: var enabled = node.textContent; nickjillings@1581: switch(node.enabled) nickjillings@1576: { nickjillings@1576: case 'testTimer': nickjillings@1576: sessionMetrics.prototype.enableTestTimer = true; nickjillings@1576: break; nickjillings@1576: case 'elementTimer': nickjillings@1576: sessionMetrics.prototype.enableElementTimer = true; nickjillings@1576: break; nickjillings@1576: case 'elementTracker': nickjillings@1576: sessionMetrics.prototype.enableElementTracker = true; nickjillings@1576: break; nickjillings@1576: case 'elementListenTracker': nickjillings@1576: sessionMetrics.prototype.enableElementListenTracker = true; nickjillings@1576: break; nickjillings@1576: case 'elementInitialPosition': nickjillings@1576: sessionMetrics.prototype.enableElementInitialPosition = true; nickjillings@1576: break; nickjillings@1576: case 'elementFlagListenedTo': nickjillings@1576: sessionMetrics.prototype.enableFlagListenedTo = true; nickjillings@1576: break; nickjillings@1576: case 'elementFlagMoved': nickjillings@1576: sessionMetrics.prototype.enableFlagMoved = true; nickjillings@1576: break; nickjillings@1576: case 'elementFlagComments': nickjillings@1576: sessionMetrics.prototype.enableFlagComments = true; nickjillings@1576: break; nickjillings@1576: } nickjillings@1576: }); nickjillings@1576: nickjillings@1576: nickjillings@1576: nickjillings@1697: // Detect the interface to use and load the relevant javascripts. nickjillings@1683: var interfaceJS = document.createElement('script'); nickjillings@1683: interfaceJS.setAttribute("type","text/javascript"); nickjillings@1581: if (specification.interfaceType == 'APE') { nickjillings@1683: interfaceJS.setAttribute("src","ape.js"); nickjillings@1643: nickjillings@1643: // APE comes with a css file nickjillings@1643: var css = document.createElement('link'); nickjillings@1643: css.rel = 'stylesheet'; nickjillings@1643: css.type = 'text/css'; nickjillings@1643: css.href = 'ape.css'; nickjillings@1643: nickjillings@1643: document.getElementsByTagName("head")[0].appendChild(css); nickjillings@1683: } nickjillings@1683: document.getElementsByTagName("head")[0].appendChild(interfaceJS); nickjillings@1633: nickjillings@1633: // Define window callbacks for interface nickjillings@1633: window.onresize = function(event){resizeWindow(event);}; nickjillings@1682: } nickjillings@1682: nickjillings@1682: function createProjectSave(destURL) { nickjillings@1682: // Save the data from interface into XML and send to destURL nickjillings@1682: // If destURL is null then download XML in client nickjillings@1688: // Now time to render file locally nickjillings@1688: var xmlDoc = interfaceXMLSave(); nickjillings@1628: var parent = document.createElement("div"); nickjillings@1628: parent.appendChild(xmlDoc); nickjillings@1628: var file = [parent.innerHTML]; nickjillings@1688: if (destURL == "null" || destURL == undefined) { nickjillings@1688: var bb = new Blob(file,{type : 'application/xml'}); nickjillings@1688: var dnlk = window.URL.createObjectURL(bb); nickjillings@1688: var a = document.createElement("a"); nickjillings@1688: a.hidden = ''; nickjillings@1688: a.href = dnlk; nickjillings@1688: a.download = "save.xml"; nickjillings@1688: a.textContent = "Save File"; nickjillings@1688: nickjillings@1624: popup.showPopup(); nickjillings@1624: popup.popupContent.innerHTML = null; nickjillings@1582: popup.popupContent.appendChild(a); nickjillings@1628: } else { nickjillings@1628: var xmlhttp = new XMLHttpRequest; nickjillings@1628: xmlhttp.open("POST",destURL,true); nickjillings@1628: xmlhttp.setRequestHeader('Content-Type', 'text/xml'); nickjillings@1629: xmlhttp.onerror = function(){ nickjillings@1629: console.log('Error saving file to server! Presenting download locally'); nickjillings@1629: createProjectSave(null); nickjillings@1629: }; nickjillings@2018: xmlhttp.onreadystatechange = function() { nickjillings@2018: console.log(xmlhttp.status); nickjillings@2018: if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { nickjillings@2018: createProjectSave(null); nickjillings@2018: } nickjillings@2018: }; nickjillings@1628: xmlhttp.send(file); nickjillings@1688: } nickjillings@1682: } nickjillings@1682: nickjillings@1634: // Only other global function which must be defined in the interface class. Determines how to create the XML document. nickjillings@1634: function interfaceXMLSave(){ nickjillings@1634: // Create the XML string to be exported with results nickjillings@1634: var xmlDoc = document.createElement("BrowserEvaluationResult"); nickjillings@1634: xmlDoc.appendChild(returnDateNode()); nickjillings@1634: for (var i=0; i nickjillings@1631: // DD/MM/YY nickjillings@1631: // nickjillings@1631: // nickjillings@1631: var dateTime = new Date(); nickjillings@1631: var year = document.createAttribute('year'); nickjillings@1631: var month = document.createAttribute('month'); nickjillings@1631: var day = document.createAttribute('day'); nickjillings@1631: var hour = document.createAttribute('hour'); nickjillings@1631: var minute = document.createAttribute('minute'); nickjillings@1631: var secs = document.createAttribute('secs'); nickjillings@1631: nickjillings@1631: year.nodeValue = dateTime.getFullYear(); nickjillings@1631: month.nodeValue = dateTime.getMonth()+1; nickjillings@1631: day.nodeValue = dateTime.getDate(); nickjillings@1631: hour.nodeValue = dateTime.getHours(); nickjillings@1631: minute.nodeValue = dateTime.getMinutes(); nickjillings@1631: secs.nodeValue = dateTime.getSeconds(); nickjillings@1631: nickjillings@1631: var hold = document.createElement("datetime"); nickjillings@1631: var date = document.createElement("date"); nickjillings@1631: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; nickjillings@1631: var time = document.createElement("time"); nickjillings@1631: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; nickjillings@1631: nickjillings@1631: date.setAttributeNode(year); nickjillings@1631: date.setAttributeNode(month); nickjillings@1631: date.setAttributeNode(day); nickjillings@1631: time.setAttributeNode(hour); nickjillings@1631: time.setAttributeNode(minute); nickjillings@1631: time.setAttributeNode(secs); nickjillings@1631: nickjillings@1631: hold.appendChild(date); nickjillings@1631: hold.appendChild(time); nickjillings@1631: return hold nickjillings@1631: nickjillings@1604: } nickjillings@1604: nickjillings@1604: function testWaitIndicator() { nickjillings@2013: if (audioEngineContext.checkAllReady() == false) { nickjillings@2013: var hold = document.createElement("div"); nickjillings@2013: hold.id = "testWaitIndicator"; nickjillings@2013: hold.className = "indicator-box"; nickjillings@1585: hold.style.zIndex = 3; nickjillings@2013: var span = document.createElement("span"); nickjillings@2013: span.textContent = "Please wait! Elements still loading"; nickjillings@2013: hold.appendChild(span); nickjillings@1585: var blank = document.createElement('div'); nickjillings@1585: blank.className = 'testHalt'; nickjillings@1585: blank.id = "testHaltBlank"; nickjillings@2013: var body = document.getElementsByTagName('body')[0]; nickjillings@2013: body.appendChild(hold); nickjillings@1585: body.appendChild(blank); nickjillings@2013: testWaitTimerIntervalHolder = setInterval(function(){ nickjillings@2013: var ready = audioEngineContext.checkAllReady(); nickjillings@2013: if (ready) { nickjillings@2013: var elem = document.getElementById('testWaitIndicator'); nickjillings@1585: var blank = document.getElementById('testHaltBlank'); nickjillings@2013: var body = document.getElementsByTagName('body')[0]; nickjillings@2013: body.removeChild(elem); nickjillings@1585: body.removeChild(blank); nickjillings@2013: clearInterval(testWaitTimerIntervalHolder); nickjillings@2013: } nickjillings@2013: },500,false); nickjillings@2013: } nickjillings@1604: } nickjillings@1604: nickjillings@2013: var testWaitTimerIntervalHolder = null; nickjillings@1580: nickjillings@1580: function Specification() { nickjillings@1580: // Handles the decoding of the project specification XML into a simple JavaScript Object. nickjillings@1580: nickjillings@1580: this.interfaceType; nickjillings@1580: this.projectReturn; nickjillings@1580: this.randomiseOrder; nickjillings@1580: this.collectMetrics; nickjillings@1580: this.preTest; nickjillings@1580: this.postTest; nickjillings@1580: this.metrics =[]; nickjillings@1580: nickjillings@1580: this.audioHolders = []; nickjillings@1580: nickjillings@1580: this.decode = function() { nickjillings@1580: // projectXML - DOM Parsed document nickjillings@1580: var setupNode = projectXML.getElementsByTagName('setup')[0]; nickjillings@1580: this.interfaceType = setupNode.getAttribute('interface'); nickjillings@1580: this.projectReturn = setupNode.getAttribute('projectReturn'); nickjillings@1580: if (setupNode.getAttribute('randomiseOrder') == "true") { nickjillings@1580: this.randomiseOrder = true; nickjillings@1584: } else {this.randomiseOrder = false;} nickjillings@1580: if (setupNode.getAttribute('collectMetrics') == "true") { nickjillings@1580: this.collectMetrics = true; nickjillings@1584: } else {this.collectMetrics = false;} nickjillings@1580: var metricCollection = setupNode.getElementsByTagName('Metric'); nickjillings@1580: nickjillings@1581: this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); nickjillings@1581: this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); nickjillings@1580: nickjillings@1580: if (metricCollection.length > 0) { nickjillings@1580: metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); nickjillings@1580: for (var i=0; i tag. nickjillings@1582: this.interfaceObjects = []; nickjillings@1582: this.interfaceObject = function(){}; nickjillings@1582: nickjillings@1582: this.commentBoxes = []; nickjillings@1582: this.commentBox = function(audioObject) { nickjillings@1582: var element = audioObject.specification; nickjillings@1583: this.audioObject = audioObject; nickjillings@1582: this.id = audioObject.id; nickjillings@1582: var audioHolderObject = audioObject.specification.parent; nickjillings@1582: // Create document objects to hold the comment boxes nickjillings@1582: this.trackComment = document.createElement('div'); nickjillings@1582: this.trackComment.className = 'comment-div'; nickjillings@1582: this.trackComment.id = 'comment-div-'+audioObject.id; nickjillings@1582: // Create a string next to each comment asking for a comment nickjillings@1583: this.trackString = document.createElement('span'); nickjillings@1583: this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; nickjillings@1582: // Create the HTML5 comment box 'textarea' nickjillings@1583: this.trackCommentBox = document.createElement('textarea'); nickjillings@1583: this.trackCommentBox.rows = '4'; nickjillings@1583: this.trackCommentBox.cols = '100'; nickjillings@1583: this.trackCommentBox.name = 'trackComment'+audioObject.id; nickjillings@1583: this.trackCommentBox.className = 'trackComment'; nickjillings@1582: var br = document.createElement('br'); nickjillings@1582: // Add to the holder. nickjillings@1583: this.trackComment.appendChild(this.trackString); nickjillings@1582: this.trackComment.appendChild(br); nickjillings@1583: this.trackComment.appendChild(this.trackCommentBox); nickjillings@1583: nickjillings@1583: this.exportXMLDOM = function() { nickjillings@1583: var root = document.createElement('comment'); nickjillings@1583: if (this.audioObject.specification.parent.elementComments) { nickjillings@1583: var question = document.createElement('question'); nickjillings@1583: question.textContent = this.trackString.textContent; nickjillings@1583: var response = document.createElement('response'); nickjillings@1583: response.textContent = this.trackCommentBox.value; nickjillings@1583: root.appendChild(question); nickjillings@1583: root.appendChild(response); nickjillings@1583: } nickjillings@1583: return root; nickjillings@1583: }; nickjillings@1582: }; nickjillings@1582: nickjillings@1582: this.createCommentBox = function(audioObject) { nickjillings@1582: var node = new this.commentBox(audioObject); nickjillings@1582: this.commentBoxes.push(node); nickjillings@1582: audioObject.commentDOM = node; nickjillings@1582: return node; nickjillings@1582: }; nickjillings@1582: nickjillings@1582: this.sortCommentBoxes = function() { nickjillings@1582: var holder = []; nickjillings@1582: while (this.commentBoxes.length > 0) { nickjillings@1582: var node = this.commentBoxes.pop(0); nickjillings@1582: holder[node.id] = node; nickjillings@1582: } nickjillings@1582: this.commentBoxes = holder; nickjillings@1582: }; nickjillings@1582: nickjillings@1582: this.showCommentBoxes = function(inject, sort) { nickjillings@1582: if (sort) {interfaceContext.sortCommentBoxes();} nickjillings@1582: for (var i=0; i