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