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