n@767: /** n@767: * core.js n@767: * n@767: * Main script to run, calls all other core functions and manages loading/store to backend. n@767: * Also contains all global variables. n@767: */ n@767: n@767: /* create the web audio API context and store in audioContext*/ n@767: var audioContext; // Hold the browser web audio API n@767: var projectXML; // Hold the parsed setup XML n@767: var specification; n@767: var interfaceContext; n@767: var popup; // Hold the interfacePopup object n@767: var testState; n@767: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order n@767: var audioEngineContext; // The custome AudioEngine object n@767: var projectReturn; // Hold the URL for the return n@767: n@767: n@767: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it n@767: AudioBufferSourceNode.prototype.owner = undefined; n@767: n@767: window.onload = function() { n@767: // Function called once the browser has loaded all files. n@767: // This should perform any initial commands such as structure / loading documents n@767: n@767: // Create a web audio API context n@767: // Fixed for cross-browser support n@767: var AudioContext = window.AudioContext || window.webkitAudioContext; n@767: audioContext = new AudioContext; n@767: n@767: // Create test state n@767: testState = new stateMachine(); n@767: n@767: // Create the audio engine object n@767: audioEngineContext = new AudioEngine(); n@767: n@767: // Create the popup interface object n@767: popup = new interfacePopup(); n@767: n@767: // Create the specification object n@767: specification = new Specification(); n@767: n@767: // Create the interface object n@767: interfaceContext = new Interface(specification); n@767: }; n@767: n@767: function interfacePopup() { n@767: // Creates an object to manage the popup n@767: this.popup = null; n@767: this.popupContent = null; n@767: this.popupTitle = null; n@767: this.popupResponse = null; n@767: this.buttonProceed = null; n@767: this.buttonPrevious = null; n@767: this.popupOptions = null; n@767: this.currentIndex = null; n@767: this.responses = null; n@767: n@767: this.createPopup = function(){ n@767: // Create popup window interface n@767: var insertPoint = document.getElementById("topLevelBody"); n@767: var blank = document.createElement('div'); n@767: blank.className = 'testHalt'; n@767: n@767: this.popup = document.createElement('div'); n@767: this.popup.id = 'popupHolder'; n@767: this.popup.className = 'popupHolder'; n@767: this.popup.style.position = 'absolute'; n@767: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; n@767: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; n@767: n@767: this.popupContent = document.createElement('div'); n@767: this.popupContent.id = 'popupContent'; n@767: this.popupContent.style.marginTop = '20px'; n@767: this.popupContent.style.marginBottom = '5px'; n@767: this.popup.appendChild(this.popupContent); n@767: n@767: var titleHolder = document.createElement('div'); n@767: titleHolder.id = 'popupTitleHolder'; n@767: titleHolder.align = 'center'; n@767: titleHolder.style.width = 'inherit'; n@767: titleHolder.style.minHeight = '25px'; n@767: titleHolder.style.maxHeight = '250px'; n@767: titleHolder.style.overflow = 'auto'; n@767: titleHolder.style.marginBottom = '5px'; n@767: n@767: this.popupTitle = document.createElement('span'); n@767: this.popupTitle.id = 'popupTitle'; n@767: titleHolder.appendChild(this.popupTitle); n@767: this.popupContent.appendChild(titleHolder); n@767: n@767: this.popupResponse = document.createElement('div'); n@767: this.popupResponse.id = 'popupResponse'; n@767: this.popupResponse.align = 'center'; n@767: this.popupResponse.style.width = 'inherit'; n@767: this.popupResponse.style.minHeight = '50px'; n@767: this.popupResponse.style.maxHeight = '320px'; n@767: this.popupResponse.style.overflow = 'auto'; n@767: this.popupContent.appendChild(this.popupResponse); n@767: n@767: this.buttonProceed = document.createElement('button'); n@767: this.buttonProceed.className = 'popupButton'; n@767: this.buttonProceed.position = 'relative'; n@767: this.buttonProceed.style.left = '390px'; n@767: this.buttonProceed.innerHTML = 'Next'; n@767: this.buttonProceed.onclick = function(){popup.proceedClicked();}; n@767: n@767: this.buttonPrevious = document.createElement('button'); n@767: this.buttonPrevious.className = 'popupButton'; n@767: this.buttonPrevious.position = 'relative'; n@767: this.buttonPrevious.style.left = '10px'; n@767: this.buttonPrevious.innerHTML = 'Back'; n@767: this.buttonPrevious.onclick = function(){popup.previousClick();}; n@767: n@767: this.popupContent.appendChild(this.buttonPrevious); n@767: this.popupContent.appendChild(this.buttonProceed); n@767: n@767: this.popup.style.zIndex = -1; n@767: this.popup.style.visibility = 'hidden'; n@767: blank.style.zIndex = -2; n@767: blank.style.visibility = 'hidden'; n@767: insertPoint.appendChild(this.popup); n@767: insertPoint.appendChild(blank); n@767: }; n@767: n@767: this.showPopup = function(){ n@767: if (this.popup == null) { n@767: this.createPopup(); n@767: } n@767: this.popup.style.zIndex = 3; n@767: this.popup.style.visibility = 'visible'; n@767: var blank = document.getElementsByClassName('testHalt')[0]; n@767: blank.style.zIndex = 2; n@767: blank.style.visibility = 'visible'; n@767: $(window).keypress(function(e){ n@767: if (e.keyCode == 13 && popup.popup.style.visibility == 'visible') n@767: { n@767: popup.buttonProceed.onclick(); n@767: } n@767: }); n@767: }; n@767: n@767: this.hidePopup = function(){ n@767: this.popup.style.zIndex = -1; n@767: this.popup.style.visibility = 'hidden'; n@767: var blank = document.getElementsByClassName('testHalt')[0]; n@767: blank.style.zIndex = -2; n@767: blank.style.visibility = 'hidden'; n@767: this.buttonPrevious.style.visibility = 'inherit'; n@767: $(window).keypress(function(e){}); n@767: }; n@767: n@767: this.postNode = function() { n@767: // This will take the node from the popupOptions and display it n@767: var node = this.popupOptions[this.currentIndex]; n@767: this.popupResponse.innerHTML = null; n@767: if (node.type == 'statement') { n@767: this.popupTitle.textContent = null; n@767: var statement = document.createElement('span'); n@767: statement.textContent = node.statement; n@767: this.popupResponse.appendChild(statement); n@767: } else if (node.type == 'question') { n@767: this.popupTitle.textContent = node.question; n@767: var textArea = document.createElement('textarea'); n@767: switch (node.boxsize) { n@767: case 'small': n@767: textArea.cols = "20"; n@767: textArea.rows = "1"; n@767: break; n@767: case 'normal': n@767: textArea.cols = "30"; n@767: textArea.rows = "2"; n@767: break; n@767: case 'large': n@767: textArea.cols = "40"; n@767: textArea.rows = "5"; n@767: break; n@767: case 'huge': n@767: textArea.cols = "50"; n@767: textArea.rows = "10"; n@767: break; n@767: } n@767: this.popupResponse.appendChild(textArea); n@767: textArea.focus(); n@767: } else if (node.type == 'checkbox') { n@767: this.popupTitle.textContent = node.statement; n@767: var optHold = this.popupResponse; n@767: for (var i=0; i 0) n@767: this.buttonPrevious.style.visibility = 'visible'; n@767: else n@767: this.buttonPrevious.style.visibility = 'hidden'; n@767: }; n@767: n@767: this.initState = function(node) { n@767: //Call this with your preTest and postTest nodes when needed to n@767: // initialise the popup procedure. n@767: this.popupOptions = node.options; n@767: if (this.popupOptions.length > 0) { n@767: if (node.type == 'pretest') { n@767: this.responses = document.createElement('PreTest'); n@767: } else if (node.type == 'posttest') { n@767: this.responses = document.createElement('PostTest'); n@767: } else { n@767: console.log ('WARNING - popup node neither pre or post!'); n@767: this.responses = document.createElement('responses'); n@767: } n@767: this.currentIndex = 0; n@767: this.showPopup(); n@767: this.postNode(); n@767: } else { n@767: advanceState(); n@767: } n@767: }; n@767: n@767: this.proceedClicked = function() { n@767: // Each time the popup button is clicked! n@767: var node = this.popupOptions[this.currentIndex]; n@767: if (node.type == 'question') { n@767: // Must extract the question data n@767: var textArea = $(popup.popupContent).find('textarea')[0]; n@767: if (node.mandatory == true && textArea.value.length == 0) { n@767: alert('This question is mandatory'); n@767: return; n@767: } else { n@767: // Save the text content n@767: var hold = document.createElement('comment'); n@767: hold.id = node.id; n@767: hold.innerHTML = textArea.value; n@767: console.log("Question: "+ node.question); n@767: console.log("Question Response: "+ textArea.value); n@767: this.responses.appendChild(hold); n@767: } n@767: } else if (node.type == 'checkbox') { n@767: // Must extract checkbox data n@767: var optHold = this.popupResponse; n@767: var hold = document.createElement('checkbox'); n@767: console.log("Checkbox: "+ node.statement); n@767: hold.id = node.id; n@767: for (var i=0; i node.max && node.max != null) { n@767: alert('Number is above the maximum value of '+node.max); n@767: return; n@767: } n@767: var hold = document.createElement('number'); n@767: hold.id = node.id; n@767: hold.textContent = input.value; n@767: this.responses.appendChild(hold); n@767: } n@767: this.currentIndex++; n@767: if (this.currentIndex < this.popupOptions.length) { n@767: this.postNode(); n@767: } else { n@767: // Reached the end of the popupOptions n@767: this.hidePopup(); n@767: if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { n@767: testState.stateResults[testState.stateIndex] = this.responses; n@767: } else { n@767: testState.stateResults[testState.stateIndex].appendChild(this.responses); n@767: } n@767: advanceState(); n@767: } n@767: }; n@767: n@767: this.previousClick = function() { n@767: // Triggered when the 'Back' button is clicked in the survey n@767: if (this.currentIndex > 0) { n@767: this.currentIndex--; n@767: var node = this.popupOptions[this.currentIndex]; n@767: if (node.type != 'statement') { n@767: var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; n@767: this.responses.removeChild(prevResp); n@767: } n@767: this.postNode(); n@767: if (node.type == 'question') { n@767: this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; n@767: } else if (node.type == 'checkbox') { n@767: var options = this.popupContent.getElementsByTagName('input'); n@767: var savedOptions = prevResp.getElementsByTagName('option'); n@767: for (var i=0; i 0) { n@767: if(this.stateIndex != null) { n@767: console.log('NOTE - State already initialise'); n@767: } n@767: this.stateIndex = -1; n@767: var that = this; n@767: var aH_pId = 0; n@767: for (var id=0; id= this.stateMap.length) { n@767: console.log('Test Completed'); n@767: createProjectSave(specification.projectReturn); n@767: } else { n@767: this.currentStateMap = this.stateMap[this.stateIndex]; n@767: if (this.currentStateMap.type == "audioHolder") { n@767: console.log('Loading test page'); n@767: loadTest(this.currentStateMap); n@767: this.initialiseInnerState(this.currentStateMap); n@767: } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") { n@767: if (this.currentStateMap.options.length >= 1) { n@767: popup.initState(this.currentStateMap); n@767: } else { n@767: this.advanceState(); n@767: } n@767: } else { n@767: this.advanceState(); n@767: } n@767: } n@767: } else { n@767: this.advanceInnerState(); n@767: } n@767: }; n@767: n@767: this.testPageCompleted = function(store, testXML, testId) { n@767: // Function called each time a test page has been completed n@767: // Can be used to over-rule default behaviour n@767: n@767: pageXMLSave(store, testXML); n@767: }; n@767: n@767: this.initialiseInnerState = function(node) { n@767: // Parses the received testXML for pre and post test options n@767: this.currentStateMap = []; n@767: var preTest = node.preTest; n@767: var postTest = node.postTest; n@767: if (preTest == undefined) {preTest = document.createElement("preTest");} n@767: if (postTest == undefined){postTest= document.createElement("postTest");} n@767: this.currentStateMap.push(preTest); n@767: this.currentStateMap.push(node); n@767: this.currentStateMap.push(postTest); n@767: this.currentIndex = -1; n@767: this.advanceInnerState(); n@767: }; n@767: n@767: this.advanceInnerState = function() { n@767: this.currentIndex++; n@767: if (this.currentIndex >= this.currentStateMap.length) { n@767: this.currentIndex = null; n@767: this.currentStateMap = this.stateMap[this.stateIndex]; n@767: this.advanceState(); n@767: } else { n@767: if (this.currentStateMap[this.currentIndex].type == "audioHolder") { n@767: console.log("Loading test page"+this.currentTestId); n@767: } else if (this.currentStateMap[this.currentIndex].type == "pretest") { n@767: popup.initState(this.currentStateMap[this.currentIndex]); n@767: } else if (this.currentStateMap[this.currentIndex].type == "posttest") { n@767: popup.initState(this.currentStateMap[this.currentIndex]); n@767: } else { n@767: this.advanceInnerState(); n@767: } n@767: } n@767: }; n@767: n@767: this.previousState = function(){}; n@767: } n@767: n@767: function testEnded(testId) n@767: { n@767: pageXMLSave(testId); n@767: if (testXMLSetups.length-1 > testId) n@767: { n@767: // Yes we have another test to perform n@767: testId = (Number(testId)+1); n@767: currentState = 'testRun-'+testId; n@767: loadTest(testId); n@767: } else { n@767: console.log('Testing Completed!'); n@767: currentState = 'postTest'; n@767: // Check for any post tests n@767: var xmlSetup = projectXML.find('setup'); n@767: var postTest = xmlSetup.find('PostTest')[0]; n@767: popup.initState(postTest); n@767: } n@767: } n@767: n@767: function loadProjectSpec(url) { n@767: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data n@767: // If url is null, request client to upload project XML document n@767: var r = new XMLHttpRequest(); n@767: r.open('GET',url,true); n@767: r.onload = function() { n@767: loadProjectSpecCallback(r.response); n@767: }; n@767: r.send(); n@767: }; n@767: n@767: function loadProjectSpecCallback(response) { n@767: // Function called after asynchronous download of XML project specification n@767: //var decode = $.parseXML(response); n@767: //projectXML = $(decode); n@767: n@767: var parse = new DOMParser(); n@767: projectXML = parse.parseFromString(response,'text/xml'); n@767: n@767: // Build the specification n@769: specification.decode(projectXML); n@767: n@767: testState.stateMap.push(specification.preTest); n@767: n@767: $(specification.audioHolders).each(function(index,elem){ n@767: testState.stateMap.push(elem); n@767: }); n@767: n@767: testState.stateMap.push(specification.postTest); n@767: n@767: // Obtain the metrics enabled n@767: $(specification.metrics).each(function(index,node){ n@767: var enabled = node.textContent; n@767: switch(node.enabled) n@767: { n@767: case 'testTimer': n@767: sessionMetrics.prototype.enableTestTimer = true; n@767: break; n@767: case 'elementTimer': n@767: sessionMetrics.prototype.enableElementTimer = true; n@767: break; n@767: case 'elementTracker': n@767: sessionMetrics.prototype.enableElementTracker = true; n@767: break; n@767: case 'elementListenTracker': n@767: sessionMetrics.prototype.enableElementListenTracker = true; n@767: break; n@767: case 'elementInitialPosition': n@767: sessionMetrics.prototype.enableElementInitialPosition = true; n@767: break; n@767: case 'elementFlagListenedTo': n@767: sessionMetrics.prototype.enableFlagListenedTo = true; n@767: break; n@767: case 'elementFlagMoved': n@767: sessionMetrics.prototype.enableFlagMoved = true; n@767: break; n@767: case 'elementFlagComments': n@767: sessionMetrics.prototype.enableFlagComments = true; n@767: break; n@767: } n@767: }); n@767: n@767: n@767: n@767: // Detect the interface to use and load the relevant javascripts. n@767: var interfaceJS = document.createElement('script'); n@767: interfaceJS.setAttribute("type","text/javascript"); n@767: if (specification.interfaceType == 'APE') { n@767: interfaceJS.setAttribute("src","ape.js"); n@767: n@767: // APE comes with a css file n@767: var css = document.createElement('link'); n@767: css.rel = 'stylesheet'; n@767: css.type = 'text/css'; n@767: css.href = 'ape.css'; n@767: n@767: document.getElementsByTagName("head")[0].appendChild(css); n@767: } else if (specification.interfaceType == "MUSHRA") n@767: { n@767: interfaceJS.setAttribute("src","mushra.js"); n@767: n@767: // MUSHRA comes with a css file n@767: var css = document.createElement('link'); n@767: css.rel = 'stylesheet'; n@767: css.type = 'text/css'; n@767: css.href = 'mushra.css'; n@767: n@767: document.getElementsByTagName("head")[0].appendChild(css); n@767: } n@767: document.getElementsByTagName("head")[0].appendChild(interfaceJS); n@767: n@767: // Define window callbacks for interface n@767: window.onresize = function(event){interfaceContext.resizeWindow(event);}; n@767: } n@767: n@767: function createProjectSave(destURL) { n@767: // Save the data from interface into XML and send to destURL n@767: // If destURL is null then download XML in client n@767: // Now time to render file locally n@767: var xmlDoc = interfaceXMLSave(); n@767: var parent = document.createElement("div"); n@767: parent.appendChild(xmlDoc); n@767: var file = [parent.innerHTML]; n@767: if (destURL == "null" || destURL == undefined) { n@767: var bb = new Blob(file,{type : 'application/xml'}); n@767: var dnlk = window.URL.createObjectURL(bb); n@767: var a = document.createElement("a"); n@767: a.hidden = ''; n@767: a.href = dnlk; n@767: a.download = "save.xml"; n@767: a.textContent = "Save File"; n@767: n@767: popup.showPopup(); n@767: popup.popupContent.innerHTML = null; n@767: popup.popupContent.appendChild(a); n@767: } else { n@767: var xmlhttp = new XMLHttpRequest; n@767: xmlhttp.open("POST",destURL,true); n@767: xmlhttp.setRequestHeader('Content-Type', 'text/xml'); n@767: xmlhttp.onerror = function(){ n@767: console.log('Error saving file to server! Presenting download locally'); n@767: createProjectSave(null); n@767: }; n@767: xmlhttp.onreadystatechange = function() { n@767: console.log(xmlhttp.status); n@767: if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { n@767: createProjectSave(null); n@767: } else { n@767: if (xmlhttp.responseXML == null) n@767: { n@767: return createProjectSave(null); n@767: } n@767: var response = xmlhttp.responseXML.childNodes[0]; n@767: if (response.getAttribute('state') == "OK") n@767: { n@767: var file = response.getElementsByTagName('file')[0]; n@767: console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B'); n@767: popup.showPopup(); n@767: popup.popupContent.innerHTML = null; n@767: popup.popupContent.textContent = "Thank you!"; n@767: } else { n@767: var message = response.getElementsByTagName('message')[0]; n@767: errorSessionDump(message.textContent); n@767: } n@767: } n@767: }; n@767: xmlhttp.send(file); n@767: } n@767: } n@767: n@767: function errorSessionDump(msg){ n@767: // Create the partial interface XML save n@767: // Include error node with message on why the dump occured n@767: var xmlDoc = interfaceXMLSave(); n@767: var err = document.createElement('error'); n@767: err.textContent = msg; n@767: xmlDoc.appendChild(err); n@767: var parent = document.createElement("div"); n@767: parent.appendChild(xmlDoc); n@767: var file = [parent.innerHTML]; n@767: var bb = new Blob(file,{type : 'application/xml'}); n@767: var dnlk = window.URL.createObjectURL(bb); n@767: var a = document.createElement("a"); n@767: a.hidden = ''; n@767: a.href = dnlk; n@767: a.download = "save.xml"; n@767: a.textContent = "Save File"; n@767: n@767: popup.showPopup(); n@767: popup.popupContent.innerHTML = "ERROR : "+msg; n@767: popup.popupContent.appendChild(a); n@767: } n@767: n@767: // Only other global function which must be defined in the interface class. Determines how to create the XML document. n@767: function interfaceXMLSave(){ n@767: // Create the XML string to be exported with results n@767: var xmlDoc = document.createElement("BrowserEvaluationResult"); n@767: var projectDocument = specification.projectXML; n@767: projectDocument.setAttribute('file-name',url); n@767: xmlDoc.appendChild(projectDocument); n@767: xmlDoc.appendChild(returnDateNode()); n@767: xmlDoc.appendChild(interfaceContext.returnNavigator()); n@767: for (var i=0; i n@767: // DD/MM/YY n@767: // n@767: // n@767: var dateTime = new Date(); n@767: var year = document.createAttribute('year'); n@767: var month = document.createAttribute('month'); n@767: var day = document.createAttribute('day'); n@767: var hour = document.createAttribute('hour'); n@767: var minute = document.createAttribute('minute'); n@767: var secs = document.createAttribute('secs'); n@767: n@767: year.nodeValue = dateTime.getFullYear(); n@767: month.nodeValue = dateTime.getMonth()+1; n@767: day.nodeValue = dateTime.getDate(); n@767: hour.nodeValue = dateTime.getHours(); n@767: minute.nodeValue = dateTime.getMinutes(); n@767: secs.nodeValue = dateTime.getSeconds(); n@767: n@767: var hold = document.createElement("datetime"); n@767: var date = document.createElement("date"); n@767: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; n@767: var time = document.createElement("time"); n@767: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; n@767: n@767: date.setAttributeNode(year); n@767: date.setAttributeNode(month); n@767: date.setAttributeNode(day); n@767: time.setAttributeNode(hour); n@767: time.setAttributeNode(minute); n@767: time.setAttributeNode(secs); n@767: n@767: hold.appendChild(date); n@767: hold.appendChild(time); n@767: return hold n@767: n@767: } n@767: n@767: function Specification() { n@767: // Handles the decoding of the project specification XML into a simple JavaScript Object. n@767: n@767: this.interfaceType = null; n@769: this.commonInterface = new function() n@769: { n@769: this.options = []; n@769: this.optionNode = function(input) n@769: { n@769: var name = input.getAttribute('name'); n@769: this.type = name; n@769: if(this.type == "option") n@769: { n@769: this.name = input.id; n@769: } else if (this.type == "check") n@769: { n@769: this.check = input.id; n@769: } n@769: }; n@769: }; n@767: this.projectReturn = null; n@767: this.randomiseOrder = null; n@767: this.collectMetrics = null; n@767: this.testPages = null; n@769: this.audioHolders = []; n@769: this.metrics = []; n@767: n@769: this.decode = function(projectXML) { n@767: // projectXML - DOM Parsed document n@767: this.projectXML = projectXML.childNodes[0]; n@767: var setupNode = projectXML.getElementsByTagName('setup')[0]; n@767: this.interfaceType = setupNode.getAttribute('interface'); n@767: this.projectReturn = setupNode.getAttribute('projectReturn'); n@767: this.testPages = setupNode.getAttribute('testPages'); n@767: if (setupNode.getAttribute('randomiseOrder') == "true") { n@767: this.randomiseOrder = true; n@767: } else {this.randomiseOrder = false;} n@767: if (setupNode.getAttribute('collectMetrics') == "true") { n@767: this.collectMetrics = true; n@767: } else {this.collectMetrics = false;} n@767: if (isNaN(Number(this.testPages)) || this.testPages == undefined) n@767: { n@767: this.testPages = null; n@767: } else { n@767: this.testPages = Number(this.testPages); n@767: if (this.testPages == 0) {this.testPages = null;} n@767: } n@767: var metricCollection = setupNode.getElementsByTagName('Metric'); n@767: n@769: var setupPreTestNode = setupNode.getElementsByTagName('PreTest'); n@769: if (setupPreTestNode.length != 0) n@769: { n@769: setupPreTestNode = setupPreTestNode[0]; n@769: this.preTest.construct(setupPreTestNode); n@769: } n@769: n@769: var setupPostTestNode = setupNode.getElementsByTagName('PostTest'); n@769: if (setupPostTestNode.length != 0) n@769: { n@769: setupPostTestNode = setupPostTestNode[0]; n@769: this.postTest.construct(setupPostTestNode); n@769: } n@767: n@767: if (metricCollection.length > 0) { n@767: metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); n@767: for (var i=0; i 0) { n@767: commonInterfaceNode = commonInterfaceNode[0]; n@767: } else { n@767: commonInterfaceNode = undefined; n@767: } n@767: n@767: this.commonInterface = new function() { n@767: this.OptionNode = function(child) { n@767: this.type = child.nodeName; n@767: if (this.type == 'option') n@767: { n@767: this.name = child.getAttribute('name'); n@767: } n@767: else if (this.type == 'check') { n@767: this.check = child.getAttribute('name'); n@767: if (this.check == 'scalerange') { n@767: this.min = child.getAttribute('min'); n@767: this.max = child.getAttribute('max'); n@767: if (this.min == null) {this.min = 1;} n@767: else if (Number(this.min) > 1 && this.min != null) { n@767: this.min = Number(this.min)/100; n@767: } else { n@767: this.min = Number(this.min); n@767: } n@767: if (this.max == null) {this.max = 0;} n@767: else if (Number(this.max) > 1 && this.max != null) { n@767: this.max = Number(this.max)/100; n@767: } else { n@767: this.max = Number(this.max); n@767: } n@767: } n@767: } else if (this.type == 'anchor' || this.type == 'reference') { n@769: this.value = Number(child.textContent); n@769: this.enforce = child.getAttribute('enforce'); n@769: if (this.enforce == 'true') {this.enforce = true;} n@769: else {this.enforce = false;} n@767: } n@767: }; n@767: this.options = []; n@767: if (commonInterfaceNode != undefined) { n@767: var child = commonInterfaceNode.firstElementChild; n@767: while (child != undefined) { n@767: this.options.push(new this.OptionNode(child)); n@767: child = child.nextElementSibling; n@767: } n@767: } n@767: }; n@767: n@767: var audioHolders = projectXML.getElementsByTagName('audioHolder'); n@767: for (var i=0; i audioHolders.length) n@767: { n@767: console.log('Warning: You have specified '+audioHolders.length+' tests but requested '+this.testPages+' be completed!'); n@767: this.testPages = audioHolders.length; n@767: } n@767: var aH = this.audioHolders; n@767: this.audioHolders = []; n@767: for (var i=0; i tag compiled n@769: var setupNode = root.createElement("setup"); n@769: setupNode.setAttribute('interface',this.interfaceType); n@769: setupNode.setAttribute('projectReturn',this.projectReturn); n@769: setupNode.setAttribute('randomiseOrder',this.randomiseOrder); n@769: setupNode.setAttribute('collectMetrics',this.collectMetrics); n@769: setupNode.setAttribute('testPages',this.testPages); n@769: n@769: var setupPreTest = root.createElement("PreTest"); n@769: for (var i=0; i tag n@769: var Metric = root.createElement("Metric"); n@769: for (var i=0; i tag n@769: var CommonInterface = root.createElement("interface"); n@769: for (var i=0; i tags n@769: for (var ahIndex = 0; ahIndex < this.audioHolders.length; ahIndex++) n@769: { n@769: var node = this.audioHolders[ahIndex].encode(root); n@769: root.getElementsByTagName("BrowserEvalProjectDocument")[0].appendChild(node); n@769: } n@769: return root; n@769: }; n@769: n@769: this.prepostNode = function(type) { n@767: this.type = type; n@767: this.options = []; n@767: n@769: this.OptionNode = function() { n@767: n@769: this.childOption = function() { n@767: this.type = 'option'; n@769: this.id = null; n@769: this.name = undefined; n@769: this.text = null; n@767: }; n@767: n@769: this.type = undefined; n@769: this.id = undefined; n@769: this.mandatory = undefined; n@769: this.question = undefined; n@769: this.statement = undefined; n@769: this.boxsize = undefined; n@769: this.options = []; n@769: this.min = undefined; n@769: this.max = undefined; n@769: this.step = undefined; n@769: n@769: this.decode = function(child) n@769: { n@769: this.type = child.nodeName; n@769: if (child.nodeName == "question") { n@769: this.id = child.id; n@769: this.mandatory; n@769: if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} n@769: else {this.mandatory = false;} n@769: this.question = child.textContent; n@769: if (child.getAttribute('boxsize') == null) { n@769: this.boxsize = 'normal'; n@769: } else { n@769: this.boxsize = child.getAttribute('boxsize'); n@769: } n@769: } else if (child.nodeName == "statement") { n@769: this.statement = child.textContent; n@769: } else if (child.nodeName == "checkbox" || child.nodeName == "radio") { n@769: var element = child.firstElementChild; n@769: this.id = child.id; n@769: if (element == null) { n@769: console.log('Malformed' +child.nodeName+ 'entry'); n@769: this.statement = 'Malformed' +child.nodeName+ 'entry'; n@769: this.type = 'statement'; n@769: } else { n@769: this.options = []; n@769: while (element != null) { n@769: if (element.nodeName == 'statement' && this.statement == undefined){ n@769: this.statement = element.textContent; n@769: } else if (element.nodeName == 'option') { n@769: var node = new this.childOption(); n@769: node.id = element.id; n@769: node.name = element.getAttribute('name'); n@769: node.text = element.textContent; n@769: this.options.push(node); n@769: } n@769: element = element.nextElementSibling; n@769: } n@769: } n@769: } else if (child.nodeName == "number") { n@769: this.statement = child.textContent; n@769: this.id = child.id; n@769: this.min = child.getAttribute('min'); n@769: this.max = child.getAttribute('max'); n@769: this.step = child.getAttribute('step'); n@767: } n@769: }; n@769: n@769: this.exportXML = function(root) n@769: { n@769: var node = root.createElement(this.type); n@769: switch(this.type) n@769: { n@769: case "statement": n@769: node.textContent = this.statement; n@769: break; n@769: case "question": n@769: node.id = this.id; n@769: node.setAttribute("mandatory",this.mandatory); n@769: node.setAttribute("boxsize",this.boxsize); n@769: node.textContent = this.question; n@769: break; n@769: case "number": n@769: node.id = this.id; n@769: node.setAttribute("mandatory",this.mandatory); n@769: node.setAttribute("min", this.min); n@769: node.setAttribute("max", this.max); n@769: node.setAttribute("step", this.step); n@769: node.textContent = this.statement; n@769: break; n@769: case "checkbox": n@769: node.id = this.id; n@769: var statement = root.createElement("statement"); n@769: statement.textContent = this.statement; n@769: node.appendChild(statement); n@769: for (var i=0; i n@769: for (var i=0; i n@769: var AHPreTest = root.createElement("PreTest"); n@769: for (var i=0; i 1) n@769: { this.marker /= 100.0;} n@769: if (this.marker >= 0 && this.marker <= 1) n@769: { n@769: this.enforce = true; n@769: return; n@769: } else { n@769: console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!"); n@769: console.log("ERROR - Marker not enforced!"); n@769: } n@767: } else { n@769: console.log("ERROR - Marker of audioElement "+this.id+" is not a number!"); n@767: console.log("ERROR - Marker not enforced!"); n@767: } n@767: } n@767: } n@769: }; n@769: this.encode = function(root) n@769: { n@769: var AENode = root.createElement("audioElements"); n@769: AENode.id = this.id; n@769: AENode.setAttribute("url",this.url); n@769: AENode.setAttribute("type",this.type); n@769: if (this.marker != false) n@769: { n@769: AENode.setAttribute("marker",this.marker*100); n@769: } n@769: return AENode; n@769: }; n@767: }; n@767: n@767: this.commentQuestionNode = function(xml) { n@769: this.id = null; n@769: this.type = undefined; n@769: this.question = undefined; n@769: this.options = []; n@769: this.statement = undefined; n@769: n@769: this.childOption = function() { n@767: this.type = 'option'; n@769: this.name = null; n@769: this.text = null; n@767: }; n@769: this.exportXML = function(root) n@769: { n@769: var CQNode = root.createElement("CommentQuestion"); n@769: CQNode.id = this.id; n@769: CQNode.setAttribute("type",this.type); n@769: switch(this.type) n@769: { n@769: case "text": n@769: CQNode.textContent = this.question; n@769: break; n@769: case "radio": n@769: var statement = root.createElement("statement"); n@769: statement.textContent = this.statement; n@769: CQNode.appendChild(statement); n@769: for (var i=0; i tag. n@767: this.interfaceObjects = []; n@767: this.interfaceObject = function(){}; n@767: n@767: this.resizeWindow = function(event) n@767: { n@767: for(var i=0; i= 600) n@767: { n@767: boxwidth = 600; n@767: } n@767: else if (boxwidth < 400) n@767: { n@767: boxwidth = 400; n@767: } n@767: this.trackComment.style.width = boxwidth+"px"; n@767: this.trackCommentBox.style.width = boxwidth-6+"px"; n@767: }; n@767: this.resize(); n@767: }; n@767: n@767: this.commentQuestions = []; n@767: n@767: this.commentBox = function(commentQuestion) { n@767: this.specification = commentQuestion; n@767: // Create document objects to hold the comment boxes n@767: this.holder = document.createElement('div'); n@767: this.holder.className = 'comment-div'; n@767: // Create a string next to each comment asking for a comment n@767: this.string = document.createElement('span'); n@767: this.string.innerHTML = commentQuestion.question; n@767: // Create the HTML5 comment box 'textarea' n@767: this.textArea = document.createElement('textarea'); n@767: this.textArea.rows = '4'; n@767: this.textArea.cols = '100'; n@767: this.textArea.className = 'trackComment'; n@767: var br = document.createElement('br'); n@767: // Add to the holder. n@767: this.holder.appendChild(this.string); n@767: this.holder.appendChild(br); n@767: this.holder.appendChild(this.textArea); n@767: n@767: this.exportXMLDOM = function() { n@767: var root = document.createElement('comment'); n@767: root.id = this.specification.id; n@767: root.setAttribute('type',this.specification.type); n@767: root.textContent = this.textArea.value; n@767: console.log("Question: "+this.string.textContent); n@767: console.log("Response: "+root.textContent); n@767: return root; n@767: }; n@767: this.resize = function() n@767: { n@767: var boxwidth = (window.innerWidth-100)/2; n@767: if (boxwidth >= 600) n@767: { n@767: boxwidth = 600; n@767: } n@767: else if (boxwidth < 400) n@767: { n@767: boxwidth = 400; n@767: } n@767: this.holder.style.width = boxwidth+"px"; n@767: this.textArea.style.width = boxwidth-6+"px"; n@767: }; n@767: this.resize(); n@767: }; n@767: n@767: this.radioBox = function(commentQuestion) { n@767: this.specification = commentQuestion; n@767: // Create document objects to hold the comment boxes n@767: this.holder = document.createElement('div'); n@767: this.holder.className = 'comment-div'; n@767: // Create a string next to each comment asking for a comment n@767: this.string = document.createElement('span'); n@767: this.string.innerHTML = commentQuestion.statement; n@767: var br = document.createElement('br'); n@767: // Add to the holder. n@767: this.holder.appendChild(this.string); n@767: this.holder.appendChild(br); n@767: this.options = []; n@767: this.inputs = document.createElement('div'); n@767: this.span = document.createElement('div'); n@767: this.inputs.align = 'center'; n@767: this.inputs.style.marginLeft = '12px'; n@767: this.span.style.marginLeft = '12px'; n@767: this.span.align = 'center'; n@767: this.span.style.marginTop = '15px'; n@767: n@767: var optCount = commentQuestion.options.length; n@767: for (var i=0; i= this.options.length) { n@767: break; n@767: } n@767: } n@767: if (i >= this.options.length) { n@767: response.textContent = 'null'; n@767: } else { n@767: response.textContent = this.options[i].getAttribute('setvalue'); n@767: response.setAttribute('number',i); n@767: } n@767: console.log('Comment: '+question.textContent); n@767: console.log('Response: '+response.textContent); n@767: root.appendChild(question); n@767: root.appendChild(response); n@767: return root; n@767: }; n@767: this.resize = function() n@767: { n@767: var boxwidth = (window.innerWidth-100)/2; n@767: if (boxwidth >= 600) n@767: { n@767: boxwidth = 600; n@767: } n@767: else if (boxwidth < 400) n@767: { n@767: boxwidth = 400; n@767: } n@767: this.holder.style.width = boxwidth+"px"; n@767: var text = this.holder.children[2]; n@767: var options = this.holder.children[3]; n@767: var optCount = options.children.length; n@767: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; n@767: var options = options.firstChild; n@767: var text = text.firstChild; n@767: options.style.marginRight = spanMargin; n@767: options.style.marginLeft = spanMargin; n@767: text.style.marginRight = spanMargin; n@767: text.style.marginLeft = spanMargin; n@767: while(options.nextSibling != undefined) n@767: { n@767: options = options.nextSibling; n@767: text = text.nextSibling; n@767: options.style.marginRight = spanMargin; n@767: options.style.marginLeft = spanMargin; n@767: text.style.marginRight = spanMargin; n@767: text.style.marginLeft = spanMargin; n@767: } n@767: }; n@767: this.resize(); n@767: }; n@767: n@767: this.checkboxBox = function(commentQuestion) { n@767: this.specification = commentQuestion; n@767: // Create document objects to hold the comment boxes n@767: this.holder = document.createElement('div'); n@767: this.holder.className = 'comment-div'; n@767: // Create a string next to each comment asking for a comment n@767: this.string = document.createElement('span'); n@767: this.string.innerHTML = commentQuestion.statement; n@767: var br = document.createElement('br'); n@767: // Add to the holder. n@767: this.holder.appendChild(this.string); n@767: this.holder.appendChild(br); n@767: this.options = []; n@767: this.inputs = document.createElement('div'); n@767: this.span = document.createElement('div'); n@767: this.inputs.align = 'center'; n@767: this.inputs.style.marginLeft = '12px'; n@767: this.span.style.marginLeft = '12px'; n@767: this.span.align = 'center'; n@767: this.span.style.marginTop = '15px'; n@767: n@767: var optCount = commentQuestion.options.length; n@767: for (var i=0; i= 600) n@767: { n@767: boxwidth = 600; n@767: } n@767: else if (boxwidth < 400) n@767: { n@767: boxwidth = 400; n@767: } n@767: this.holder.style.width = boxwidth+"px"; n@767: var text = this.holder.children[2]; n@767: var options = this.holder.children[3]; n@767: var optCount = options.children.length; n@767: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; n@767: var options = options.firstChild; n@767: var text = text.firstChild; n@767: options.style.marginRight = spanMargin; n@767: options.style.marginLeft = spanMargin; n@767: text.style.marginRight = spanMargin; n@767: text.style.marginLeft = spanMargin; n@767: while(options.nextSibling != undefined) n@767: { n@767: options = options.nextSibling; n@767: text = text.nextSibling; n@767: options.style.marginRight = spanMargin; n@767: options.style.marginLeft = spanMargin; n@767: text.style.marginRight = spanMargin; n@767: text.style.marginLeft = spanMargin; n@767: } n@767: }; n@767: this.resize(); n@767: }; n@767: n@767: this.createCommentBox = function(audioObject) { n@767: var node = new this.elementCommentBox(audioObject); n@767: this.commentBoxes.push(node); n@767: audioObject.commentDOM = node; n@767: return node; n@767: }; n@767: n@767: this.sortCommentBoxes = function() { n@767: var holder = []; n@767: while (this.commentBoxes.length > 0) { n@767: var node = this.commentBoxes.pop(0); n@767: holder[node.id] = node; n@767: } n@767: this.commentBoxes = holder; n@767: }; n@767: n@767: this.showCommentBoxes = function(inject, sort) { n@767: if (sort) {interfaceContext.sortCommentBoxes();} n@767: for (var i=0; i 0) { n@767: var time = this.playbackObject.getCurrentPosition(); n@767: if (time > 0) { n@767: var width = 490; n@767: var pix = Math.floor(time/this.timePerPixel); n@767: this.scrubberHead.style.left = pix+'px'; n@767: if (this.maxTime > 60.0) { n@767: var secs = time%60; n@767: var mins = Math.floor((time-secs)/60); n@767: secs = secs.toString(); n@767: secs = secs.substr(0,2); n@767: mins = mins.toString(); n@767: this.curTimeSpan.textContent = mins+':'+secs; n@767: } else { n@767: time = time.toString(); n@767: this.curTimeSpan.textContent = time.substr(0,4); n@767: } n@767: } else { n@767: this.scrubberHead.style.left = '0px'; n@767: if (this.maxTime < 60) { n@767: this.curTimeSpan.textContent = '0.00'; n@767: } else { n@767: this.curTimeSpan.textContent = '00:00'; n@767: } n@767: } n@767: } n@767: }; n@767: n@767: this.interval = undefined; n@767: n@767: this.start = function() { n@767: if (this.playbackObject != undefined && this.interval == undefined) { n@767: if (this.maxTime < 60) { n@767: this.interval = setInterval(function(){interfaceContext.playhead.update();},10); n@767: } else { n@767: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); n@767: } n@767: } n@767: }; n@767: this.stop = function() { n@767: clearInterval(this.interval); n@767: this.interval = undefined; n@767: if (this.maxTime < 60) { n@767: this.curTimeSpan.textContent = '0.00'; n@767: } else { n@767: this.curTimeSpan.textContent = '00:00'; n@767: } n@767: }; n@767: }; n@767: n@767: // Global Checkers n@767: // These functions will help enforce the checkers n@767: this.checkHiddenAnchor = function() n@767: { n@767: var audioHolder = testState.currentStateMap[testState.currentIndex]; n@767: if (audioHolder.anchorId != null) n@767: { n@767: var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId]; n@767: if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) n@767: { n@767: // Anchor is not set below n@767: console.log('Anchor node not below marker value'); n@767: alert('Please keep listening'); n@767: return false; n@767: } n@767: } n@767: return true; n@767: }; n@767: n@767: this.checkHiddenReference = function() n@767: { n@767: var audioHolder = testState.currentStateMap[testState.currentIndex]; n@767: if (audioHolder.referenceId != null) n@767: { n@767: var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId]; n@767: if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) n@767: { n@767: // Anchor is not set below n@767: console.log('Reference node not above marker value'); n@767: alert('Please keep listening'); n@767: return false; n@767: } n@767: } n@767: return true; n@767: }; n@767: n@767: this.checkFragmentsFullyPlayed = function () n@767: { n@767: // Checks the entire file has been played back n@767: // NOTE ! This will return true IF playback is Looped!!! n@767: if (audioEngineContext.loopPlayback) n@767: { n@767: console.log("WARNING - Looped source: Cannot check fragments are fully played"); n@767: return true; n@767: } n@767: var check_pass = true; n@767: var error_obj = []; n@767: for (var i = 0; i= time) n@767: { n@767: passed = true; n@767: break; n@767: } n@767: } n@767: if (passed == false) n@767: { n@767: check_pass = false; n@767: console.log("Continue listening to track-"+i); n@767: error_obj.push(i); n@767: } n@767: } n@767: if (check_pass == false) n@767: { n@767: var str_start = "You have not listened to fragments "; n@767: for (var i=0; i