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