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