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