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