n@841: /** n@841: * core.js n@841: * n@841: * Main script to run, calls all other core functions and manages loading/store to backend. n@841: * Also contains all global variables. n@841: */ n@841: n@841: /* create the web audio API context and store in audioContext*/ n@841: var audioContext; // Hold the browser web audio API n@841: var projectXML; // Hold the parsed setup XML n@841: var specification; n@841: var interfaceContext; n@841: var popup; // Hold the interfacePopup object n@841: var testState; n@841: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order n@841: var audioEngineContext; // The custome AudioEngine object n@841: var projectReturn; // Hold the URL for the return n@841: n@841: n@841: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it n@841: AudioBufferSourceNode.prototype.owner = undefined; n@841: n@841: window.onload = function() { n@841: // Function called once the browser has loaded all files. n@841: // This should perform any initial commands such as structure / loading documents n@841: n@841: // Create a web audio API context n@841: // Fixed for cross-browser support n@841: var AudioContext = window.AudioContext || window.webkitAudioContext; n@841: audioContext = new AudioContext; n@841: n@841: // Create test state n@841: testState = new stateMachine(); n@841: n@841: // Create the audio engine object n@841: audioEngineContext = new AudioEngine(); n@841: n@841: // Create the popup interface object n@841: popup = new interfacePopup(); n@841: n@841: // Create the specification object n@841: specification = new Specification(); n@841: n@841: // Create the interface object n@841: interfaceContext = new Interface(specification); n@841: }; n@841: n@841: function interfacePopup() { n@841: // Creates an object to manage the popup n@841: this.popup = null; n@841: this.popupContent = null; n@841: this.buttonProceed = null; n@841: this.buttonPrevious = null; n@841: this.popupOptions = null; n@841: this.currentIndex = null; n@841: this.responses = null; n@841: n@841: this.createPopup = function(){ n@841: // Create popup window interface n@841: var insertPoint = document.getElementById("topLevelBody"); n@841: var blank = document.createElement('div'); n@841: blank.className = 'testHalt'; n@841: n@841: this.popup = document.createElement('div'); n@841: this.popup.id = 'popupHolder'; n@841: this.popup.className = 'popupHolder'; n@841: this.popup.style.position = 'absolute'; n@841: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; n@841: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; n@841: n@841: this.popupContent = document.createElement('div'); n@841: this.popupContent.id = 'popupContent'; n@841: this.popupContent.style.marginTop = '25px'; n@841: this.popupContent.align = 'center'; n@841: this.popup.appendChild(this.popupContent); n@841: n@841: this.buttonProceed = document.createElement('button'); n@841: this.buttonProceed.className = 'popupButton'; n@841: this.buttonProceed.style.left = '440px'; n@841: this.buttonProceed.style.top = '215px'; n@841: this.buttonProceed.innerHTML = 'Next'; n@841: this.buttonProceed.onclick = function(){popup.proceedClicked();}; n@841: n@841: this.buttonPrevious = document.createElement('button'); n@841: this.buttonPrevious.className = 'popupButton'; n@841: this.buttonPrevious.style.left = '10px'; n@841: this.buttonPrevious.style.top = '215px'; n@841: this.buttonPrevious.innerHTML = 'Back'; n@841: this.buttonPrevious.onclick = function(){popup.previousClick();}; n@841: n@841: this.popup.style.zIndex = -1; n@841: this.popup.style.visibility = 'hidden'; n@841: blank.style.zIndex = -2; n@841: blank.style.visibility = 'hidden'; n@841: insertPoint.appendChild(this.popup); n@841: insertPoint.appendChild(blank); n@841: }; n@841: n@841: this.showPopup = function(){ n@841: if (this.popup == null) { n@841: this.createPopup(); n@841: } n@841: this.popup.style.zIndex = 3; n@841: this.popup.style.visibility = 'visible'; n@841: var blank = document.getElementsByClassName('testHalt')[0]; n@841: blank.style.zIndex = 2; n@841: blank.style.visibility = 'visible'; n@841: $(window).keypress(function(e){ n@841: if (e.keyCode == 13 && popup.popup.style.visibility == 'visible') n@841: { n@841: // Enter key pressed n@841: var textarea = $(popup.popupContent).find('textarea'); n@841: if (textarea.length != 0) n@841: { n@841: if (textarea[0] == document.activeElement) n@841: {return;} n@841: } n@841: popup.buttonProceed.onclick(); n@841: } n@841: }); n@841: }; n@841: n@841: this.hidePopup = function(){ n@841: this.popup.style.zIndex = -1; n@841: this.popup.style.visibility = 'hidden'; n@841: var blank = document.getElementsByClassName('testHalt')[0]; n@841: blank.style.zIndex = -2; n@841: blank.style.visibility = 'hidden'; n@841: }; n@841: n@841: this.postNode = function() { n@841: // This will take the node from the popupOptions and display it n@841: var node = this.popupOptions[this.currentIndex]; n@841: this.popupContent.innerHTML = null; n@841: if (node.type == 'statement') { n@841: var span = document.createElement('span'); n@841: span.textContent = node.statement; n@841: this.popupContent.appendChild(span); n@841: } else if (node.type == 'question') { n@841: var span = document.createElement('span'); n@841: span.textContent = node.question; n@841: var textArea = document.createElement('textarea'); n@841: switch (node.boxsize) { n@841: case 'small': n@841: textArea.cols = "20"; n@841: textArea.rows = "1"; n@841: break; n@841: case 'normal': n@841: textArea.cols = "30"; n@841: textArea.rows = "2"; n@841: break; n@841: case 'large': n@841: textArea.cols = "40"; n@841: textArea.rows = "5"; n@841: break; n@841: case 'huge': n@841: textArea.cols = "50"; n@841: textArea.rows = "10"; n@841: break; n@841: } n@841: var br = document.createElement('br'); n@841: this.popupContent.appendChild(span); n@841: this.popupContent.appendChild(br); n@841: this.popupContent.appendChild(textArea); n@841: this.popupContent.childNodes[2].focus(); n@841: } else if (node.type == 'checkbox') { n@841: var span = document.createElement('span'); n@841: span.textContent = node.statement; n@841: this.popupContent.appendChild(span); n@841: var optHold = document.createElement('div'); n@841: optHold.id = 'option-holder'; n@841: optHold.align = 'left'; n@841: for (var i=0; i 0) n@841: this.popupContent.appendChild(this.buttonPrevious); n@841: }; n@841: n@841: this.initState = function(node) { n@841: //Call this with your preTest and postTest nodes when needed to n@841: // initialise the popup procedure. n@841: this.popupOptions = node.options; n@841: if (this.popupOptions.length > 0) { n@841: if (node.type == 'pretest') { n@841: this.responses = document.createElement('PreTest'); n@841: } else if (node.type == 'posttest') { n@841: this.responses = document.createElement('PostTest'); n@841: } else { n@841: console.log ('WARNING - popup node neither pre or post!'); n@841: this.responses = document.createElement('responses'); n@841: } n@841: this.currentIndex = 0; n@841: this.showPopup(); n@841: this.postNode(); n@841: } else { n@841: advanceState(); n@841: } n@841: }; n@841: n@841: this.proceedClicked = function() { n@841: // Each time the popup button is clicked! n@841: var node = this.popupOptions[this.currentIndex]; n@841: if (node.type == 'question') { n@841: // Must extract the question data n@841: var textArea = $(popup.popupContent).find('textarea')[0]; n@841: if (node.mandatory == true && textArea.value.length == 0) { n@841: alert('This question is mandatory'); n@841: return; n@841: } else { n@841: // Save the text content n@841: var hold = document.createElement('comment'); n@841: hold.id = node.id; n@841: hold.innerHTML = textArea.value; n@841: console.log("Question: "+ node.question); n@841: console.log("Question Response: "+ textArea.value); n@841: this.responses.appendChild(hold); n@841: } n@841: } else if (node.type == 'checkbox') { n@841: // Must extract checkbox data n@841: var optHold = document.getElementById('option-holder'); n@841: var hold = document.createElement('checkbox'); n@841: console.log("Checkbox: "+ node.statement); n@841: hold.id = node.id; n@841: for (var i=0; i node.max && node.max != null) { n@841: alert('Number is above the maximum value of '+node.max); n@841: return; n@841: } n@841: var hold = document.createElement('number'); n@841: hold.id = node.id; n@841: hold.textContent = input.value; n@841: this.responses.appendChild(hold); n@841: } n@841: this.currentIndex++; n@841: if (this.currentIndex < this.popupOptions.length) { n@841: this.postNode(); n@841: } else { n@841: // Reached the end of the popupOptions n@841: this.hidePopup(); n@841: if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { n@841: testState.stateResults[testState.stateIndex] = this.responses; n@841: } else { n@841: testState.stateResults[testState.stateIndex].appendChild(this.responses); n@841: } n@841: advanceState(); n@841: } n@841: }; n@841: n@841: this.previousClick = function() { n@841: // Triggered when the 'Back' button is clicked in the survey n@841: if (this.currentIndex > 0) { n@841: this.currentIndex--; n@841: var node = this.popupOptions[this.currentIndex]; n@841: if (node.type != 'statement') { n@841: var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; n@841: this.responses.removeChild(prevResp); n@841: } n@841: this.postNode(); n@841: if (node.type == 'question') { n@841: this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; n@841: } else if (node.type == 'checkbox') { n@841: var options = this.popupContent.getElementsByTagName('input'); n@841: var savedOptions = prevResp.getElementsByTagName('option'); n@841: for (var i=0; i 0) { n@841: if(this.stateIndex != null) { n@841: console.log('NOTE - State already initialise'); n@841: } n@841: this.stateIndex = -1; n@841: var that = this; n@841: var aH_pId = 0; n@841: for (var id=0; id= this.stateMap.length) { n@841: console.log('Test Completed'); n@841: createProjectSave(specification.projectReturn); n@841: } else { n@841: this.currentStateMap = this.stateMap[this.stateIndex]; n@841: if (this.currentStateMap.type == "audioHolder") { n@841: console.log('Loading test page'); n@841: loadTest(this.currentStateMap); n@841: this.initialiseInnerState(this.currentStateMap); n@841: } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") { n@841: if (this.currentStateMap.options.length >= 1) { n@841: popup.initState(this.currentStateMap); n@841: } else { n@841: this.advanceState(); n@841: } n@841: } else { n@841: this.advanceState(); n@841: } n@841: } n@841: } else { n@841: this.advanceInnerState(); n@841: } n@841: }; n@841: n@841: this.testPageCompleted = function(store, testXML, testId) { n@841: // Function called each time a test page has been completed n@841: // Can be used to over-rule default behaviour n@841: n@841: pageXMLSave(store, testXML); n@841: }; n@841: n@841: this.initialiseInnerState = function(node) { n@841: // Parses the received testXML for pre and post test options n@841: this.currentStateMap = []; n@841: var preTest = node.preTest; n@841: var postTest = node.postTest; n@841: if (preTest == undefined) {preTest = document.createElement("preTest");} n@841: if (postTest == undefined){postTest= document.createElement("postTest");} n@841: this.currentStateMap.push(preTest); n@841: this.currentStateMap.push(node); n@841: this.currentStateMap.push(postTest); n@841: this.currentIndex = -1; n@841: this.advanceInnerState(); n@841: }; n@841: n@841: this.advanceInnerState = function() { n@841: this.currentIndex++; n@841: if (this.currentIndex >= this.currentStateMap.length) { n@841: this.currentIndex = null; n@841: this.currentStateMap = this.stateMap[this.stateIndex]; n@841: this.advanceState(); n@841: } else { n@841: if (this.currentStateMap[this.currentIndex].type == "audioHolder") { n@841: console.log("Loading test page"+this.currentTestId); n@841: } else if (this.currentStateMap[this.currentIndex].type == "pretest") { n@841: popup.initState(this.currentStateMap[this.currentIndex]); n@841: } else if (this.currentStateMap[this.currentIndex].type == "posttest") { n@841: popup.initState(this.currentStateMap[this.currentIndex]); n@841: } else { n@841: this.advanceInnerState(); n@841: } n@841: } n@841: }; n@841: n@841: this.previousState = function(){}; n@841: } n@841: n@841: function testEnded(testId) n@841: { n@841: pageXMLSave(testId); n@841: if (testXMLSetups.length-1 > testId) n@841: { n@841: // Yes we have another test to perform n@841: testId = (Number(testId)+1); n@841: currentState = 'testRun-'+testId; n@841: loadTest(testId); n@841: } else { n@841: console.log('Testing Completed!'); n@841: currentState = 'postTest'; n@841: // Check for any post tests n@841: var xmlSetup = projectXML.find('setup'); n@841: var postTest = xmlSetup.find('PostTest')[0]; n@841: popup.initState(postTest); n@841: } n@841: } n@841: n@841: function loadProjectSpec(url) { n@841: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data n@841: // If url is null, request client to upload project XML document n@841: var r = new XMLHttpRequest(); n@841: r.open('GET',url,true); n@841: r.onload = function() { n@841: loadProjectSpecCallback(r.response); n@841: }; n@841: r.send(); n@841: }; n@841: n@841: function loadProjectSpecCallback(response) { n@841: // Function called after asynchronous download of XML project specification n@841: //var decode = $.parseXML(response); n@841: //projectXML = $(decode); n@841: n@841: var parse = new DOMParser(); n@841: projectXML = parse.parseFromString(response,'text/xml'); n@841: n@841: // Build the specification n@841: specification.decode(); n@841: n@841: testState.stateMap.push(specification.preTest); n@841: n@841: // New check if we need to randomise the test order n@841: if (specification.randomiseOrder) n@841: { n@841: specification.audioHolders = randomiseOrder(specification.audioHolders); n@841: for (var i=0; i n@841: // DD/MM/YY n@841: // n@841: // n@841: var dateTime = new Date(); n@841: var year = document.createAttribute('year'); n@841: var month = document.createAttribute('month'); n@841: var day = document.createAttribute('day'); n@841: var hour = document.createAttribute('hour'); n@841: var minute = document.createAttribute('minute'); n@841: var secs = document.createAttribute('secs'); n@841: n@841: year.nodeValue = dateTime.getFullYear(); n@841: month.nodeValue = dateTime.getMonth()+1; n@841: day.nodeValue = dateTime.getDate(); n@841: hour.nodeValue = dateTime.getHours(); n@841: minute.nodeValue = dateTime.getMinutes(); n@841: secs.nodeValue = dateTime.getSeconds(); n@841: n@841: var hold = document.createElement("datetime"); n@841: var date = document.createElement("date"); n@841: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; n@841: var time = document.createElement("time"); n@841: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; n@841: n@841: date.setAttributeNode(year); n@841: date.setAttributeNode(month); n@841: date.setAttributeNode(day); n@841: time.setAttributeNode(hour); n@841: time.setAttributeNode(minute); n@841: time.setAttributeNode(secs); n@841: n@841: hold.appendChild(date); n@841: hold.appendChild(time); n@841: return hold n@841: n@841: } n@841: n@841: function testWaitIndicator() { n@841: if (audioEngineContext.checkAllReady() == false) { n@841: var hold = document.createElement("div"); n@841: hold.id = "testWaitIndicator"; n@841: hold.className = "indicator-box"; n@841: hold.style.zIndex = 3; n@841: var span = document.createElement("span"); n@841: span.textContent = "Please wait! Elements still loading"; n@841: hold.appendChild(span); n@841: var blank = document.createElement('div'); n@841: blank.className = 'testHalt'; n@841: blank.id = "testHaltBlank"; n@841: var body = document.getElementsByTagName('body')[0]; n@841: body.appendChild(hold); n@841: body.appendChild(blank); n@841: testWaitTimerIntervalHolder = setInterval(function(){ n@841: var ready = audioEngineContext.checkAllReady(); n@841: if (ready) { n@841: var elem = document.getElementById('testWaitIndicator'); n@841: var blank = document.getElementById('testHaltBlank'); n@841: var body = document.getElementsByTagName('body')[0]; n@841: body.removeChild(elem); n@841: body.removeChild(blank); n@841: clearInterval(testWaitTimerIntervalHolder); n@841: } n@841: },500,false); n@841: } n@841: } n@841: n@841: var testWaitTimerIntervalHolder = null; n@841: n@841: function Specification() { n@841: // Handles the decoding of the project specification XML into a simple JavaScript Object. n@841: n@841: this.interfaceType; n@841: this.commonInterface; n@841: this.projectReturn; n@841: this.randomiseOrder; n@841: this.collectMetrics; n@841: this.preTest; n@841: this.postTest; n@841: this.metrics =[]; n@841: n@841: this.audioHolders = []; n@841: n@841: this.decode = function() { n@841: // projectXML - DOM Parsed document n@841: this.projectXML = projectXML.childNodes[0]; n@841: var setupNode = projectXML.getElementsByTagName('setup')[0]; n@841: this.interfaceType = setupNode.getAttribute('interface'); n@841: this.projectReturn = setupNode.getAttribute('projectReturn'); n@841: if (setupNode.getAttribute('randomiseOrder') == "true") { n@841: this.randomiseOrder = true; n@841: } else {this.randomiseOrder = false;} n@841: if (setupNode.getAttribute('collectMetrics') == "true") { n@841: this.collectMetrics = true; n@841: } else {this.collectMetrics = false;} n@841: var metricCollection = setupNode.getElementsByTagName('Metric'); n@841: n@841: this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); n@841: this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); n@841: n@841: if (metricCollection.length > 0) { n@841: metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); n@841: for (var i=0; i 0) { n@841: commonInterfaceNode = commonInterfaceNode[0]; n@841: } else { n@841: commonInterfaceNode = undefined; n@841: } n@841: n@841: this.commonInterface = new function() { n@841: this.OptionNode = function(child) { n@841: this.type = child.nodeName; n@841: if (this.type == 'option') n@841: { n@841: this.name = child.getAttribute('name'); n@841: } n@841: else if (this.type == 'check') { n@841: this.check = child.getAttribute('name'); n@841: if (this.check == 'scalerange') { n@841: this.min = child.getAttribute('min'); n@841: this.max = child.getAttribute('max'); n@841: if (this.min == null) {this.min = 1;} n@841: else if (Number(this.min) > 1 && this.min != null) { n@841: this.min = Number(this.min)/100; n@841: } else { n@841: this.min = Number(this.min); n@841: } n@841: if (this.max == null) {this.max = 0;} n@841: else if (Number(this.max) > 1 && this.max != null) { n@841: this.max = Number(this.max)/100; n@841: } else { n@841: this.max = Number(this.max); n@841: } n@841: } n@841: } else if (this.type == 'anchor' || this.type == 'reference') { n@841: this.value = Number(child.textContent); n@841: this.enforce = child.getAttribute('enforce'); n@841: if (this.enforce == 'true') {this.enforce = true;} n@841: else {this.enforce = false;} n@841: } n@841: }; n@841: this.options = []; n@841: if (commonInterfaceNode != undefined) { n@841: var child = commonInterfaceNode.firstElementChild; n@841: while (child != undefined) { n@841: this.options.push(new this.OptionNode(child)); n@841: child = child.nextElementSibling; n@841: } n@841: } n@841: }; n@841: n@841: var audioHolders = projectXML.getElementsByTagName('audioHolder'); n@841: for (var i=0; i 1) {this.marker /= 100;} n@841: } n@841: }; n@841: n@841: this.commentQuestionNode = function(xml) { n@841: this.childOption = function(element) { n@841: this.type = 'option'; n@841: this.name = element.getAttribute('name'); n@841: this.text = element.textContent; n@841: }; n@841: this.id = xml.id; n@841: if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} n@841: else {this.mandatory = false;} n@841: this.type = xml.getAttribute('type'); n@841: if (this.type == undefined) {this.type = 'text';} n@841: switch (this.type) { n@841: case 'text': n@841: this.question = xml.textContent; n@841: break; n@841: case 'radio': n@841: var child = xml.firstElementChild; n@841: this.options = []; n@841: while (child != undefined) { n@841: if (child.nodeName == 'statement' && this.statement == undefined) { n@841: this.statement = child.textContent; n@841: } else if (child.nodeName == 'option') { n@841: this.options.push(new this.childOption(child)); n@841: } n@841: child = child.nextElementSibling; n@841: } n@841: break; n@841: case 'checkbox': n@841: var child = xml.firstElementChild; n@841: this.options = []; n@841: while (child != undefined) { n@841: if (child.nodeName == 'statement' && this.statement == undefined) { n@841: this.statement = child.textContent; n@841: } else if (child.nodeName == 'option') { n@841: this.options.push(new this.childOption(child)); n@841: } n@841: child = child.nextElementSibling; n@841: } n@841: break; n@841: } n@841: }; n@841: n@841: this.id = xml.id; n@841: this.hostURL = xml.getAttribute('hostURL'); n@841: this.sampleRate = xml.getAttribute('sampleRate'); n@841: if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;} n@841: else {this.randomiseOrder = false;} n@841: this.repeatCount = xml.getAttribute('repeatCount'); n@841: if (xml.getAttribute('loop') == 'true') {this.loop = true;} n@841: else {this.loop == false;} n@841: if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;} n@841: else {this.elementComments = false;} n@841: n@841: var anchor = xml.getElementsByTagName('anchor'); n@841: var enforceAnchor = false; n@841: if (anchor.length == 0) { n@841: // Find anchor in commonInterface; n@841: for (var i=0; i 1 && anchor < 100) {anchor /= 100.0;} n@841: } n@841: n@841: if (typeof(reference) == 'number') { n@841: if (reference > 1 && reference < 100) {reference /= 100.0;} n@841: } n@841: n@841: this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest')); n@841: this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest')); n@841: n@841: this.interfaces = []; n@841: var interfaceDOM = xml.getElementsByTagName('interface'); n@841: for (var i=0; i 1) { n@841: console.log('Error - cannot have more than one anchor!'); n@841: console.log('Each anchor node will be a normal mode to continue the test'); n@841: for (var i=0; i 1) { n@841: console.log('Error - cannot have more than one anchor!'); n@841: console.log('Each anchor node will be a normal mode to continue the test'); n@841: for (var i=0; i tag. n@841: this.interfaceObjects = []; n@841: this.interfaceObject = function(){}; n@841: n@841: this.commentBoxes = []; n@841: this.elementCommentBox = function(audioObject) { n@841: var element = audioObject.specification; n@841: this.audioObject = audioObject; n@841: this.id = audioObject.id; n@841: var audioHolderObject = audioObject.specification.parent; n@841: // Create document objects to hold the comment boxes n@841: this.trackComment = document.createElement('div'); n@841: this.trackComment.className = 'comment-div'; n@841: this.trackComment.id = 'comment-div-'+audioObject.id; n@841: // Create a string next to each comment asking for a comment n@841: this.trackString = document.createElement('span'); n@841: this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; n@841: // Create the HTML5 comment box 'textarea' n@841: this.trackCommentBox = document.createElement('textarea'); n@841: this.trackCommentBox.rows = '4'; n@841: this.trackCommentBox.cols = '100'; n@841: this.trackCommentBox.name = 'trackComment'+audioObject.id; n@841: this.trackCommentBox.className = 'trackComment'; n@841: var br = document.createElement('br'); n@841: // Add to the holder. n@841: this.trackComment.appendChild(this.trackString); n@841: this.trackComment.appendChild(br); n@841: this.trackComment.appendChild(this.trackCommentBox); n@841: n@841: this.exportXMLDOM = function() { n@841: var root = document.createElement('comment'); n@841: if (this.audioObject.specification.parent.elementComments) { n@841: var question = document.createElement('question'); n@841: question.textContent = this.trackString.textContent; n@841: var response = document.createElement('response'); n@841: response.textContent = this.trackCommentBox.value; n@841: console.log("Comment frag-"+this.id+": "+response.textContent); n@841: root.appendChild(question); n@841: root.appendChild(response); n@841: } n@841: return root; n@841: }; n@841: }; n@841: n@841: this.commentQuestions = []; n@841: n@841: this.commentBox = function(commentQuestion) { n@841: this.specification = commentQuestion; n@841: // Create document objects to hold the comment boxes n@841: this.holder = document.createElement('div'); n@841: this.holder.className = 'comment-div'; n@841: // Create a string next to each comment asking for a comment n@841: this.string = document.createElement('span'); n@841: this.string.innerHTML = commentQuestion.question; n@841: // Create the HTML5 comment box 'textarea' n@841: this.textArea = document.createElement('textarea'); n@841: this.textArea.rows = '4'; n@841: this.textArea.cols = '100'; n@841: this.textArea.className = 'trackComment'; n@841: var br = document.createElement('br'); n@841: // Add to the holder. n@841: this.holder.appendChild(this.string); n@841: this.holder.appendChild(br); n@841: this.holder.appendChild(this.textArea); n@841: n@841: this.exportXMLDOM = function() { n@841: var root = document.createElement('comment'); n@841: root.id = this.specification.id; n@841: root.setAttribute('type',this.specification.type); n@841: root.textContent = this.textArea.value; n@841: console.log("Question: "+this.string.textContent); n@841: console.log("Response: "+root.textContent); n@841: return root; n@841: }; n@841: }; n@841: n@841: this.radioBox = function(commentQuestion) { n@841: this.specification = commentQuestion; n@841: // Create document objects to hold the comment boxes n@841: this.holder = document.createElement('div'); n@841: this.holder.className = 'comment-div'; n@841: // Create a string next to each comment asking for a comment n@841: this.string = document.createElement('span'); n@841: this.string.innerHTML = commentQuestion.statement; n@841: var br = document.createElement('br'); n@841: // Add to the holder. n@841: this.holder.appendChild(this.string); n@841: this.holder.appendChild(br); n@841: this.options = []; n@841: this.inputs = document.createElement('div'); n@841: this.span = document.createElement('div'); n@841: this.inputs.align = 'center'; n@841: this.inputs.style.marginLeft = '12px'; n@841: this.span.style.marginLeft = '12px'; n@841: this.span.align = 'center'; n@841: this.span.style.marginTop = '15px'; n@841: n@841: var optCount = commentQuestion.options.length; n@841: var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; n@841: console.log(spanMargin); n@841: for (var i=0; i= this.options.length) { n@841: break; n@841: } n@841: } n@841: if (i >= this.options.length) { n@841: response.textContent = 'null'; n@841: } else { n@841: response.textContent = this.options[i].getAttribute('setvalue'); n@841: response.setAttribute('number',i); n@841: } n@841: console.log('Comment: '+question.textContent); n@841: console.log('Response: '+response.textContent); n@841: root.appendChild(question); n@841: root.appendChild(response); n@841: return root; n@841: }; n@841: }; n@841: n@841: this.checkboxBox = function(commentQuestion) { n@841: this.specification = commentQuestion; n@841: // Create document objects to hold the comment boxes n@841: this.holder = document.createElement('div'); n@841: this.holder.className = 'comment-div'; n@841: // Create a string next to each comment asking for a comment n@841: this.string = document.createElement('span'); n@841: this.string.innerHTML = commentQuestion.statement; n@841: var br = document.createElement('br'); n@841: // Add to the holder. n@841: this.holder.appendChild(this.string); n@841: this.holder.appendChild(br); n@841: this.options = []; n@841: this.inputs = document.createElement('div'); n@841: this.span = document.createElement('div'); n@841: this.inputs.align = 'center'; n@841: this.inputs.style.marginLeft = '12px'; n@841: this.span.style.marginLeft = '12px'; n@841: this.span.align = 'center'; n@841: this.span.style.marginTop = '15px'; n@841: n@841: var optCount = commentQuestion.options.length; n@841: var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; n@841: console.log(spanMargin); n@841: for (var i=0; i 0) { n@841: var node = this.commentBoxes.pop(0); n@841: holder[node.id] = node; n@841: } n@841: this.commentBoxes = holder; n@841: }; n@841: n@841: this.showCommentBoxes = function(inject, sort) { n@841: if (sort) {interfaceContext.sortCommentBoxes();} n@841: for (var i=0; i 0) { n@841: var time = this.playbackObject.getCurrentPosition(); n@841: if (time > 0) { n@841: var width = 490; n@841: var pix = Math.floor(time/this.timePerPixel); n@841: this.scrubberHead.style.left = pix+'px'; n@841: if (this.maxTime > 60.0) { n@841: var secs = time%60; n@841: var mins = Math.floor((time-secs)/60); n@841: secs = secs.toString(); n@841: secs = secs.substr(0,2); n@841: mins = mins.toString(); n@841: this.curTimeSpan.textContent = mins+':'+secs; n@841: } else { n@841: time = time.toString(); n@841: this.curTimeSpan.textContent = time.substr(0,4); n@841: } n@841: } else { n@841: this.scrubberHead.style.left = '0px'; n@841: if (this.maxTime < 60) { n@841: this.curTimeSpan.textContent = '0.00'; n@841: } else { n@841: this.curTimeSpan.textContent = '00:00'; n@841: } n@841: } n@841: } n@841: }; n@841: n@841: this.interval = undefined; n@841: n@841: this.start = function() { n@841: if (this.playbackObject != undefined && this.interval == undefined) { n@841: if (this.maxTime < 60) { n@841: this.interval = setInterval(function(){interfaceContext.playhead.update();},10); n@841: } else { n@841: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); n@841: } n@841: } n@841: }; n@841: this.stop = function() { n@841: clearInterval(this.interval); n@841: this.interval = undefined; n@841: if (this.maxTime < 60) { n@841: this.curTimeSpan.textContent = '0.00'; n@841: } else { n@841: this.curTimeSpan.textContent = '00:00'; n@841: } n@841: }; n@841: }; n@841: n@841: // Global Checkers n@841: // These functions will help enforce the checkers n@841: this.checkHiddenAnchor = function() n@841: { n@841: var audioHolder = testState.currentStateMap[testState.currentIndex]; n@841: if (audioHolder.anchorId != null) n@841: { n@841: var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId]; n@841: if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) n@841: { n@841: // Anchor is not set below n@841: console.log('Anchor node not below marker value'); n@841: alert('Please keep listening'); n@841: return false; n@841: } n@841: } n@841: return true; n@841: }; n@841: n@841: this.checkHiddenReference = function() n@841: { n@841: var audioHolder = testState.currentStateMap[testState.currentIndex]; n@841: if (audioHolder.referenceId != null) n@841: { n@841: var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId]; n@841: if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) n@841: { n@841: // Anchor is not set below n@841: console.log('Reference node not above marker value'); n@841: alert('Please keep listening'); n@841: return false; n@841: } n@841: } n@841: return true; n@841: }; n@841: }