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