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