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