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