Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1102:b5bf2f57187c
Merge
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 08 Mar 2016 14:44:14 +0000 |
parents | 0a15fa67bda1 |
children | 83b439322229 |
comparison
equal
deleted
inserted
replaced
1101:a497058ae2ae | 1102:b5bf2f57187c |
---|---|
145 var r = new XMLHttpRequest(); | 145 var r = new XMLHttpRequest(); |
146 r.open('GET',url,true); | 146 r.open('GET',url,true); |
147 r.onload = function() { | 147 r.onload = function() { |
148 loadProjectSpecCallback(r.response); | 148 loadProjectSpecCallback(r.response); |
149 }; | 149 }; |
150 r.onerror = function() { | |
151 document.getElementsByTagName('body')[0].innerHTML = null; | |
152 var msg = document.createElement("h3"); | |
153 msg.textContent = "FATAL ERROR"; | |
154 var span = document.createElement("p"); | |
155 span.textContent = "There was an error when loading your XML file. Please check your path in the URL. After the path to this page, there should be '?url=path/to/your/file.xml'. Check the spelling of your filename as well. If you are still having issues, check the log of the python server or your webserver distribution for 404 codes for your file."; | |
156 document.getElementsByTagName('body')[0].appendChild(msg); | |
157 document.getElementsByTagName('body')[0].appendChild(span); | |
158 } | |
150 r.send(); | 159 r.send(); |
151 }; | 160 }; |
152 xmlhttp.send(); | 161 xmlhttp.send(); |
153 }; | 162 }; |
154 | 163 |
342 xmlhttp.onreadystatechange = function() { | 351 xmlhttp.onreadystatechange = function() { |
343 console.log(xmlhttp.status); | 352 console.log(xmlhttp.status); |
344 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { | 353 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) { |
345 createProjectSave(null); | 354 createProjectSave(null); |
346 } else { | 355 } else { |
347 if (xmlhttp.responseXML == null) | 356 var parser = new DOMParser(); |
357 var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml"); | |
358 if (xmlDoc == null) | |
348 { | 359 { |
349 createProjectSave('null'); | 360 createProjectSave('null'); |
350 } | 361 } |
351 var response = xmlhttp.responseXML.childNodes[0]; | 362 var response = xmlDoc.childNodes[0]; |
352 if (response.getAttribute('state') == "OK") | 363 if (response.getAttribute('state') == "OK") |
353 { | 364 { |
354 var file = response.getElementsByTagName('file')[0]; | 365 var file = response.getElementsByTagName('file')[0]; |
355 console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B'); | 366 console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B'); |
356 popup.showPopup(); | 367 popup.showPopup(); |
357 popup.popupContent.innerHTML = null; | 368 popup.popupContent.innerHTML = null; |
358 popup.popupContent.textContent = "Thank you!"; | 369 popup.popupContent.textContent = "Thank you!"; |
370 window.onbeforeunload=null; | |
359 } else { | 371 } else { |
360 var message = response.getElementsByTagName('message')[0]; | 372 var message = response.getElementsByTagName('message')[0]; |
361 errorSessionDump(message.textContent); | 373 errorSessionDump(message.textContent); |
362 } | 374 } |
363 } | 375 } |
364 }; | 376 }; |
365 xmlhttp.send(file); | 377 xmlhttp.send(file); |
366 popup.showPopup(); | 378 popup.showPopup(); |
367 popup.popupContent.innerHTML = null; | 379 popup.popupContent.innerHTML = null; |
368 popup.popupContent.textContent = "Submitting. Please Wait"; | 380 popup.popupContent.textContent = "Submitting. Please Wait"; |
381 popup.hideNextButton(); | |
382 popup.hidePreviousButton(); | |
369 } | 383 } |
370 } | 384 } |
371 | 385 |
372 function errorSessionDump(msg){ | 386 function errorSessionDump(msg){ |
373 // Create the partial interface XML save | 387 // Create the partial interface XML save |
734 var blank = document.getElementsByClassName('testHalt')[0]; | 748 var blank = document.getElementsByClassName('testHalt')[0]; |
735 blank.style.width = window.innerWidth; | 749 blank.style.width = window.innerWidth; |
736 blank.style.height = window.innerHeight; | 750 blank.style.height = window.innerHeight; |
737 } | 751 } |
738 }; | 752 }; |
753 this.hideNextButton = function() { | |
754 this.buttonProceed.style.visibility = "hidden"; | |
755 } | |
756 this.hidePreviousButton = function() { | |
757 this.buttonPrevious.style.visibility = "hidden"; | |
758 } | |
759 this.showNextButton = function() { | |
760 this.buttonProceed.style.visibility = "visible"; | |
761 } | |
762 this.showPreviousButton = function() { | |
763 this.buttonPrevious.style.visibility = "visible"; | |
764 } | |
739 } | 765 } |
740 | 766 |
741 function advanceState() | 767 function advanceState() |
742 { | 768 { |
743 // Just for complete clarity | 769 // Just for complete clarity |
775 { | 801 { |
776 pageHolder[i].presentedId = i; | 802 pageHolder[i].presentedId = i; |
777 } | 803 } |
778 for (var i=0; i<specification.pages.length; i++) | 804 for (var i=0; i<specification.pages.length; i++) |
779 { | 805 { |
780 if (specification.testPages < i && specification.testPages != 0) {break;} | 806 if (specification.testPages <= i && specification.testPages != 0) {break;} |
781 this.stateMap.push(pageHolder[i]); | 807 this.stateMap.push(pageHolder[i]); |
782 | 808 } |
783 } | 809 |
784 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;} | 810 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;} |
785 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;} | 811 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;} |
786 | 812 |
787 if (this.stateMap.length > 0) { | 813 if (this.stateMap.length > 0) { |
788 if(this.stateIndex != null) { | 814 if(this.stateIndex != null) { |
955 var bufferObj = this; | 981 var bufferObj = this; |
956 | 982 |
957 // Create callback to decode the data asynchronously | 983 // Create callback to decode the data asynchronously |
958 this.xmlRequest.onloadend = function() { | 984 this.xmlRequest.onloadend = function() { |
959 // Use inbuilt WAVE decoder first | 985 // Use inbuilt WAVE decoder first |
986 if (this.status == -1) {return;} | |
960 var waveObj = new WAVE(); | 987 var waveObj = new WAVE(); |
961 if (waveObj.open(bufferObj.xmlRequest.response) == 0) | 988 if (waveObj.open(bufferObj.xmlRequest.response) == 0) |
962 { | 989 { |
963 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate); | 990 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate); |
964 for (var c=0; c<waveObj.num_channels; c++) | 991 for (var c=0; c<waveObj.num_channels; c++) |
984 { | 1011 { |
985 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); | 1012 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); |
986 console.log('URL: '+audioObj.url); | 1013 console.log('URL: '+audioObj.url); |
987 errorSessionDump('Fragment '+audioObj.id+' 404 error'); | 1014 errorSessionDump('Fragment '+audioObj.id+' 404 error'); |
988 } | 1015 } |
989 this.status = -1; | 1016 this.parent.status = -1; |
990 } | 1017 } |
991 }); | 1018 }); |
992 } | 1019 } |
993 if (bufferObj.buffer != undefined) | 1020 if (bufferObj.buffer != undefined) |
994 { | 1021 { |
995 bufferObj.status = 2; | 1022 bufferObj.status = 2; |
996 calculateLoudness(bufferObj,"I"); | 1023 calculateLoudness(bufferObj,"I"); |
997 } | 1024 } |
998 }; | 1025 }; |
1026 | |
1027 // Create callback for any error in loading | |
1028 this.xmlRequest.onerror = function() { | |
1029 this.parent.status = -1; | |
1030 for (var i=0; i<this.parent.users.length; i++) | |
1031 { | |
1032 this.parent.users[i].state = -1; | |
1033 if (this.parent.users[i].interfaceDOM != null) | |
1034 { | |
1035 this.parent.users[i].bufferLoaded(this); | |
1036 } | |
1037 } | |
1038 } | |
1039 | |
999 this.progress = 0; | 1040 this.progress = 0; |
1000 this.progressCallback = function(event){ | 1041 this.progressCallback = function(event){ |
1001 if (event.lengthComputable) | 1042 if (event.lengthComputable) |
1002 { | 1043 { |
1003 this.parent.progress = event.loaded / event.total; | 1044 this.parent.progress = event.loaded / event.total; |
1025 for (var objects of this.users) | 1066 for (var objects of this.users) |
1026 { | 1067 { |
1027 if (audioObject.id == objects.id){return 0;} | 1068 if (audioObject.id == objects.id){return 0;} |
1028 } | 1069 } |
1029 this.users.push(audioObject); | 1070 this.users.push(audioObject); |
1030 if (this.status == 3) | 1071 if (this.status == 3 || this.status == -1) |
1031 { | 1072 { |
1032 // The buffer is already ready, trigger bufferLoaded | 1073 // The buffer is already ready, trigger bufferLoaded |
1033 audioObject.bufferLoaded(this); | 1074 audioObject.bufferLoaded(this); |
1034 } | 1075 } |
1035 } | 1076 } |
1138 return this.audioObjects[audioObjectId]; | 1179 return this.audioObjects[audioObjectId]; |
1139 }; | 1180 }; |
1140 | 1181 |
1141 this.newTestPage = function(audioHolderObject,store) { | 1182 this.newTestPage = function(audioHolderObject,store) { |
1142 this.pageStore = store; | 1183 this.pageStore = store; |
1143 this.state = 0; | 1184 this.status = 0; |
1144 this.audioObjectsReady = false; | 1185 this.audioObjectsReady = false; |
1145 this.metric.reset(); | 1186 this.metric.reset(); |
1146 for (var i=0; i < this.buffers.length; i++) | 1187 for (var i=0; i < this.buffers.length; i++) |
1147 { | 1188 { |
1148 this.buffers[i].users = []; | 1189 this.buffers[i].users = []; |
1240 | 1281 |
1241 this.bufferLoaded = function(callee) | 1282 this.bufferLoaded = function(callee) |
1242 { | 1283 { |
1243 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the | 1284 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the |
1244 // audioObject and trigger the interfaceDOM.enable() function for user feedback | 1285 // audioObject and trigger the interfaceDOM.enable() function for user feedback |
1286 if (callee.status == -1) { | |
1287 // ERROR | |
1288 this.state = -1; | |
1289 if (this.interfaceDOM != null) {this.interfaceDOM.error();} | |
1290 this.buffer = callee; | |
1291 return; | |
1292 } | |
1245 if (audioEngineContext.loopPlayback){ | 1293 if (audioEngineContext.loopPlayback){ |
1246 // First copy the buffer into this.buffer | 1294 // First copy the buffer into this.buffer |
1247 this.buffer = new audioEngineContext.bufferObj(); | 1295 this.buffer = new audioEngineContext.bufferObj(); |
1248 this.buffer.url = callee.url; | 1296 this.buffer.url = callee.url; |
1249 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate); | 1297 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate); |
1281 this.interfaceDOM = interfaceObject; | 1329 this.interfaceDOM = interfaceObject; |
1282 this.metric.initialise(interfaceObject.getValue()); | 1330 this.metric.initialise(interfaceObject.getValue()); |
1283 if (this.state == 1) | 1331 if (this.state == 1) |
1284 { | 1332 { |
1285 this.interfaceDOM.enable(); | 1333 this.interfaceDOM.enable(); |
1286 } | 1334 } else if (this.state == -1) { |
1335 // ERROR | |
1336 this.interfaceDOM.error(); | |
1337 return; | |
1338 } | |
1287 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId()); | 1339 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId()); |
1288 }; | 1340 }; |
1289 | 1341 |
1290 this.loopStart = function(setTime) { | 1342 this.loopStart = function(setTime) { |
1291 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime); | 1343 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime); |
1309 this.bufferNode.buffer = this.buffer.buffer; | 1361 this.bufferNode.buffer = this.buffer.buffer; |
1310 this.bufferNode.loop = audioEngineContext.loopPlayback; | 1362 this.bufferNode.loop = audioEngineContext.loopPlayback; |
1311 this.bufferNode.onended = function(event) { | 1363 this.bufferNode.onended = function(event) { |
1312 // Safari does not like using 'this' to reference the calling object! | 1364 // Safari does not like using 'this' to reference the calling object! |
1313 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); | 1365 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); |
1314 event.currentTarget.owner.stop(audioContext.currentTime+1); | 1366 if (event.currentTarget != null) { |
1367 event.currentTarget.owner.stop(audioContext.currentTime+1); | |
1368 } | |
1315 }; | 1369 }; |
1316 if (this.bufferNode.loop == false) { | 1370 if (this.bufferNode.loop == false) { |
1317 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 1371 this.metric.startListening(audioEngineContext.timer.getTestTime()); |
1318 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime); | 1372 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime); |
1319 this.interfaceDOM.startPlayback(); | 1373 this.interfaceDOM.startPlayback(); |
1320 } else { | 1374 } else { |
1321 this.outputGain.gain.setValueAtTime(0.0,startTime); | 1375 this.outputGain.gain.setValueAtTime(0.0,startTime); |
1322 } | 1376 } |
1323 this.bufferNode.start(startTime); | 1377 this.bufferNode.start(startTime); |
1324 this.bufferNode.playbackStartTime = startTime; | 1378 this.bufferNode.playbackStartTime = audioEngineContext.timer.getTestTime(); |
1325 } | 1379 } |
1326 }; | 1380 }; |
1327 | 1381 |
1328 this.stop = function(stopTime) { | 1382 this.stop = function(stopTime) { |
1329 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); | 1383 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); |
1338 }; | 1392 }; |
1339 | 1393 |
1340 this.getCurrentPosition = function() { | 1394 this.getCurrentPosition = function() { |
1341 var time = audioEngineContext.timer.getTestTime(); | 1395 var time = audioEngineContext.timer.getTestTime(); |
1342 if (this.bufferNode != undefined) { | 1396 if (this.bufferNode != undefined) { |
1343 return (time - this.bufferNode.playbackStartTime)%this.buffer.buffer.duration; | 1397 var position = (time - this.bufferNode.playbackStartTime)%this.buffer.buffer.duration; |
1398 if (isNaN(position)){return 0;} | |
1399 return position; | |
1344 } else { | 1400 } else { |
1345 return 0; | 1401 return 0; |
1346 } | 1402 } |
1347 }; | 1403 }; |
1348 | 1404 |
1561 if (audioEngineContext.metric.enableElementTracker) { | 1617 if (audioEngineContext.metric.enableElementTracker) { |
1562 var elementTrackerFull = storage.document.createElement('metricResult'); | 1618 var elementTrackerFull = storage.document.createElement('metricResult'); |
1563 elementTrackerFull.setAttribute('name','elementTrackerFull'); | 1619 elementTrackerFull.setAttribute('name','elementTrackerFull'); |
1564 for (var k=0; k<this.movementTracker.length; k++) | 1620 for (var k=0; k<this.movementTracker.length; k++) |
1565 { | 1621 { |
1566 var timePos = storage.document.createElement('timePos'); | 1622 var timePos = storage.document.createElement('movement'); |
1567 timePos.id = k; | 1623 timePos.setAttribute("time",this.movementTracker[k][0]); |
1568 var time = storage.document.createElement('time'); | 1624 timePos.setAttribute("value",this.movementTracker[k][1]); |
1569 time.textContent = this.movementTracker[k][0]; | |
1570 var position = document.createElement('position'); | |
1571 position.textContent = this.movementTracker[k][1]; | |
1572 timePos.appendChild(time); | |
1573 timePos.appendChild(position); | |
1574 elementTrackerFull.appendChild(timePos); | 1625 elementTrackerFull.appendChild(timePos); |
1575 } | 1626 } |
1576 storeDOM.push(elementTrackerFull); | 1627 storeDOM.push(elementTrackerFull); |
1577 } | 1628 } |
1578 if (audioEngineContext.metric.enableElementListenTracker) { | 1629 if (audioEngineContext.metric.enableElementListenTracker) { |
1908 } | 1959 } |
1909 }; | 1960 }; |
1910 | 1961 |
1911 this.exportXML = function(doc) | 1962 this.exportXML = function(doc) |
1912 { | 1963 { |
1913 var node = doc.createElement('surveyelement'); | 1964 var node = doc.createElement('surveyentry'); |
1914 node.setAttribute('type',this.type); | 1965 node.setAttribute('type',this.type); |
1915 var statement = doc.createElement('statement'); | 1966 var statement = doc.createElement('statement'); |
1916 statement.textContent = this.statement; | 1967 statement.textContent = this.statement; |
1917 node.appendChild(statement); | 1968 node.appendChild(statement); |
1918 switch(this.type) | 1969 switch(this.type) |
1919 { | 1970 { |
1920 case "statement": | 1971 case "statement": |
1921 break; | 1972 break; |
1922 case "question": | 1973 case "question": |
1923 node.id = this.id; | 1974 node.id = this.id; |
1924 node.setAttribute("mandatory",this.mandatory); | 1975 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);} |
1925 node.setAttribute("boxsize",this.boxsize); | 1976 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);} |
1926 break; | 1977 break; |
1927 case "number": | 1978 case "number": |
1928 node.id = this.id; | 1979 node.id = this.id; |
1929 node.setAttribute("mandatory",this.mandatory); | 1980 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);} |
1930 node.setAttribute("min", this.min); | 1981 if (this.min != undefined) {node.setAttribute("min", this.min);} |
1931 node.setAttribute("max", this.max); | 1982 if (this.max != undefined) {node.setAttribute("max", this.max);} |
1932 node.setAttribute("step", this.step); | 1983 break; |
1933 break; | |
1934 case "checkbox": | 1984 case "checkbox": |
1935 case "radio": | 1985 case "radio": |
1936 node.id = this.id; | 1986 node.id = this.id; |
1937 for (var i=0; i<this.options.length; i++) | 1987 for (var i=0; i<this.options.length; i++) |
1938 { | 1988 { |
2252 this.audioElementNode = function() { | 2302 this.audioElementNode = function() { |
2253 this.url = null; | 2303 this.url = null; |
2254 this.id = null; | 2304 this.id = null; |
2255 this.parent = null; | 2305 this.parent = null; |
2256 this.type = null; | 2306 this.type = null; |
2257 this.marker = false; | 2307 this.marker = null; |
2258 this.enforce = false; | 2308 this.enforce = false; |
2259 this.gain = 1.0; | 2309 this.gain = 0.0; |
2260 this.schema = specification.schema.getAllElementsByName('audioelement')[0];; | 2310 this.schema = specification.schema.getAllElementsByName('audioelement')[0];; |
2261 this.parent = null; | 2311 this.parent = null; |
2262 this.decode = function(parent,xml) | 2312 this.decode = function(parent,xml) |
2263 { | 2313 { |
2264 this.parent = parent; | 2314 this.parent = parent; |
2308 this.insertPoint = document.getElementById("topLevelBody"); | 2358 this.insertPoint = document.getElementById("topLevelBody"); |
2309 | 2359 |
2310 this.newPage = function(audioHolderObject,store) | 2360 this.newPage = function(audioHolderObject,store) |
2311 { | 2361 { |
2312 audioEngineContext.newTestPage(audioHolderObject,store); | 2362 audioEngineContext.newTestPage(audioHolderObject,store); |
2313 interfaceContext.deleteCommentBoxes(); | 2363 interfaceContext.commentBoxes.deleteCommentBoxes(); |
2314 interfaceContext.deleteCommentQuestions(); | 2364 interfaceContext.deleteCommentQuestions(); |
2315 loadTest(audioHolderObject,store); | 2365 loadTest(audioHolderObject,store); |
2316 }; | 2366 }; |
2317 | 2367 |
2318 // Bounded by interface!! | 2368 // Bounded by interface!! |
2356 node.appendChild(userAgent); | 2406 node.appendChild(userAgent); |
2357 node.appendChild(screen); | 2407 node.appendChild(screen); |
2358 return node; | 2408 return node; |
2359 }; | 2409 }; |
2360 | 2410 |
2361 this.commentBoxes = []; | 2411 this.commentBoxes = new function() { |
2362 this.elementCommentBox = function(audioObject) { | 2412 this.boxes = []; |
2363 var element = audioObject.specification; | 2413 this.injectPoint = null; |
2364 this.audioObject = audioObject; | 2414 this.elementCommentBox = function(audioObject) { |
2365 this.id = audioObject.id; | 2415 var element = audioObject.specification; |
2366 var audioHolderObject = audioObject.specification.parent; | 2416 this.audioObject = audioObject; |
2367 // Create document objects to hold the comment boxes | 2417 this.id = audioObject.id; |
2368 this.trackComment = document.createElement('div'); | 2418 var audioHolderObject = audioObject.specification.parent; |
2369 this.trackComment.className = 'comment-div'; | 2419 // Create document objects to hold the comment boxes |
2370 this.trackComment.id = 'comment-div-'+audioObject.id; | 2420 this.trackComment = document.createElement('div'); |
2371 // Create a string next to each comment asking for a comment | 2421 this.trackComment.className = 'comment-div'; |
2372 this.trackString = document.createElement('span'); | 2422 this.trackComment.id = 'comment-div-'+audioObject.id; |
2373 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId(); | 2423 // Create a string next to each comment asking for a comment |
2374 // Create the HTML5 comment box 'textarea' | 2424 this.trackString = document.createElement('span'); |
2375 this.trackCommentBox = document.createElement('textarea'); | 2425 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId(); |
2376 this.trackCommentBox.rows = '4'; | 2426 // Create the HTML5 comment box 'textarea' |
2377 this.trackCommentBox.cols = '100'; | 2427 this.trackCommentBox = document.createElement('textarea'); |
2378 this.trackCommentBox.name = 'trackComment'+audioObject.id; | 2428 this.trackCommentBox.rows = '4'; |
2379 this.trackCommentBox.className = 'trackComment'; | 2429 this.trackCommentBox.cols = '100'; |
2380 var br = document.createElement('br'); | 2430 this.trackCommentBox.name = 'trackComment'+audioObject.id; |
2381 // Add to the holder. | 2431 this.trackCommentBox.className = 'trackComment'; |
2382 this.trackComment.appendChild(this.trackString); | 2432 var br = document.createElement('br'); |
2383 this.trackComment.appendChild(br); | 2433 // Add to the holder. |
2384 this.trackComment.appendChild(this.trackCommentBox); | 2434 this.trackComment.appendChild(this.trackString); |
2385 | 2435 this.trackComment.appendChild(br); |
2386 this.exportXMLDOM = function() { | 2436 this.trackComment.appendChild(this.trackCommentBox); |
2387 var root = document.createElement('comment'); | 2437 |
2388 var question = document.createElement('question'); | 2438 this.exportXMLDOM = function() { |
2389 question.textContent = this.trackString.textContent; | 2439 var root = document.createElement('comment'); |
2390 var response = document.createElement('response'); | 2440 var question = document.createElement('question'); |
2391 response.textContent = this.trackCommentBox.value; | 2441 question.textContent = this.trackString.textContent; |
2392 console.log("Comment frag-"+this.id+": "+response.textContent); | 2442 var response = document.createElement('response'); |
2393 root.appendChild(question); | 2443 response.textContent = this.trackCommentBox.value; |
2394 root.appendChild(response); | 2444 console.log("Comment frag-"+this.id+": "+response.textContent); |
2395 return root; | 2445 root.appendChild(question); |
2396 }; | 2446 root.appendChild(response); |
2397 this.resize = function() | 2447 return root; |
2398 { | 2448 }; |
2399 var boxwidth = (window.innerWidth-100)/2; | 2449 this.resize = function() |
2400 if (boxwidth >= 600) | 2450 { |
2401 { | 2451 var boxwidth = (window.innerWidth-100)/2; |
2402 boxwidth = 600; | 2452 if (boxwidth >= 600) |
2403 } | 2453 { |
2404 else if (boxwidth < 400) | 2454 boxwidth = 600; |
2405 { | 2455 } |
2406 boxwidth = 400; | 2456 else if (boxwidth < 400) |
2407 } | 2457 { |
2408 this.trackComment.style.width = boxwidth+"px"; | 2458 boxwidth = 400; |
2409 this.trackCommentBox.style.width = boxwidth-6+"px"; | 2459 } |
2410 }; | 2460 this.trackComment.style.width = boxwidth+"px"; |
2411 this.resize(); | 2461 this.trackCommentBox.style.width = boxwidth-6+"px"; |
2412 }; | 2462 }; |
2463 this.resize(); | |
2464 }; | |
2465 this.createCommentBox = function(audioObject) { | |
2466 var node = new this.elementCommentBox(audioObject); | |
2467 this.boxes.push(node); | |
2468 audioObject.commentDOM = node; | |
2469 return node; | |
2470 }; | |
2471 this.sortCommentBoxes = function() { | |
2472 this.boxes.sort(function(a,b){return a.id - b.id;}); | |
2473 }; | |
2474 | |
2475 this.showCommentBoxes = function(inject, sort) { | |
2476 this.injectPoint = inject; | |
2477 if (sort) {this.sortCommentBoxes();} | |
2478 for (var box of this.boxes) { | |
2479 inject.appendChild(box.trackComment); | |
2480 } | |
2481 }; | |
2482 | |
2483 this.deleteCommentBoxes = function() { | |
2484 if (this.injectPoint != null) { | |
2485 for (var box of this.boxes) { | |
2486 this.injectPoint.removeChild(box.trackComment); | |
2487 } | |
2488 this.injectPoint = null; | |
2489 } | |
2490 this.boxes = []; | |
2491 }; | |
2492 } | |
2413 | 2493 |
2414 this.commentQuestions = []; | 2494 this.commentQuestions = []; |
2415 | 2495 |
2416 this.commentBox = function(commentQuestion) { | 2496 this.commentBox = function(commentQuestion) { |
2417 this.specification = commentQuestion; | 2497 this.specification = commentQuestion; |
2675 text.style.marginRight = spanMargin; | 2755 text.style.marginRight = spanMargin; |
2676 text.style.marginLeft = spanMargin; | 2756 text.style.marginLeft = spanMargin; |
2677 } | 2757 } |
2678 }; | 2758 }; |
2679 this.resize(); | 2759 this.resize(); |
2680 }; | |
2681 | |
2682 this.createCommentBox = function(audioObject) { | |
2683 var node = new this.elementCommentBox(audioObject); | |
2684 this.commentBoxes.push(node); | |
2685 audioObject.commentDOM = node; | |
2686 return node; | |
2687 }; | |
2688 | |
2689 this.sortCommentBoxes = function() { | |
2690 this.commentBoxes.sort(function(a,b){return a.id - b.id;}); | |
2691 }; | |
2692 | |
2693 this.showCommentBoxes = function(inject, sort) { | |
2694 if (sort) {interfaceContext.sortCommentBoxes();} | |
2695 for (var box of interfaceContext.commentBoxes) { | |
2696 inject.appendChild(box.trackComment); | |
2697 } | |
2698 }; | |
2699 | |
2700 this.deleteCommentBoxes = function() { | |
2701 this.commentBoxes = []; | |
2702 }; | 2760 }; |
2703 | 2761 |
2704 this.createCommentQuestion = function(element) { | 2762 this.createCommentQuestion = function(element) { |
2705 var node; | 2763 var node; |
2706 if (element.type == 'question') { | 2764 if (element.type == 'question') { |
3034 // Holds results in XML format until ready for collection | 3092 // Holds results in XML format until ready for collection |
3035 this.globalPreTest = null; | 3093 this.globalPreTest = null; |
3036 this.globalPostTest = null; | 3094 this.globalPostTest = null; |
3037 this.testPages = []; | 3095 this.testPages = []; |
3038 this.document = document.implementation.createDocument(null,"waetresult"); | 3096 this.document = document.implementation.createDocument(null,"waetresult"); |
3039 this.root = this.document.children[0]; | 3097 this.root = this.document.childNodes[0]; |
3040 this.state = 0; | 3098 this.state = 0; |
3041 | 3099 |
3042 this.initialise = function() | 3100 this.initialise = function() |
3043 { | 3101 { |
3044 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} | 3102 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} |