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