b@1608: /** b@1608: * ape.js b@1608: * Create the APE interface b@1608: */ b@1608: b@1608: var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?) b@1608: // preTest - In preTest state b@1608: // testRun-ID - In test running, test Id number at the end 'testRun-2' b@1608: // testRunPost-ID - Post test of test ID b@1608: // testRunPre-ID - Pre-test of test ID b@1608: // postTest - End of test, final submission! b@1608: b@1608: b@1608: // Once this is loaded and parsed, begin execution b@1608: loadInterface(projectXML); b@1608: b@1608: function loadInterface(xmlDoc) { b@1608: b@1608: // Get the dimensions of the screen available to the page b@1608: var width = window.innerWidth; b@1608: var height = window.innerHeight; b@1608: b@1608: // The injection point into the HTML page b@1608: var insertPoint = document.getElementById("topLevelBody"); b@1608: var testContent = document.createElement('div'); b@1608: testContent.id = 'testContent'; b@1608: b@1608: b@1608: // Decode parts of the xmlDoc that are needed b@1608: // xmlDoc MUST already be parsed by jQuery! b@1608: var xmlSetup = xmlDoc.find('setup'); b@1608: // Should put in an error function here incase of malprocessed or malformed XML b@1608: b@1608: // Extract the different test XML DOM trees b@1608: var audioHolders = xmlDoc.find('audioHolder'); b@1608: audioHolders.each(function(index,element) { b@1608: var repeatN = element.attributes['repeatCount'].value; b@1608: for (var r=0; r<=repeatN; r++) { b@1608: testXMLSetups[testXMLSetups.length] = element; b@1608: } b@1608: }); b@1608: b@1608: // New check if we need to randomise the test order b@1608: var randomise = xmlSetup[0].attributes['randomiseOrder']; b@1608: if (randomise != undefined) { b@1608: randomise = Boolean(randomise.value); b@1608: } else { b@1608: randomise = false; b@1608: } b@1608: if (randomise) b@1608: { b@1608: testXMLSetups = randomiseOrder(testXMLSetups); b@1608: } b@1608: b@1608: // Obtain the metrics enabled b@1608: var metricNode = xmlSetup.find('Metric'); b@1608: var metricNode = metricNode.find('metricEnable'); b@1608: metricNode.each(function(index,node){ b@1608: var enabled = node.textContent; b@1608: switch(enabled) b@1608: { b@1608: case 'testTimer': b@1608: sessionMetrics.prototype.enableTestTimer = true; b@1608: break; b@1608: case 'elementTimer': b@1608: sessionMetrics.prototype.enableElementTimer = true; b@1608: break; b@1608: case 'elementTracker': b@1608: sessionMetrics.prototype.enableElementTracker = true; b@1608: break; b@1608: case 'elementInitalPosition': b@1608: sessionMetrics.prototype.enableElementInitialPosition = true; b@1608: break; b@1608: case 'elementFlagListenedTo': b@1608: sessionMetrics.prototype.enableFlagListenedTo = true; b@1608: break; b@1608: case 'elementFlagMoved': b@1608: sessionMetrics.prototype.enableFlagMoved = true; b@1608: break; b@1608: case 'elementFlagComments': b@1608: sessionMetrics.prototype.enableFlagComments = true; b@1608: break; b@1608: } b@1608: }); b@1608: b@1608: // Create APE specific metric functions b@1608: audioEngineContext.metric.initialiseTest = function() b@1608: { b@1608: var sliders = document.getElementsByClassName('track-slider'); b@1608: for (var i=0; i= 0) b@1608: { b@1608: audioEngineContext.audioObjects[this.lastClicked].metric.listening(time); b@1608: } b@1608: this.lastClicked = id; b@1608: audioEngineContext.audioObjects[id].metric.listening(time); b@1608: } b@1608: }; b@1608: b@1608: // Create the top div for the Title element b@1608: var titleAttr = xmlSetup[0].attributes['title']; b@1608: var title = document.createElement('div'); b@1608: title.className = "title"; b@1608: title.align = "center"; b@1608: var titleSpan = document.createElement('span'); b@1608: b@1608: // Set title to that defined in XML, else set to default b@1608: if (titleAttr != undefined) { b@1608: titleSpan.innerHTML = titleAttr.value; b@1608: } else { b@1608: titleSpan.innerHTML = 'Listening test'; b@1608: } b@1608: // Insert the titleSpan element into the title div element. b@1608: title.appendChild(titleSpan); b@1608: b@1608: var pagetitle = document.createElement('div'); b@1608: pagetitle.className = "pageTitle"; b@1608: pagetitle.align = "center"; b@1608: var titleSpan = document.createElement('span'); b@1608: titleSpan.id = "pageTitle"; b@1608: pagetitle.appendChild(titleSpan); b@1608: b@1608: // Store the return URL path in global projectReturn b@1608: projectReturn = xmlSetup[0].attributes['projectReturn'].value; b@1608: b@1608: // Create Interface buttons! b@1608: var interfaceButtons = document.createElement('div'); b@1608: interfaceButtons.id = 'interface-buttons'; b@1608: b@1608: // MANUAL DOWNLOAD POINT b@1608: // If project return is null, this MUST be specified as the location to create the download link b@1608: var downloadPoint = document.createElement('div'); b@1608: downloadPoint.id = 'download-point'; b@1608: b@1608: // Create playback start/stop points b@1608: var playback = document.createElement("button"); b@1609: playback.innerHTML = 'Stop'; b@1608: playback.id = 'playback-button'; b@1608: // onclick function. Check if it is playing or not, call the correct function in the b@1608: // audioEngine, change the button text to reflect the next state. b@1608: playback.onclick = function() { b@1609: if (audioEngineContext.status == 1) { b@1609: audioEngineContext.stop(); b@1608: this.innerHTML = 'Stop'; b@1608: } b@1608: }; b@1608: // Create Submit (save) button b@1608: var submit = document.createElement("button"); b@1608: submit.innerHTML = 'Submit'; b@1608: submit.onclick = buttonSubmitClick; b@1608: submit.id = 'submit-button'; b@1608: // Append the interface buttons into the interfaceButtons object. b@1608: interfaceButtons.appendChild(playback); b@1608: interfaceButtons.appendChild(submit); b@1608: interfaceButtons.appendChild(downloadPoint); b@1608: b@1608: // Now create the slider and HTML5 canvas boxes b@1608: b@1608: // Create the div box to center align b@1608: var sliderBox = document.createElement('div'); b@1608: sliderBox.className = 'sliderCanvasDiv'; b@1608: sliderBox.id = 'sliderCanvasHolder'; b@1608: sliderBox.align = 'center'; b@1608: b@1608: // Create the slider box to hold the slider elements b@1608: var canvas = document.createElement('div'); b@1608: canvas.id = 'slider'; b@1608: // Must have a known EXACT width, as this is used later to determine the ratings b@1608: canvas.style.width = width - 100 +"px"; b@1608: canvas.align = "left"; b@1608: sliderBox.appendChild(canvas); b@1608: b@1608: // Create the div to hold any scale objects b@1608: var scale = document.createElement('div'); b@1608: scale.className = 'sliderScale'; b@1608: scale.id = 'sliderScaleHolder'; b@1608: scale.align = 'left'; b@1608: sliderBox.appendChild(scale); b@1608: b@1608: // Global parent for the comment boxes on the page b@1608: var feedbackHolder = document.createElement('div'); b@1608: feedbackHolder.id = 'feedbackHolder'; b@1608: b@1608: testContent.style.zIndex = 1; b@1608: insertPoint.innerHTML = null; // Clear the current schema b@1608: b@1608: // Create pre and post test questions b@1608: var blank = document.createElement('div'); b@1608: blank.className = 'testHalt'; b@1608: b@1608: var popupHolder = document.createElement('div'); b@1608: popupHolder.id = 'popupHolder'; b@1608: popupHolder.className = 'popupHolder'; b@1608: popupHolder.style.position = 'absolute'; b@1608: popupHolder.style.left = (window.innerWidth/2)-250 + 'px'; b@1608: popupHolder.style.top = (window.innerHeight/2)-125 + 'px'; b@1608: insertPoint.appendChild(popupHolder); b@1608: insertPoint.appendChild(blank); b@1608: hidePopup(); b@1608: b@1608: var preTest = xmlSetup.find('PreTest'); b@1608: var postTest = xmlSetup.find('PostTest'); b@1608: preTest = preTest[0]; b@1608: postTest = postTest[0]; b@1608: b@1608: currentState = 'preTest'; b@1608: b@1608: // Create Pre-Test Box nickjillings@1612: if (preTest != undefined && preTest.childElementCount >= 1) b@1608: { b@1608: showPopup(); b@1608: preTestPopupStart(preTest); b@1608: } b@1608: b@1608: // Inject into HTML b@1608: testContent.appendChild(title); // Insert the title b@1608: testContent.appendChild(pagetitle); b@1608: testContent.appendChild(interfaceButtons); b@1608: testContent.appendChild(sliderBox); b@1608: testContent.appendChild(feedbackHolder); b@1608: insertPoint.appendChild(testContent); b@1608: b@1608: // Load the full interface b@1608: b@1608: } b@1608: b@1608: function loadTest(id) b@1608: { b@1608: // Used to load a specific test page b@1608: var textXML = testXMLSetups[id]; b@1608: b@1608: var feedbackHolder = document.getElementById('feedbackHolder'); b@1608: var canvas = document.getElementById('slider'); b@1608: feedbackHolder.innerHTML = null; b@1608: canvas.innerHTML = null; b@1608: b@1608: // Setup question title b@1608: var interfaceObj = $(textXML).find('interface'); b@1608: var titleNode = interfaceObj.find('title'); b@1608: if (titleNode[0] != undefined) b@1608: { b@1608: document.getElementById('pageTitle').textContent = titleNode[0].textContent; b@1608: } b@1608: var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2); b@1608: var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8 b@1608: // TODO: AUTOMATE ABOVE!! b@1608: var scale = document.getElementById('sliderScaleHolder'); b@1608: scale.innerHTML = null; b@1608: interfaceObj.find('scale').each(function(index,scaleObj){ b@1608: var position = Number(scaleObj.attributes['position'].value)*0.01; b@1608: var pixelPosition = (position*positionScale)+offset; b@1608: var scaleDOM = document.createElement('span'); b@1608: scaleDOM.textContent = scaleObj.textContent; b@1608: scale.appendChild(scaleDOM); b@1608: scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px'; b@1608: }); b@1608: b@1608: // Extract the hostURL attribute. If not set, create an empty string. b@1608: var hostURL = textXML.attributes['hostURL']; b@1608: if (hostURL == undefined) { b@1608: hostURL = ""; b@1608: } else { b@1608: hostURL = hostURL.value; b@1608: } b@1608: // Extract the sampleRate. If set, convert the string to a Number. b@1608: var hostFs = textXML.attributes['sampleRate']; b@1608: if (hostFs != undefined) { b@1608: hostFs = Number(hostFs.value); b@1608: } b@1608: b@1608: /// CHECK FOR SAMPLE RATE COMPATIBILITY b@1608: if (hostFs != undefined) { b@1608: if (Number(hostFs) != audioContext.sampleRate) { b@1608: var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; b@1608: alert(errStr); b@1608: return; b@1608: } b@1608: } b@1608: b@1608: var commentShow = textXML.attributes['elementComments']; b@1608: if (commentShow != undefined) { b@1608: if (commentShow.value == 'false') {commentShow = false;} b@1608: else {commentShow = true;} b@1608: } else {commentShow = true;} b@1608: b@1608: var loopPlayback = textXML.attributes['loop']; b@1608: if (loopPlayback != undefined) b@1608: { b@1608: loopPlayback = loopPlayback.value; b@1608: if (loopPlayback == 'true') { b@1608: loopPlayback = true; b@1608: } else { b@1608: loopPlayback = false; b@1608: } b@1608: } else { b@1608: loopPlayback = false; b@1608: } b@1608: audioEngineContext.loopPlayback = loopPlayback; b@1608: b@1608: // Create AudioEngine bindings for playback b@1608: if (loopPlayback) { b@1608: audioEngineContext.play = function() { b@1608: // Send play command to all playback buffers for synchronised start b@1608: // Also start timer callbacks to detect if playback has finished b@1608: if (this.status == 0) { b@1608: this.timer.startTest(); b@1608: // First get current clock b@1608: var timer = audioContext.currentTime; b@1608: // Add 3 seconds b@1608: timer += 3.0; b@1608: // Send play to all tracks b@1608: for (var i=0; i'; b@1608: trackSliderObj.draggable = true; b@1608: trackSliderObj.ondragend = dragEnd; b@1608: trackSliderObj.ondragstart = function() b@1608: { b@1608: var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99! b@1608: audioEngineContext.metric.sliderMoveStart(id); b@1608: }; b@1608: b@1608: // Onclick, switch playback to that track b@1608: trackSliderObj.onclick = function() { b@1608: // Get the track ID from the object ID b@1608: var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99! b@1608: audioEngineContext.metric.sliderPlayed(id); b@1608: audioEngineContext.selectedTrack(id); b@1608: // Currently playing track red, rest green b@1608: document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; b@1608: for (var i = 0; i<$(currentTrackOrder).length; i++) b@1608: { b@1610: if (i!=index) // Make all other sliders green b@1608: { b@1608: document.getElementById('track-slider-'+i).style.backgroundColor = "rgb(100,200,100)"; b@1608: } b@1608: b@1608: } b@1609: audioEngineContext.play(); b@1608: }; b@1608: b@1608: canvas.appendChild(trackSliderObj); b@1610: b@1608: }); b@1608: b@1608: // Append any commentQuestion boxes b@1608: var commentQuestions = $(textXML).find('CommentQuestion'); b@1608: $(commentQuestions).each(function(index,element) { b@1608: // Create document objects to hold the comment boxes b@1608: var trackComment = document.createElement('div'); b@1608: trackComment.className = 'comment-div commentQuestion'; b@1608: trackComment.id = element.attributes['id'].value; b@1608: // Create a string next to each comment asking for a comment b@1608: var trackString = document.createElement('span'); b@1608: trackString.innerHTML = element.textContent; b@1608: // Create the HTML5 comment box 'textarea' b@1608: var trackCommentBox = document.createElement('textarea'); b@1608: trackCommentBox.rows = '4'; b@1608: trackCommentBox.cols = '100'; b@1608: trackCommentBox.name = 'commentQuestion'+index; b@1608: trackCommentBox.className = 'trackComment'; b@1608: var br = document.createElement('br'); b@1608: // Add to the holder. b@1608: trackComment.appendChild(trackString); b@1608: trackComment.appendChild(br); b@1608: trackComment.appendChild(trackCommentBox); b@1608: feedbackHolder.appendChild(trackComment); b@1608: }); b@1608: b@1608: // Now process any pre-test commands b@1608: b@1608: var preTest = $(testXMLSetups[id]).find('PreTest')[0]; nickjillings@1612: if (preTest.childElementCount > 0) b@1608: { b@1608: currentState = 'testRunPre-'+id; b@1608: preTestPopupStart(preTest); b@1608: showPopup(); b@1608: } else { b@1608: currentState = 'testRun-'+id; b@1608: } b@1608: } b@1608: b@1608: function preTestPopupStart(preTest) b@1608: { b@1608: var popupHolder = document.getElementById('popupHolder'); b@1608: popupHolder.innerHTML = null; b@1608: // Parse the first box b@1608: var preTestOption = document.createElement('div'); b@1608: preTestOption.id = 'preTest'; b@1608: preTestOption.style.marginTop = '25px'; b@1608: preTestOption.align = "center"; nickjillings@1612: var child = $(preTest).children()[0]; b@1608: if (child.nodeName == 'statement') b@1608: { nickjillings@1612: preTestOption.innerHTML = ''+child.textContent+''; b@1608: } else if (child.nodeName == 'question') b@1608: { b@1608: var questionId = child.attributes['id'].value; b@1608: var textHold = document.createElement('span'); nickjillings@1612: textHold.innerHTML = child.textContent; b@1608: textHold.id = questionId + 'response'; b@1608: var textEnter = document.createElement('textarea'); b@1608: preTestOption.appendChild(textHold); b@1608: preTestOption.appendChild(textEnter); b@1608: } b@1608: var nextButton = document.createElement('button'); b@1608: nextButton.className = 'popupButton'; b@1608: nextButton.value = '0'; b@1608: nextButton.innerHTML = 'Next'; b@1608: nextButton.onclick = popupButtonClick; b@1608: b@1608: popupHolder.appendChild(preTestOption); b@1608: popupHolder.appendChild(nextButton); b@1608: } b@1608: b@1608: function popupButtonClick() b@1608: { b@1608: // Global call from the 'Next' button click b@1608: if (currentState == 'preTest') b@1608: { b@1608: // At the start of the preTest routine! b@1608: var xmlTree = projectXML.find('setup'); b@1608: var preTest = xmlTree.find('PreTest')[0]; b@1608: this.value = preTestButtonClick(preTest,this.value); b@1608: } else if (currentState.substr(0,10) == 'testRunPre') b@1608: { b@1608: //Specific test pre-test b@1608: var testId = currentState.substr(11,currentState.length-10); b@1608: var preTest = $(testXMLSetups[testId]).find('PreTest')[0]; b@1608: this.value = preTestButtonClick(preTest,this.value); b@1608: } else if (currentState.substr(0,11) == 'testRunPost') b@1608: { b@1608: // Specific test post-test b@1608: var testId = currentState.substr(12,currentState.length-11); b@1608: var preTest = $(testXMLSetups[testId]).find('PostTest')[0]; b@1608: this.value = preTestButtonClick(preTest,this.value); b@1608: } else if (currentState == 'postTest') b@1608: { b@1608: // At the end of the test, running global post test b@1608: var xmlTree = projectXML.find('setup'); b@1608: var PostTest = xmlTree.find('PostTest')[0]; b@1608: this.value = preTestButtonClick(PostTest,this.value); b@1608: } b@1608: } b@1608: b@1608: function preTestButtonClick(preTest,index) b@1608: { b@1608: // Called on click of pre-test button b@1608: // Need to find and parse preTest again! b@1608: var preTestOption = document.getElementById('preTest'); b@1608: // Check if current state is a question! nickjillings@1612: if ($(preTest).children()[index].nodeName == 'question') { nickjillings@1612: var questionId = $(preTest).children()[index].attributes['id'].value; b@1608: var questionHold = document.createElement('comment'); b@1608: var questionResponse = document.getElementById(questionId + 'response'); nickjillings@1612: var mandatory = $(preTest).children()[index].attributes['mandatory']; b@1608: if (mandatory != undefined){ b@1608: if (mandatory.value == 'true') {mandatory = true;} b@1608: else {mandatory = false;} b@1608: } else {mandatory = false;} b@1608: if (mandatory == true && questionResponse.value.length == 0) { b@1608: return index; b@1608: } b@1608: questionHold.id = questionId; b@1608: questionHold.innerHTML = questionResponse.value; b@1608: postPopupResponse(questionHold); b@1608: } b@1608: index++; nickjillings@1612: if (index < preTest.childElementCount) b@1608: { b@1608: // More to process nickjillings@1612: var child = $(preTest).children()[index]; b@1608: if (child.nodeName == 'statement') b@1608: { nickjillings@1612: preTestOption.innerHTML = ''+child.textContent+''; b@1608: } else if (child.nodeName == 'question') b@1608: { b@1608: var textHold = document.createElement('span'); nickjillings@1612: textHold.innerHTML = child.textContent; b@1608: var textEnter = document.createElement('textarea'); b@1608: textEnter.id = child.attributes['id'].value + 'response'; b@1608: var br = document.createElement('br'); b@1608: preTestOption.innerHTML = null; b@1608: preTestOption.appendChild(textHold); b@1608: preTestOption.appendChild(br); b@1608: preTestOption.appendChild(textEnter); b@1608: } b@1608: } else { b@1608: // Time to clear b@1608: preTestOption.innerHTML = null; b@1608: if (currentState != 'postTest') { b@1608: hidePopup(); b@1608: // Progress the state! b@1608: advanceState(); b@1608: } else { b@1608: a = createProjectSave(projectReturn); b@1608: preTestOption.appendChild(a); b@1608: } b@1608: } b@1608: return index; b@1608: } b@1608: b@1608: function postPopupResponse(response) b@1608: { b@1608: if (currentState == 'preTest') { b@1608: preTestQuestions.appendChild(response); b@1608: } else if (currentState == 'postTest') { b@1608: postTestQuestions.appendChild(response); b@1608: } else { b@1608: // Inside a specific test b@1608: if (currentState.substr(0,10) == 'testRunPre') { b@1608: // Pre Test b@1608: var store = $(currentTestHolder).find('preTest'); b@1608: } else { b@1608: // Post Test b@1608: var store = $(currentTestHolder).find('postTest'); b@1608: } b@1608: store[0].appendChild(response); b@1608: } b@1608: } b@1608: b@1608: function showPopup() b@1608: { b@1608: var popupHolder = document.getElementById('popupHolder'); b@1608: popupHolder.style.zIndex = 3; b@1608: popupHolder.style.visibility = 'visible'; b@1608: var blank = document.getElementsByClassName('testHalt')[0]; b@1608: blank.style.zIndex = 2; b@1608: blank.style.visibility = 'visible'; b@1608: } b@1608: b@1608: function hidePopup() b@1608: { b@1608: var popupHolder = document.getElementById('popupHolder'); b@1608: popupHolder.style.zIndex = -1; b@1608: popupHolder.style.visibility = 'hidden'; b@1608: var blank = document.getElementsByClassName('testHalt')[0]; b@1608: blank.style.zIndex = -2; b@1608: blank.style.visibility = 'hidden'; b@1608: } b@1608: b@1608: function dragEnd(ev) { b@1608: // Function call when a div has been dropped b@1608: var slider = document.getElementById('slider'); b@1608: var w = slider.style.width; b@1608: w = Number(w.substr(0,w.length-2)); b@1608: var x = ev.x; b@1608: if (x >= 42 && x < w+42) { b@1608: this.style.left = (x)+'px'; b@1608: } else { b@1608: if (x<42) { b@1608: this.style.left = '42px'; b@1608: } else { b@1608: this.style.left = (w+42) + 'px'; b@1608: } b@1608: } b@1608: audioEngineContext.metric.sliderMoved(); b@1608: } b@1608: b@1608: function advanceState() b@1608: { b@1608: console.log(currentState); b@1608: if (currentState == 'preTest') b@1608: { b@1608: // End of pre-test, begin the test b@1608: loadTest(0); b@1608: } else if (currentState.substr(0,10) == 'testRunPre') b@1608: { b@1608: // Start the test b@1608: var testId = currentState.substr(11,currentState.length-10); b@1608: currentState = 'testRun-'+testId; nickjillings@1614: //audioEngineContext.timer.startTest(); nickjillings@1614: audioEngineContext.play(); b@1608: } else if (currentState.substr(0,11) == 'testRunPost') b@1608: { b@1608: var testId = currentState.substr(12,currentState.length-11); b@1608: testEnded(testId); b@1608: } else if (currentState.substr(0,7) == 'testRun') b@1608: { b@1608: var testId = currentState.substr(8,currentState.length-7); b@1608: // Check if we have any post tests to perform b@1608: var postXML = $(testXMLSetups[testId]).find('PostTest')[0]; b@1608: if (postXML == undefined) { b@1608: testEnded(testId); b@1608: } nickjillings@1612: else if (postXML.childElementCount > 0) b@1608: { b@1608: currentState = 'testRunPost-'+testId; b@1608: showPopup(); b@1608: preTestPopupStart(postXML); b@1608: } b@1608: else { b@1608: b@1608: b@1608: // No post tests, check if we have another test to perform instead b@1608: b@1608: } b@1608: } b@1608: console.log(currentState); b@1608: } b@1608: b@1608: function testEnded(testId) b@1608: { b@1608: pageXMLSave(testId); b@1608: if (testXMLSetups.length-1 > testId) b@1608: { b@1608: // Yes we have another test to perform b@1608: testId = (Number(testId)+1); b@1608: currentState = 'testRun-'+testId; b@1608: loadTest(testId); b@1608: } else { b@1608: console.log('Testing Completed!'); b@1608: currentState = 'postTest'; b@1608: // Check for any post tests b@1608: var xmlSetup = projectXML.find('setup'); b@1608: var postTest = xmlSetup.find('PostTest')[0]; b@1608: showPopup(); b@1608: preTestPopupStart(postTest); b@1608: } b@1608: } b@1608: b@1609: function buttonSubmitClick() // TODO: Only when all songs have been played! b@1608: { nickjillings@1614: hasBeenPlayed = audioEngineContext.checkAllPlayed(); nickjillings@1614: if (hasBeenPlayed.length == 0) { nickjillings@1614: if (audioEngineContext.status == 1) { nickjillings@1614: var playback = document.getElementById('playback-button'); nickjillings@1614: playback.click(); nickjillings@1614: // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options nickjillings@1614: } else nickjillings@1614: { nickjillings@1614: if (audioEngineContext.timer.testStarted == false) nickjillings@1614: { nickjillings@1614: alert('You have not started the test! Please press start to begin the test!'); nickjillings@1614: return; nickjillings@1614: } nickjillings@1614: } nickjillings@1614: if (currentState.substr(0,7) == 'testRun') nickjillings@1614: { nickjillings@1614: hasBeenPlayed = []; // clear array to prepare for next test nickjillings@1614: audioEngineContext.timer.stopTest(); nickjillings@1614: advanceState(); nickjillings@1614: } b@1610: } else // if a fragment has not been played yet b@1610: { nickjillings@1614: str = ""; nickjillings@1614: if (hasBeenPlayed.length > 1) { nickjillings@1614: for (var i=0; i