nicholas@872: /** nicholas@872: * core.js nicholas@872: * nicholas@872: * Main script to run, calls all other core functions and manages loading/store to backend. nicholas@872: * Also contains all global variables. nicholas@872: */ nicholas@872: nicholas@872: /* create the web audio API context and store in audioContext*/ nicholas@872: var audioContext; // Hold the browser web audio API nicholas@872: var projectXML; // Hold the parsed setup XML nicholas@872: var specification; nicholas@872: var interfaceContext; nicholas@872: var popup; // Hold the interfacePopup object nicholas@872: var testState; nicholas@872: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order nicholas@872: var audioEngineContext; // The custome AudioEngine object nicholas@872: var projectReturn; // Hold the URL for the return nicholas@872: nicholas@872: nicholas@872: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it nicholas@872: AudioBufferSourceNode.prototype.owner = undefined; nicholas@872: nicholas@872: window.onload = function() { nicholas@872: // Function called once the browser has loaded all files. nicholas@872: // This should perform any initial commands such as structure / loading documents nicholas@872: nicholas@872: // Create a web audio API context nicholas@872: // Fixed for cross-browser support nicholas@872: var AudioContext = window.AudioContext || window.webkitAudioContext; nicholas@872: audioContext = new AudioContext; nicholas@872: nicholas@872: // Create test state nicholas@872: testState = new stateMachine(); nicholas@872: nicholas@872: // Create the audio engine object nicholas@872: audioEngineContext = new AudioEngine(); nicholas@872: nicholas@872: // Create the popup interface object nicholas@872: popup = new interfacePopup(); nicholas@872: nicholas@872: // Create the specification object nicholas@872: specification = new Specification(); nicholas@872: nicholas@872: // Create the interface object nicholas@872: interfaceContext = new Interface(specification); nicholas@872: }; nicholas@872: nicholas@872: function interfacePopup() { nicholas@872: // Creates an object to manage the popup nicholas@872: this.popup = null; nicholas@872: this.popupContent = null; nicholas@872: this.buttonProceed = null; nicholas@872: this.buttonPrevious = null; nicholas@872: this.popupOptions = null; nicholas@872: this.currentIndex = null; nicholas@872: this.responses = null; nicholas@872: nicholas@872: this.createPopup = function(){ nicholas@872: // Create popup window interface nicholas@872: var insertPoint = document.getElementById("topLevelBody"); nicholas@872: var blank = document.createElement('div'); nicholas@872: blank.className = 'testHalt'; nicholas@872: nicholas@872: this.popup = document.createElement('div'); nicholas@872: this.popup.id = 'popupHolder'; nicholas@872: this.popup.className = 'popupHolder'; nicholas@872: this.popup.style.position = 'absolute'; nicholas@872: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; nicholas@872: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; nicholas@872: nicholas@872: this.popupContent = document.createElement('div'); nicholas@872: this.popupContent.id = 'popupContent'; nicholas@872: this.popupContent.style.marginTop = '25px'; nicholas@872: this.popupContent.align = 'center'; nicholas@872: this.popup.appendChild(this.popupContent); nicholas@872: nicholas@872: this.buttonProceed = document.createElement('button'); nicholas@872: this.buttonProceed.className = 'popupButton'; nicholas@872: this.buttonProceed.style.left = '440px'; nicholas@872: this.buttonProceed.style.top = '215px'; nicholas@872: this.buttonProceed.innerHTML = 'Next'; nicholas@872: this.buttonProceed.onclick = function(){popup.proceedClicked();}; nicholas@872: nicholas@872: this.buttonPrevious = document.createElement('button'); nicholas@872: this.buttonPrevious.className = 'popupButton'; nicholas@872: this.buttonPrevious.style.left = '10px'; nicholas@872: this.buttonPrevious.style.top = '215px'; nicholas@872: this.buttonPrevious.innerHTML = 'Back'; nicholas@872: this.buttonPrevious.onclick = function(){popup.previousClick();}; nicholas@872: nicholas@872: this.popup.style.zIndex = -1; nicholas@872: this.popup.style.visibility = 'hidden'; nicholas@872: blank.style.zIndex = -2; nicholas@872: blank.style.visibility = 'hidden'; nicholas@872: insertPoint.appendChild(this.popup); nicholas@872: insertPoint.appendChild(blank); nicholas@872: }; nicholas@872: nicholas@872: this.showPopup = function(){ nicholas@872: if (this.popup == null) { nicholas@872: this.createPopup(); nicholas@872: } nicholas@872: this.popup.style.zIndex = 3; nicholas@872: this.popup.style.visibility = 'visible'; nicholas@872: var blank = document.getElementsByClassName('testHalt')[0]; nicholas@872: blank.style.zIndex = 2; nicholas@872: blank.style.visibility = 'visible'; nicholas@872: }; nicholas@872: nicholas@872: this.hidePopup = function(){ nicholas@872: this.popup.style.zIndex = -1; nicholas@872: this.popup.style.visibility = 'hidden'; nicholas@872: var blank = document.getElementsByClassName('testHalt')[0]; nicholas@872: blank.style.zIndex = -2; nicholas@872: blank.style.visibility = 'hidden'; nicholas@872: }; nicholas@872: nicholas@872: this.postNode = function() { nicholas@872: // This will take the node from the popupOptions and display it nicholas@872: var node = this.popupOptions[this.currentIndex]; nicholas@872: this.popupContent.innerHTML = null; nicholas@872: if (node.type == 'statement') { nicholas@872: var span = document.createElement('span'); nicholas@872: span.textContent = node.statement; nicholas@872: this.popupContent.appendChild(span); nicholas@872: } else if (node.type == 'question') { nicholas@872: var span = document.createElement('span'); nicholas@872: span.textContent = node.question; nicholas@872: var textArea = document.createElement('textarea'); nicholas@872: switch (node.boxsize) { nicholas@872: case 'small': nicholas@872: textArea.cols = "20"; nicholas@872: textArea.rows = "1"; nicholas@872: break; nicholas@872: case 'normal': nicholas@872: textArea.cols = "30"; nicholas@872: textArea.rows = "2"; nicholas@872: break; nicholas@872: case 'large': nicholas@872: textArea.cols = "40"; nicholas@872: textArea.rows = "5"; nicholas@872: break; nicholas@872: case 'huge': nicholas@872: textArea.cols = "50"; nicholas@872: textArea.rows = "10"; nicholas@872: break; nicholas@872: } nicholas@872: var br = document.createElement('br'); nicholas@872: this.popupContent.appendChild(span); nicholas@872: this.popupContent.appendChild(br); nicholas@872: this.popupContent.appendChild(textArea); nicholas@872: this.popupContent.childNodes[2].focus(); nicholas@872: } else if (node.type == 'checkbox') { nicholas@872: var span = document.createElement('span'); nicholas@872: span.textContent = node.statement; nicholas@872: this.popupContent.appendChild(span); nicholas@872: var optHold = document.createElement('div'); nicholas@872: optHold.id = 'option-holder'; nicholas@872: optHold.align = 'left'; nicholas@872: for (var i=0; i 0) nicholas@872: this.popupContent.appendChild(this.buttonPrevious); nicholas@872: }; nicholas@872: nicholas@872: this.initState = function(node) { nicholas@872: //Call this with your preTest and postTest nodes when needed to nicholas@872: // initialise the popup procedure. nicholas@872: this.popupOptions = node.options; nicholas@872: if (this.popupOptions.length > 0) { nicholas@872: if (node.type == 'pretest') { nicholas@872: this.responses = document.createElement('PreTest'); nicholas@872: } else if (node.type == 'posttest') { nicholas@872: this.responses = document.createElement('PostTest'); nicholas@872: } else { nicholas@872: console.log ('WARNING - popup node neither pre or post!'); nicholas@872: this.responses = document.createElement('responses'); nicholas@872: } nicholas@872: this.currentIndex = 0; nicholas@872: this.showPopup(); nicholas@872: this.postNode(); nicholas@872: } else { nicholas@872: advanceState(); nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: this.proceedClicked = function() { nicholas@872: // Each time the popup button is clicked! nicholas@872: var node = this.popupOptions[this.currentIndex]; nicholas@872: if (node.type == 'question') { nicholas@872: // Must extract the question data nicholas@872: var textArea = $(popup.popupContent).find('textarea')[0]; nicholas@872: if (node.mandatory == true && textArea.value.length == 0) { nicholas@872: alert('This question is mandatory'); nicholas@872: return; nicholas@872: } else { nicholas@872: // Save the text content nicholas@872: var hold = document.createElement('comment'); nicholas@872: hold.id = node.id; nicholas@872: hold.innerHTML = textArea.value; nicholas@872: console.log("Question: "+ node.question); nicholas@872: console.log("Question Response: "+ textArea.value); nicholas@872: this.responses.appendChild(hold); nicholas@872: } nicholas@872: } else if (node.type == 'checkbox') { nicholas@872: // Must extract checkbox data nicholas@872: var optHold = document.getElementById('option-holder'); nicholas@872: var hold = document.createElement('checkbox'); nicholas@872: console.log("Checkbox: "+ node.statement); nicholas@872: hold.id = node.id; nicholas@872: for (var i=0; i node.max && node.max != null) { nicholas@872: alert('Number is above the maximum value of '+node.max); nicholas@872: return; nicholas@872: } nicholas@872: var hold = document.createElement('number'); nicholas@872: hold.id = node.id; nicholas@872: hold.textContent = input.value; nicholas@872: this.responses.appendChild(hold); nicholas@872: } nicholas@872: this.currentIndex++; nicholas@872: if (this.currentIndex < this.popupOptions.length) { nicholas@872: this.postNode(); nicholas@872: } else { nicholas@872: // Reached the end of the popupOptions nicholas@872: this.hidePopup(); nicholas@872: if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { nicholas@872: testState.stateResults[testState.stateIndex] = this.responses; nicholas@872: } else { nicholas@872: testState.stateResults[testState.stateIndex].appendChild(this.responses); nicholas@872: } nicholas@872: advanceState(); nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: this.previousClick = function() { nicholas@872: // Triggered when the 'Back' button is clicked in the survey nicholas@872: if (this.currentIndex > 0) { nicholas@872: this.currentIndex--; nicholas@872: var node = this.popupOptions[this.currentIndex]; nicholas@872: if (node.type != 'statement') { nicholas@872: var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; nicholas@872: this.responses.removeChild(prevResp); nicholas@872: } nicholas@872: this.postNode(); nicholas@872: if (node.type == 'question') { nicholas@872: this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; nicholas@872: } else if (node.type == 'checkbox') { nicholas@872: var options = this.popupContent.getElementsByTagName('input'); nicholas@872: var savedOptions = prevResp.getElementsByTagName('option'); nicholas@872: for (var i=0; i 0) { nicholas@872: if(this.stateIndex != null) { nicholas@872: console.log('NOTE - State already initialise'); nicholas@872: } nicholas@872: this.stateIndex = -1; nicholas@872: var that = this; nicholas@872: for (var id=0; id= this.stateMap.length) { nicholas@872: console.log('Test Completed'); nicholas@872: createProjectSave(specification.projectReturn); nicholas@872: } else { nicholas@872: this.currentStateMap = this.stateMap[this.stateIndex]; nicholas@872: if (this.currentStateMap.type == "audioHolder") { nicholas@872: console.log('Loading test page'); nicholas@872: loadTest(this.currentStateMap); nicholas@872: this.initialiseInnerState(this.currentStateMap); nicholas@872: } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") { nicholas@872: if (this.currentStateMap.options.length >= 1) { nicholas@872: popup.initState(this.currentStateMap); nicholas@872: } else { nicholas@872: this.advanceState(); nicholas@872: } nicholas@872: } else { nicholas@872: this.advanceState(); nicholas@872: } nicholas@872: } nicholas@872: } else { nicholas@872: this.advanceInnerState(); nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: this.testPageCompleted = function(store, testXML, testId) { nicholas@872: // Function called each time a test page has been completed nicholas@872: // Can be used to over-rule default behaviour nicholas@872: nicholas@872: pageXMLSave(store, testXML); nicholas@872: }; nicholas@872: nicholas@872: this.initialiseInnerState = function(node) { nicholas@872: // Parses the received testXML for pre and post test options nicholas@872: this.currentStateMap = []; nicholas@872: var preTest = node.preTest; nicholas@872: var postTest = node.postTest; nicholas@872: if (preTest == undefined) {preTest = document.createElement("preTest");} nicholas@872: if (postTest == undefined){postTest= document.createElement("postTest");} nicholas@872: this.currentStateMap.push(preTest); nicholas@872: this.currentStateMap.push(node); nicholas@872: this.currentStateMap.push(postTest); nicholas@872: this.currentIndex = -1; nicholas@872: this.advanceInnerState(); nicholas@872: }; nicholas@872: nicholas@872: this.advanceInnerState = function() { nicholas@872: this.currentIndex++; nicholas@872: if (this.currentIndex >= this.currentStateMap.length) { nicholas@872: this.currentIndex = null; nicholas@872: this.currentStateMap = this.stateMap[this.stateIndex]; nicholas@872: this.advanceState(); nicholas@872: } else { nicholas@872: if (this.currentStateMap[this.currentIndex].type == "audioHolder") { nicholas@872: console.log("Loading test page"+this.currentTestId); nicholas@872: } else if (this.currentStateMap[this.currentIndex].type == "pretest") { nicholas@872: popup.initState(this.currentStateMap[this.currentIndex]); nicholas@872: } else if (this.currentStateMap[this.currentIndex].type == "posttest") { nicholas@872: popup.initState(this.currentStateMap[this.currentIndex]); nicholas@872: } else { nicholas@872: this.advanceInnerState(); nicholas@872: } nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: this.previousState = function(){}; nicholas@872: } nicholas@872: nicholas@872: function testEnded(testId) nicholas@872: { nicholas@872: pageXMLSave(testId); nicholas@872: if (testXMLSetups.length-1 > testId) nicholas@872: { nicholas@872: // Yes we have another test to perform nicholas@872: testId = (Number(testId)+1); nicholas@872: currentState = 'testRun-'+testId; nicholas@872: loadTest(testId); nicholas@872: } else { nicholas@872: console.log('Testing Completed!'); nicholas@872: currentState = 'postTest'; nicholas@872: // Check for any post tests nicholas@872: var xmlSetup = projectXML.find('setup'); nicholas@872: var postTest = xmlSetup.find('PostTest')[0]; nicholas@872: popup.initState(postTest); nicholas@872: } nicholas@872: } nicholas@872: nicholas@872: function loadProjectSpec(url) { nicholas@872: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data nicholas@872: // If url is null, request client to upload project XML document nicholas@872: var r = new XMLHttpRequest(); nicholas@872: r.open('GET',url,true); nicholas@872: r.onload = function() { nicholas@872: loadProjectSpecCallback(r.response); nicholas@872: }; nicholas@872: r.send(); nicholas@872: }; nicholas@872: nicholas@872: function loadProjectSpecCallback(response) { nicholas@872: // Function called after asynchronous download of XML project specification nicholas@872: //var decode = $.parseXML(response); nicholas@872: //projectXML = $(decode); nicholas@872: nicholas@872: var parse = new DOMParser(); nicholas@872: projectXML = parse.parseFromString(response,'text/xml'); nicholas@872: nicholas@872: // Build the specification nicholas@872: specification.decode(); nicholas@872: nicholas@872: testState.stateMap.push(specification.preTest); nicholas@872: nicholas@872: // New check if we need to randomise the test order nicholas@872: if (specification.randomiseOrder) nicholas@872: { nicholas@872: specification.audioHolders = randomiseOrder(specification.audioHolders); nicholas@872: } nicholas@872: nicholas@872: $(specification.audioHolders).each(function(index,elem){ nicholas@872: testState.stateMap.push(elem); nicholas@872: }); nicholas@872: nicholas@872: testState.stateMap.push(specification.postTest); nicholas@872: nicholas@872: // Obtain the metrics enabled nicholas@872: $(specification.metrics).each(function(index,node){ nicholas@872: var enabled = node.textContent; nicholas@872: switch(node.enabled) nicholas@872: { nicholas@872: case 'testTimer': nicholas@872: sessionMetrics.prototype.enableTestTimer = true; nicholas@872: break; nicholas@872: case 'elementTimer': nicholas@872: sessionMetrics.prototype.enableElementTimer = true; nicholas@872: break; nicholas@872: case 'elementTracker': nicholas@872: sessionMetrics.prototype.enableElementTracker = true; nicholas@872: break; nicholas@872: case 'elementListenTracker': nicholas@872: sessionMetrics.prototype.enableElementListenTracker = true; nicholas@872: break; nicholas@872: case 'elementInitialPosition': nicholas@872: sessionMetrics.prototype.enableElementInitialPosition = true; nicholas@872: break; nicholas@872: case 'elementFlagListenedTo': nicholas@872: sessionMetrics.prototype.enableFlagListenedTo = true; nicholas@872: break; nicholas@872: case 'elementFlagMoved': nicholas@872: sessionMetrics.prototype.enableFlagMoved = true; nicholas@872: break; nicholas@872: case 'elementFlagComments': nicholas@872: sessionMetrics.prototype.enableFlagComments = true; nicholas@872: break; nicholas@872: } nicholas@872: }); nicholas@872: nicholas@872: nicholas@872: nicholas@872: // Detect the interface to use and load the relevant javascripts. nicholas@872: var interfaceJS = document.createElement('script'); nicholas@872: interfaceJS.setAttribute("type","text/javascript"); nicholas@872: if (specification.interfaceType == 'APE') { nicholas@872: interfaceJS.setAttribute("src","ape.js"); nicholas@872: nicholas@872: // APE comes with a css file nicholas@872: var css = document.createElement('link'); nicholas@872: css.rel = 'stylesheet'; nicholas@872: css.type = 'text/css'; nicholas@872: css.href = 'ape.css'; nicholas@872: nicholas@872: document.getElementsByTagName("head")[0].appendChild(css); nicholas@872: } nicholas@872: document.getElementsByTagName("head")[0].appendChild(interfaceJS); nicholas@872: nicholas@872: // Define window callbacks for interface nicholas@872: window.onresize = function(event){resizeWindow(event);}; nicholas@872: } nicholas@872: nicholas@872: function createProjectSave(destURL) { nicholas@872: // Save the data from interface into XML and send to destURL nicholas@872: // If destURL is null then download XML in client nicholas@872: // Now time to render file locally nicholas@872: var xmlDoc = interfaceXMLSave(); nicholas@872: var parent = document.createElement("div"); nicholas@872: parent.appendChild(xmlDoc); nicholas@872: var file = [parent.innerHTML]; nicholas@872: if (destURL == "null" || destURL == undefined) { nicholas@872: var bb = new Blob(file,{type : 'application/xml'}); nicholas@872: var dnlk = window.URL.createObjectURL(bb); nicholas@872: var a = document.createElement("a"); nicholas@872: a.hidden = ''; nicholas@872: a.href = dnlk; nicholas@872: a.download = "save.xml"; nicholas@872: a.textContent = "Save File"; nicholas@872: nicholas@872: popup.showPopup(); nicholas@872: popup.popupContent.innerHTML = null; nicholas@872: popup.popupContent.appendChild(a); nicholas@872: } else { nicholas@872: var xmlhttp = new XMLHttpRequest; nicholas@872: xmlhttp.open("POST",destURL,true); nicholas@872: xmlhttp.setRequestHeader('Content-Type', 'text/xml'); nicholas@872: xmlhttp.onerror = function(){ nicholas@872: console.log('Error saving file to server! Presenting download locally'); nicholas@872: createProjectSave(null); nicholas@872: }; nicholas@872: xmlhttp.onreadystatechange = function() { nicholas@872: console.log(xmlhttp.status); nicholas@872: if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { nicholas@872: createProjectSave(null); nicholas@872: } nicholas@872: }; nicholas@872: xmlhttp.send(file); nicholas@872: } nicholas@872: } nicholas@872: nicholas@872: // Only other global function which must be defined in the interface class. Determines how to create the XML document. nicholas@872: function interfaceXMLSave(){ nicholas@872: // Create the XML string to be exported with results nicholas@872: var xmlDoc = document.createElement("BrowserEvaluationResult"); nicholas@872: xmlDoc.appendChild(returnDateNode()); nicholas@872: for (var i=0; i nicholas@872: // DD/MM/YY nicholas@872: // nicholas@872: // nicholas@872: var dateTime = new Date(); nicholas@872: var year = document.createAttribute('year'); nicholas@872: var month = document.createAttribute('month'); nicholas@872: var day = document.createAttribute('day'); nicholas@872: var hour = document.createAttribute('hour'); nicholas@872: var minute = document.createAttribute('minute'); nicholas@872: var secs = document.createAttribute('secs'); nicholas@872: nicholas@872: year.nodeValue = dateTime.getFullYear(); nicholas@872: month.nodeValue = dateTime.getMonth()+1; nicholas@872: day.nodeValue = dateTime.getDate(); nicholas@872: hour.nodeValue = dateTime.getHours(); nicholas@872: minute.nodeValue = dateTime.getMinutes(); nicholas@872: secs.nodeValue = dateTime.getSeconds(); nicholas@872: nicholas@872: var hold = document.createElement("datetime"); nicholas@872: var date = document.createElement("date"); nicholas@872: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; nicholas@872: var time = document.createElement("time"); nicholas@872: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; nicholas@872: nicholas@872: date.setAttributeNode(year); nicholas@872: date.setAttributeNode(month); nicholas@872: date.setAttributeNode(day); nicholas@872: time.setAttributeNode(hour); nicholas@872: time.setAttributeNode(minute); nicholas@872: time.setAttributeNode(secs); nicholas@872: nicholas@872: hold.appendChild(date); nicholas@872: hold.appendChild(time); nicholas@872: return hold nicholas@872: nicholas@872: } nicholas@872: nicholas@872: function testWaitIndicator() { nicholas@872: if (audioEngineContext.checkAllReady() == false) { nicholas@872: var hold = document.createElement("div"); nicholas@872: hold.id = "testWaitIndicator"; nicholas@872: hold.className = "indicator-box"; nicholas@872: hold.style.zIndex = 3; nicholas@872: var span = document.createElement("span"); nicholas@872: span.textContent = "Please wait! Elements still loading"; nicholas@872: hold.appendChild(span); nicholas@872: var blank = document.createElement('div'); nicholas@872: blank.className = 'testHalt'; nicholas@872: blank.id = "testHaltBlank"; nicholas@872: var body = document.getElementsByTagName('body')[0]; nicholas@872: body.appendChild(hold); nicholas@872: body.appendChild(blank); nicholas@872: testWaitTimerIntervalHolder = setInterval(function(){ nicholas@872: var ready = audioEngineContext.checkAllReady(); nicholas@872: if (ready) { nicholas@872: var elem = document.getElementById('testWaitIndicator'); nicholas@872: var blank = document.getElementById('testHaltBlank'); nicholas@872: var body = document.getElementsByTagName('body')[0]; nicholas@872: body.removeChild(elem); nicholas@872: body.removeChild(blank); nicholas@872: clearInterval(testWaitTimerIntervalHolder); nicholas@872: } nicholas@872: },500,false); nicholas@872: } nicholas@872: } nicholas@872: nicholas@872: var testWaitTimerIntervalHolder = null; nicholas@872: nicholas@872: function Specification() { nicholas@872: // Handles the decoding of the project specification XML into a simple JavaScript Object. nicholas@872: nicholas@872: this.interfaceType; nicholas@872: this.commonInterface; nicholas@872: this.projectReturn; nicholas@872: this.randomiseOrder; nicholas@872: this.collectMetrics; nicholas@872: this.preTest; nicholas@872: this.postTest; nicholas@872: this.metrics =[]; nicholas@872: nicholas@872: this.audioHolders = []; nicholas@872: nicholas@872: this.decode = function() { nicholas@872: // projectXML - DOM Parsed document nicholas@872: var setupNode = projectXML.getElementsByTagName('setup')[0]; nicholas@872: this.interfaceType = setupNode.getAttribute('interface'); nicholas@872: this.projectReturn = setupNode.getAttribute('projectReturn'); nicholas@872: if (setupNode.getAttribute('randomiseOrder') == "true") { nicholas@872: this.randomiseOrder = true; nicholas@872: } else {this.randomiseOrder = false;} nicholas@872: if (setupNode.getAttribute('collectMetrics') == "true") { nicholas@872: this.collectMetrics = true; nicholas@872: } else {this.collectMetrics = false;} nicholas@872: var metricCollection = setupNode.getElementsByTagName('Metric'); nicholas@872: nicholas@872: this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); nicholas@872: this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); nicholas@872: nicholas@872: if (metricCollection.length > 0) { nicholas@872: metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); nicholas@872: for (var i=0; i 0) { nicholas@872: commonInterfaceNode = commonInterfaceNode[0]; nicholas@872: } else { nicholas@872: commonInterfaceNode = undefined; nicholas@872: } nicholas@872: nicholas@872: this.commonInterface = new function() { nicholas@872: this.OptionNode = function(child) { nicholas@872: this.type = child.nodeName; nicholas@872: if (this.type == 'check') { nicholas@872: this.check = child.getAttribute('name'); nicholas@872: } else if (this.type == 'anchor' || this.type == 'reference') { nicholas@872: this.value = Number(child.textContent); nicholas@872: } nicholas@872: }; nicholas@872: this.options = []; nicholas@872: if (commonInterfaceNode != undefined) { nicholas@872: var child = commonInterfaceNode.firstElementChild; nicholas@872: while (child != undefined) { nicholas@872: this.options.push(new this.OptionNode(child)); nicholas@872: child = child.nextElementSibling; nicholas@872: } nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: var audioHolders = projectXML.getElementsByTagName('audioHolder'); nicholas@872: for (var i=0; i 1 && anchor < 100) {anchor /= 100.0;} nicholas@872: } nicholas@872: nicholas@872: if (typeof(reference) == 'number') { nicholas@872: if (reference > 1 && reference < 100) {reference /= 100.0;} nicholas@872: } nicholas@872: nicholas@872: this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest')); nicholas@872: this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest')); nicholas@872: nicholas@872: this.interfaces = []; nicholas@872: var interfaceDOM = xml.getElementsByTagName('interface'); nicholas@872: for (var i=0; i 1) { nicholas@872: console.log('Error - cannot have more than one anchor!'); nicholas@872: console.log('Each anchor node will be a normal mode to continue the test'); nicholas@872: for (var i=0; i 1) { nicholas@872: console.log('Error - cannot have more than one anchor!'); nicholas@872: console.log('Each anchor node will be a normal mode to continue the test'); nicholas@872: for (var i=0; i tag. nicholas@872: this.interfaceObjects = []; nicholas@872: this.interfaceObject = function(){}; nicholas@872: nicholas@872: this.commentBoxes = []; nicholas@872: this.elementCommentBox = function(audioObject) { nicholas@872: var element = audioObject.specification; nicholas@872: this.audioObject = audioObject; nicholas@872: this.id = audioObject.id; nicholas@872: var audioHolderObject = audioObject.specification.parent; nicholas@872: // Create document objects to hold the comment boxes nicholas@872: this.trackComment = document.createElement('div'); nicholas@872: this.trackComment.className = 'comment-div'; nicholas@872: this.trackComment.id = 'comment-div-'+audioObject.id; nicholas@872: // Create a string next to each comment asking for a comment nicholas@872: this.trackString = document.createElement('span'); nicholas@872: this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; nicholas@872: // Create the HTML5 comment box 'textarea' nicholas@872: this.trackCommentBox = document.createElement('textarea'); nicholas@872: this.trackCommentBox.rows = '4'; nicholas@872: this.trackCommentBox.cols = '100'; nicholas@872: this.trackCommentBox.name = 'trackComment'+audioObject.id; nicholas@872: this.trackCommentBox.className = 'trackComment'; nicholas@872: var br = document.createElement('br'); nicholas@872: // Add to the holder. nicholas@872: this.trackComment.appendChild(this.trackString); nicholas@872: this.trackComment.appendChild(br); nicholas@872: this.trackComment.appendChild(this.trackCommentBox); nicholas@872: nicholas@872: this.exportXMLDOM = function() { nicholas@872: var root = document.createElement('comment'); nicholas@872: if (this.audioObject.specification.parent.elementComments) { nicholas@872: var question = document.createElement('question'); nicholas@872: question.textContent = this.trackString.textContent; nicholas@872: var response = document.createElement('response'); nicholas@872: response.textContent = this.trackCommentBox.value; nicholas@872: root.appendChild(question); nicholas@872: root.appendChild(response); nicholas@872: } nicholas@872: return root; nicholas@872: }; nicholas@872: }; nicholas@872: nicholas@872: this.commentQuestions = []; nicholas@872: nicholas@872: this.commentBox = function(commentQuestion) { nicholas@872: this.specification = commentQuestion; nicholas@872: // Create document objects to hold the comment boxes nicholas@872: this.holder = document.createElement('div'); nicholas@872: this.holder.className = 'comment-div'; nicholas@872: // Create a string next to each comment asking for a comment nicholas@872: this.string = document.createElement('span'); nicholas@872: this.string.innerHTML = commentQuestion.question; nicholas@872: // Create the HTML5 comment box 'textarea' nicholas@872: this.textArea = document.createElement('textarea'); nicholas@872: this.textArea.rows = '4'; nicholas@872: this.textArea.cols = '100'; nicholas@872: this.textArea.className = 'trackComment'; nicholas@872: var br = document.createElement('br'); nicholas@872: // Add to the holder. nicholas@872: this.holder.appendChild(this.string); nicholas@872: this.holder.appendChild(br); nicholas@872: this.holder.appendChild(this.textArea); nicholas@872: nicholas@872: this.exportXMLDOM = function() { nicholas@872: var root = document.createElement('comment'); nicholas@872: root.id = this.specification.id; nicholas@872: root.setAttribute('type',this.specification.type); nicholas@872: root.textContent = this.textArea.value; nicholas@872: return root; nicholas@872: }; nicholas@872: }; nicholas@872: nicholas@872: this.radioBox = function(commentQuestion) { nicholas@872: this.specification = commentQuestion; nicholas@872: // Create document objects to hold the comment boxes nicholas@872: this.holder = document.createElement('div'); nicholas@872: this.holder.className = 'comment-div'; nicholas@872: // Create a string next to each comment asking for a comment nicholas@872: this.string = document.createElement('span'); nicholas@872: this.string.innerHTML = commentQuestion.statement; nicholas@872: var br = document.createElement('br'); nicholas@872: // Add to the holder. nicholas@872: this.holder.appendChild(this.string); nicholas@872: this.holder.appendChild(br); nicholas@872: this.options = []; nicholas@872: this.inputs = document.createElement('div'); nicholas@872: this.span = document.createElement('div'); nicholas@872: this.inputs.align = 'center'; nicholas@872: this.inputs.style.marginLeft = '12px'; nicholas@872: this.span.style.marginLeft = '12px'; nicholas@872: this.span.align = 'center'; nicholas@872: this.span.style.marginTop = '15px'; nicholas@872: nicholas@872: var optCount = commentQuestion.options.length; nicholas@872: var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; nicholas@872: console.log(spanMargin); nicholas@872: for (var i=0; i= this.options.length) { nicholas@872: break; nicholas@872: } nicholas@872: } nicholas@872: if (i >= this.options.length) { nicholas@872: response.textContent = 'null'; nicholas@872: } else { nicholas@872: response.textContent = this.options[i].getAttribute('setvalue'); nicholas@872: response.setAttribute('number',i); nicholas@872: } nicholas@872: console.log('Comment: '+question.textContent); nicholas@872: console.log('Response: '+response.textContent); nicholas@872: root.appendChild(question); nicholas@872: root.appendChild(response); nicholas@872: return root; nicholas@872: }; nicholas@872: }; nicholas@872: nicholas@872: this.checkboxBox = function(commentQuestion) { nicholas@872: this.specification = commentQuestion; nicholas@872: // Create document objects to hold the comment boxes nicholas@872: this.holder = document.createElement('div'); nicholas@872: this.holder.className = 'comment-div'; nicholas@872: // Create a string next to each comment asking for a comment nicholas@872: this.string = document.createElement('span'); nicholas@872: this.string.innerHTML = commentQuestion.statement; nicholas@872: var br = document.createElement('br'); nicholas@872: // Add to the holder. nicholas@872: this.holder.appendChild(this.string); nicholas@872: this.holder.appendChild(br); nicholas@872: this.options = []; nicholas@872: this.inputs = document.createElement('div'); nicholas@872: this.span = document.createElement('div'); nicholas@872: this.inputs.align = 'center'; nicholas@872: this.inputs.style.marginLeft = '12px'; nicholas@872: this.span.style.marginLeft = '12px'; nicholas@872: this.span.align = 'center'; nicholas@872: this.span.style.marginTop = '15px'; nicholas@872: nicholas@872: var optCount = commentQuestion.options.length; nicholas@872: var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; nicholas@872: console.log(spanMargin); nicholas@872: for (var i=0; i 0) { nicholas@872: var node = this.commentBoxes.pop(0); nicholas@872: holder[node.id] = node; nicholas@872: } nicholas@872: this.commentBoxes = holder; nicholas@872: }; nicholas@872: nicholas@872: this.showCommentBoxes = function(inject, sort) { nicholas@872: if (sort) {interfaceContext.sortCommentBoxes();} nicholas@872: for (var i=0; i 0) { nicholas@872: var time = this.playbackObject.getCurrentPosition(); nicholas@872: var width = 490; nicholas@872: var pix = Math.floor(time/this.timePerPixel); nicholas@872: this.scrubberHead.style.left = pix+'px'; nicholas@872: if (this.maxTime > 60.0) { nicholas@872: var secs = time%60; nicholas@872: var mins = Math.floor((time-secs)/60); nicholas@872: secs = secs.toString(); nicholas@872: secs = secs.substr(0,2); nicholas@872: mins = mins.toString(); nicholas@872: this.curTimeSpan.textContent = mins+':'+secs; nicholas@872: } else { nicholas@872: time = time.toString(); nicholas@872: this.curTimeSpan.textContent = time.substr(0,4); nicholas@872: } nicholas@872: } nicholas@872: }; nicholas@872: nicholas@872: this.interval = undefined; nicholas@872: nicholas@872: this.start = function() { nicholas@872: if (this.playbackObject != undefined && this.interval == undefined) { nicholas@872: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); nicholas@872: } nicholas@872: }; nicholas@872: this.stop = function() { nicholas@872: clearInterval(this.interval); nicholas@872: this.interval = undefined; nicholas@872: }; nicholas@872: }; nicholas@872: } nicholas@872: