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