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 audio engine object nickjillings@1404: audioEngineContext = new AudioEngine(); 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@1404: function interfacePopup() { nickjillings@1404: // Creates an object to manage the popup nickjillings@1404: this.popup = null; nickjillings@1404: this.popupContent = null; nickjillings@1404: this.popupTitle = null; nickjillings@1404: this.popupResponse = null; nickjillings@1404: this.buttonProceed = null; nickjillings@1404: this.buttonPrevious = null; nickjillings@1404: this.popupOptions = null; nickjillings@1404: this.currentIndex = null; nickjillings@1404: this.responses = null; nickjillings@1404: nickjillings@1404: this.createPopup = function(){ nickjillings@1404: // Create popup window interface nickjillings@1404: var insertPoint = document.getElementById("topLevelBody"); nickjillings@1404: var blank = document.createElement('div'); nickjillings@1404: blank.className = 'testHalt'; nickjillings@1404: nickjillings@1404: this.popup = document.createElement('div'); nickjillings@1404: this.popup.id = 'popupHolder'; nickjillings@1404: this.popup.className = 'popupHolder'; nickjillings@1404: this.popup.style.position = 'absolute'; nickjillings@1404: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; nickjillings@1404: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; nickjillings@1404: nickjillings@1404: this.popupContent = document.createElement('div'); nickjillings@1404: this.popupContent.id = 'popupContent'; nickjillings@1404: this.popupContent.style.marginTop = '20px'; nickjillings@1404: this.popupContent.style.marginBottom = '5px'; nickjillings@1404: this.popup.appendChild(this.popupContent); nickjillings@1404: nickjillings@1404: var titleHolder = document.createElement('div'); nickjillings@1404: titleHolder.id = 'popupTitleHolder'; nickjillings@1404: titleHolder.align = 'center'; nickjillings@1404: titleHolder.style.width = 'inherit'; nickjillings@1404: titleHolder.style.minHeight = '25px'; nickjillings@1404: titleHolder.style.maxHeight = '250px'; nickjillings@1404: titleHolder.style.overflow = 'auto'; nickjillings@1404: titleHolder.style.marginBottom = '5px'; nickjillings@1404: nickjillings@1404: this.popupTitle = document.createElement('span'); nickjillings@1404: this.popupTitle.id = 'popupTitle'; nickjillings@1404: titleHolder.appendChild(this.popupTitle); nickjillings@1404: this.popupContent.appendChild(titleHolder); nickjillings@1404: nickjillings@1404: this.popupResponse = document.createElement('div'); nickjillings@1404: this.popupResponse.id = 'popupResponse'; nickjillings@1404: this.popupResponse.align = 'center'; nickjillings@1404: this.popupResponse.style.width = 'inherit'; nickjillings@1404: this.popupResponse.style.minHeight = '50px'; nickjillings@1404: this.popupResponse.style.maxHeight = '320px'; nickjillings@1404: this.popupResponse.style.overflow = 'auto'; nickjillings@1404: this.popupContent.appendChild(this.popupResponse); nickjillings@1404: nickjillings@1404: this.buttonProceed = document.createElement('button'); nickjillings@1404: this.buttonProceed.className = 'popupButton'; nickjillings@1404: this.buttonProceed.position = 'relative'; nickjillings@1404: this.buttonProceed.style.left = '390px'; nickjillings@1404: this.buttonProceed.innerHTML = 'Next'; nickjillings@1404: this.buttonProceed.onclick = function(){popup.proceedClicked();}; nickjillings@1404: nickjillings@1404: this.buttonPrevious = document.createElement('button'); nickjillings@1404: this.buttonPrevious.className = 'popupButton'; nickjillings@1404: this.buttonPrevious.position = 'relative'; nickjillings@1404: this.buttonPrevious.style.left = '10px'; nickjillings@1404: this.buttonPrevious.innerHTML = 'Back'; nickjillings@1404: this.buttonPrevious.onclick = function(){popup.previousClick();}; nickjillings@1404: nickjillings@1404: this.popupContent.appendChild(this.buttonPrevious); nickjillings@1404: this.popupContent.appendChild(this.buttonProceed); nickjillings@1404: nickjillings@1404: this.popup.style.zIndex = -1; nickjillings@1404: this.popup.style.visibility = 'hidden'; nickjillings@1404: blank.style.zIndex = -2; nickjillings@1404: blank.style.visibility = 'hidden'; nickjillings@1404: insertPoint.appendChild(this.popup); nickjillings@1404: insertPoint.appendChild(blank); nickjillings@1404: }; nickjillings@1404: nickjillings@1404: this.showPopup = function(){ nickjillings@1404: if (this.popup == null) { nickjillings@1404: this.createPopup(); nickjillings@1404: } nickjillings@1404: this.popup.style.zIndex = 3; nickjillings@1404: this.popup.style.visibility = 'visible'; nickjillings@1404: var blank = document.getElementsByClassName('testHalt')[0]; nickjillings@1404: blank.style.zIndex = 2; nickjillings@1404: blank.style.visibility = 'visible'; nickjillings@1404: $(window).keypress(function(e){ nickjillings@1404: if (e.keyCode == 13 && popup.popup.style.visibility == 'visible') nickjillings@1404: { nickjillings@1404: popup.buttonProceed.onclick(); nickjillings@1404: } nickjillings@1404: }); nickjillings@1404: }; nickjillings@1404: nickjillings@1404: this.hidePopup = function(){ nickjillings@1404: this.popup.style.zIndex = -1; nickjillings@1404: this.popup.style.visibility = 'hidden'; nickjillings@1404: var blank = document.getElementsByClassName('testHalt')[0]; nickjillings@1404: blank.style.zIndex = -2; nickjillings@1404: blank.style.visibility = 'hidden'; nickjillings@1404: this.buttonPrevious.style.visibility = 'inherit'; nickjillings@1404: $(window).keypress(function(e){}); nickjillings@1404: }; nickjillings@1404: nickjillings@1404: this.postNode = function() { nickjillings@1404: // This will take the node from the popupOptions and display it nickjillings@1404: var node = this.popupOptions[this.currentIndex]; nickjillings@1404: this.popupResponse.innerHTML = null; nickjillings@1404: if (node.type == 'statement') { nickjillings@1404: this.popupTitle.textContent = null; nickjillings@1404: var statement = document.createElement('span'); nickjillings@1404: statement.textContent = node.statement; nickjillings@1404: this.popupResponse.appendChild(statement); nickjillings@1404: } else if (node.type == 'question') { nickjillings@1404: this.popupTitle.textContent = node.question; nickjillings@1404: var textArea = document.createElement('textarea'); nickjillings@1404: switch (node.boxsize) { nickjillings@1404: case 'small': nickjillings@1404: textArea.cols = "20"; nickjillings@1404: textArea.rows = "1"; nickjillings@1404: break; nickjillings@1404: case 'normal': nickjillings@1404: textArea.cols = "30"; nickjillings@1404: textArea.rows = "2"; nickjillings@1404: break; nickjillings@1404: case 'large': nickjillings@1404: textArea.cols = "40"; nickjillings@1404: textArea.rows = "5"; nickjillings@1404: break; nickjillings@1404: case 'huge': nickjillings@1404: textArea.cols = "50"; nickjillings@1404: textArea.rows = "10"; nickjillings@1404: break; nickjillings@1404: } nickjillings@1404: this.popupResponse.appendChild(textArea); nickjillings@1404: textArea.focus(); nickjillings@1404: } else if (node.type == 'checkbox') { nickjillings@1404: this.popupTitle.textContent = node.statement; nickjillings@1404: var optHold = this.popupResponse; nickjillings@1404: 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@1404: loadTest(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@1404: function testEnded(testId) nickjillings@1404: { nickjillings@1404: pageXMLSave(testId); nickjillings@1404: if (testXMLSetups.length-1 > testId) nickjillings@1404: { nickjillings@1404: // Yes we have another test to perform nickjillings@1404: testId = (Number(testId)+1); nickjillings@1404: currentState = 'testRun-'+testId; nickjillings@1404: loadTest(testId); nickjillings@1404: } else { nickjillings@1404: console.log('Testing Completed!'); nickjillings@1404: currentState = 'postTest'; nickjillings@1404: // Check for any post tests nickjillings@1404: var xmlSetup = projectXML.find('setup'); nickjillings@1404: var postTest = xmlSetup.find('PostTest')[0]; nickjillings@1404: popup.initState(postTest); nickjillings@1404: } nickjillings@1404: } nickjillings@1404: nickjillings@1404: function loadProjectSpec(url) { nickjillings@1404: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data nickjillings@1404: // If url is null, request client to upload project XML document nickjillings@1404: var r = new XMLHttpRequest(); nickjillings@1404: r.open('GET',url,true); nickjillings@1404: r.onload = function() { nickjillings@1404: loadProjectSpecCallback(r.response); nickjillings@1404: }; nickjillings@1404: r.send(); nickjillings@1404: }; nickjillings@1404: nickjillings@1404: function loadProjectSpecCallback(response) { nickjillings@1404: // Function called after asynchronous download of XML project specification nickjillings@1404: //var decode = $.parseXML(response); nickjillings@1404: //projectXML = $(decode); nickjillings@1404: nickjillings@1404: var parse = new DOMParser(); nickjillings@1404: projectXML = parse.parseFromString(response,'text/xml'); nickjillings@1404: nickjillings@1404: // Build the specification nickjillings@1404: specification.decode(); nickjillings@1404: nickjillings@1404: testState.stateMap.push(specification.preTest); nickjillings@1404: nickjillings@1404: $(specification.audioHolders).each(function(index,elem){ nickjillings@1404: testState.stateMap.push(elem); nickjillings@1404: }); nickjillings@1404: nickjillings@1404: testState.stateMap.push(specification.postTest); nickjillings@1404: nickjillings@1404: // Obtain the metrics enabled nickjillings@1404: $(specification.metrics).each(function(index,node){ nickjillings@1404: var enabled = node.textContent; nickjillings@1404: switch(node.enabled) nickjillings@1404: { nickjillings@1404: case 'testTimer': nickjillings@1404: sessionMetrics.prototype.enableTestTimer = true; nickjillings@1404: break; nickjillings@1404: case 'elementTimer': nickjillings@1404: sessionMetrics.prototype.enableElementTimer = true; nickjillings@1404: break; nickjillings@1404: case 'elementTracker': nickjillings@1404: sessionMetrics.prototype.enableElementTracker = true; nickjillings@1404: break; nickjillings@1404: case 'elementListenTracker': nickjillings@1404: sessionMetrics.prototype.enableElementListenTracker = true; nickjillings@1404: break; nickjillings@1404: case 'elementInitialPosition': nickjillings@1404: sessionMetrics.prototype.enableElementInitialPosition = true; nickjillings@1404: break; nickjillings@1404: case 'elementFlagListenedTo': nickjillings@1404: sessionMetrics.prototype.enableFlagListenedTo = true; nickjillings@1404: break; nickjillings@1404: case 'elementFlagMoved': nickjillings@1404: sessionMetrics.prototype.enableFlagMoved = true; nickjillings@1404: break; nickjillings@1404: case 'elementFlagComments': nickjillings@1404: sessionMetrics.prototype.enableFlagComments = true; nickjillings@1404: break; nickjillings@1404: } nickjillings@1404: }); nickjillings@1404: nickjillings@1404: nickjillings@1404: nickjillings@1404: // Detect the interface to use and load the relevant javascripts. nickjillings@1404: var interfaceJS = document.createElement('script'); nickjillings@1404: interfaceJS.setAttribute("type","text/javascript"); nickjillings@1404: if (specification.interfaceType == 'APE') { nickjillings@1404: interfaceJS.setAttribute("src","ape.js"); nickjillings@1404: nickjillings@1404: // APE comes with a css file nickjillings@1404: var css = document.createElement('link'); nickjillings@1404: css.rel = 'stylesheet'; nickjillings@1404: css.type = 'text/css'; nickjillings@1404: css.href = 'ape.css'; nickjillings@1404: nickjillings@1404: document.getElementsByTagName("head")[0].appendChild(css); nickjillings@1404: } else if (specification.interfaceType == "MUSHRA") nickjillings@1404: { nickjillings@1404: interfaceJS.setAttribute("src","mushra.js"); nickjillings@1404: nickjillings@1404: // MUSHRA comes with a css file nickjillings@1404: var css = document.createElement('link'); nickjillings@1404: css.rel = 'stylesheet'; nickjillings@1404: css.type = 'text/css'; nickjillings@1404: css.href = 'mushra.css'; nickjillings@1404: nickjillings@1404: document.getElementsByTagName("head")[0].appendChild(css); nickjillings@1404: } nickjillings@1404: document.getElementsByTagName("head")[0].appendChild(interfaceJS); nickjillings@1404: nickjillings@1404: // Define window callbacks for interface nickjillings@1404: window.onresize = function(event){interfaceContext.resizeWindow(event);}; nickjillings@1404: } nickjillings@1404: nickjillings@1404: function createProjectSave(destURL) { nickjillings@1404: // Save the data from interface into XML and send to destURL nickjillings@1404: // If destURL is null then download XML in client nickjillings@1404: // Now time to render file locally nickjillings@1404: var xmlDoc = interfaceXMLSave(); nickjillings@1404: var parent = document.createElement("div"); nickjillings@1404: parent.appendChild(xmlDoc); nickjillings@1404: var file = [parent.innerHTML]; nickjillings@1404: if (destURL == "null" || destURL == undefined) { nickjillings@1404: var bb = new Blob(file,{type : 'application/xml'}); nickjillings@1404: var dnlk = window.URL.createObjectURL(bb); nickjillings@1404: var a = document.createElement("a"); nickjillings@1404: a.hidden = ''; nickjillings@1404: a.href = dnlk; nickjillings@1404: a.download = "save.xml"; nickjillings@1404: a.textContent = "Save File"; nickjillings@1404: nickjillings@1404: popup.showPopup(); nickjillings@1404: popup.popupContent.innerHTML = null; nickjillings@1404: popup.popupContent.appendChild(a); nickjillings@1404: } else { nickjillings@1404: var xmlhttp = new XMLHttpRequest; nickjillings@1404: xmlhttp.open("POST",destURL,true); nickjillings@1404: xmlhttp.setRequestHeader('Content-Type', 'text/xml'); nickjillings@1404: xmlhttp.onerror = function(){ nickjillings@1404: console.log('Error saving file to server! Presenting download locally'); nickjillings@1404: createProjectSave(null); nickjillings@1404: }; nickjillings@1404: xmlhttp.onreadystatechange = function() { nickjillings@1404: console.log(xmlhttp.status); nickjillings@1404: if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { nickjillings@1404: createProjectSave(null); nickjillings@1404: } else { nickjillings@1404: if (xmlhttp.responseXML == null) nickjillings@1404: { nickjillings@1404: return createProjectSave(null); nickjillings@1404: } nickjillings@1404: var response = xmlhttp.responseXML.childNodes[0]; nickjillings@1404: if (response.getAttribute('state') == "OK") nickjillings@1404: { nickjillings@1404: var file = response.getElementsByTagName('file')[0]; nickjillings@1404: console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B'); nickjillings@1404: popup.showPopup(); nickjillings@1404: popup.popupContent.innerHTML = null; nickjillings@1404: popup.popupContent.textContent = "Thank you!"; nickjillings@1404: } else { nickjillings@1404: var message = response.getElementsByTagName('message')[0]; nickjillings@1404: errorSessionDump(message.textContent); nickjillings@1404: } nickjillings@1404: } nickjillings@1404: }; nickjillings@1404: xmlhttp.send(file); nickjillings@1404: } nickjillings@1404: } nickjillings@1404: nickjillings@1404: function errorSessionDump(msg){ nickjillings@1404: // Create the partial interface XML save nickjillings@1404: // Include error node with message on why the dump occured nickjillings@1404: var xmlDoc = interfaceXMLSave(); nickjillings@1404: var err = document.createElement('error'); nickjillings@1404: err.textContent = msg; nickjillings@1404: xmlDoc.appendChild(err); nickjillings@1404: var parent = document.createElement("div"); nickjillings@1404: parent.appendChild(xmlDoc); nickjillings@1404: var file = [parent.innerHTML]; nickjillings@1404: var bb = new Blob(file,{type : 'application/xml'}); nickjillings@1404: var dnlk = window.URL.createObjectURL(bb); nickjillings@1404: var a = document.createElement("a"); nickjillings@1404: a.hidden = ''; nickjillings@1404: a.href = dnlk; nickjillings@1404: a.download = "save.xml"; nickjillings@1404: a.textContent = "Save File"; nickjillings@1404: nickjillings@1404: popup.showPopup(); nickjillings@1404: popup.popupContent.innerHTML = "ERROR : "+msg; nickjillings@1404: popup.popupContent.appendChild(a); nickjillings@1404: } nickjillings@1404: nickjillings@1404: // Only other global function which must be defined in the interface class. Determines how to create the XML document. nickjillings@1404: function interfaceXMLSave(){ nickjillings@1404: // Create the XML string to be exported with results nickjillings@1404: var xmlDoc = document.createElement("BrowserEvaluationResult"); nickjillings@1404: var projectDocument = specification.projectXML; nickjillings@1404: projectDocument.setAttribute('file-name',url); nickjillings@1404: xmlDoc.appendChild(projectDocument); nickjillings@1404: xmlDoc.appendChild(returnDateNode()); nickjillings@1404: xmlDoc.appendChild(interfaceContext.returnNavigator()); 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@1404: 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@1404: this.commonInterface = null; nickjillings@1404: this.projectReturn = null; nickjillings@1404: this.randomiseOrder = null; nickjillings@1404: this.collectMetrics = null; nickjillings@1404: this.testPages = null; nickjillings@1404: this.preTest = null; nickjillings@1404: this.postTest = null; nickjillings@1404: this.metrics =[]; nickjillings@1404: nickjillings@1404: this.audioHolders = []; nickjillings@1404: nickjillings@1404: this.decode = function() { 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@1404: this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); nickjillings@1404: this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); 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@1404: Console.log("WARNING: Anchor and Reference tags in the node are depricated"); 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 1) nickjillings@1404: { this.marker /= 100.0;} nickjillings@1404: if (this.marker >= 0 && this.marker <= 1) nickjillings@1404: { nickjillings@1404: this.enforce = true; nickjillings@1404: return; nickjillings@1404: } else { nickjillings@1404: console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!"); nickjillings@1404: console.log("ERROR - Marker not enforced!"); nickjillings@1404: } nickjillings@1404: } else { nickjillings@1404: 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@1404: this.marker = false; nickjillings@1404: this.enforce = false; nickjillings@1404: }; nickjillings@1404: nickjillings@1404: this.commentQuestionNode = function(xml) { nickjillings@1404: this.childOption = function(element) { nickjillings@1404: this.type = 'option'; nickjillings@1404: this.name = element.getAttribute('name'); nickjillings@1404: this.text = element.textContent; nickjillings@1404: }; nickjillings@1404: this.id = xml.id; nickjillings@1404: if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} nickjillings@1404: else {this.mandatory = false;} nickjillings@1404: this.type = xml.getAttribute('type'); nickjillings@1404: if (this.type == undefined) {this.type = 'text';} nickjillings@1404: switch (this.type) { nickjillings@1404: case 'text': nickjillings@1404: this.question = xml.textContent; nickjillings@1404: break; nickjillings@1404: case 'radio': nickjillings@1404: var child = xml.firstElementChild; nickjillings@1404: this.options = []; nickjillings@1404: while (child != undefined) { nickjillings@1404: if (child.nodeName == 'statement' && this.statement == undefined) { nickjillings@1404: this.statement = child.textContent; nickjillings@1404: } else if (child.nodeName == 'option') { nickjillings@1404: this.options.push(new this.childOption(child)); nickjillings@1404: } nickjillings@1404: child = child.nextElementSibling; nickjillings@1404: } nickjillings@1404: break; nickjillings@1404: case 'checkbox': nickjillings@1404: var child = xml.firstElementChild; nickjillings@1404: this.options = []; nickjillings@1404: while (child != undefined) { nickjillings@1404: if (child.nodeName == 'statement' && this.statement == undefined) { nickjillings@1404: this.statement = child.textContent; nickjillings@1404: } else if (child.nodeName == 'option') { nickjillings@1404: this.options.push(new this.childOption(child)); nickjillings@1404: } nickjillings@1404: child = child.nextElementSibling; nickjillings@1404: } nickjillings@1404: break; nickjillings@1404: } nickjillings@1404: }; nickjillings@1404: nickjillings@1404: this.id = xml.id; nickjillings@1404: this.hostURL = xml.getAttribute('hostURL'); nickjillings@1404: this.sampleRate = xml.getAttribute('sampleRate'); nickjillings@1404: if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;} nickjillings@1404: else {this.randomiseOrder = false;} nickjillings@1404: this.repeatCount = xml.getAttribute('repeatCount'); nickjillings@1404: if (xml.getAttribute('loop') == 'true') {this.loop = true;} nickjillings@1404: else {this.loop == false;} nickjillings@1404: if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;} nickjillings@1404: else {this.elementComments = false;} nickjillings@1404: nickjillings@1404: this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest')); nickjillings@1404: this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest')); nickjillings@1404: nickjillings@1404: this.interfaces = []; nickjillings@1404: var interfaceDOM = xml.getElementsByTagName('interface'); nickjillings@1404: 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