Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1048:7a8fcf04aad3
Merge
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Mon, 29 Jun 2015 19:04:40 +0100 |
parents | 8ab5f8969856 01fcd75067c1 |
children | a37ab38cf90b |
comparison
equal
deleted
inserted
replaced
885:ba83143187d6 | 1048:7a8fcf04aad3 |
---|---|
202 var span = document.createElement('span'); | 202 var span = document.createElement('span'); |
203 span.textContent = node.statement; | 203 span.textContent = node.statement; |
204 this.popupContent.appendChild(span); | 204 this.popupContent.appendChild(span); |
205 this.popupContent.appendChild(document.createElement('br')); | 205 this.popupContent.appendChild(document.createElement('br')); |
206 var input = document.createElement('input'); | 206 var input = document.createElement('input'); |
207 input.type = 'number'; | 207 input.type = 'textarea'; |
208 if (node.min != null) {input.min = node.min;} | 208 if (node.min != null) {input.min = node.min;} |
209 if (node.max != null) {input.max = node.max;} | 209 if (node.max != null) {input.max = node.max;} |
210 if (node.step != null) {input.step = node.step;} | 210 if (node.step != null) {input.step = node.step;} |
211 this.popupContent.appendChild(input); | 211 this.popupContent.appendChild(input); |
212 } | 212 } |
296 if (node.mandatory == true && input.value.length == 0) { | 296 if (node.mandatory == true && input.value.length == 0) { |
297 alert('This question is mandatory. Please enter a number'); | 297 alert('This question is mandatory. Please enter a number'); |
298 return; | 298 return; |
299 } | 299 } |
300 var enteredNumber = Number(input.value); | 300 var enteredNumber = Number(input.value); |
301 if (enteredNumber == undefined) { | 301 if (isNaN(enteredNumber)) { |
302 alert('Please enter a valid number'); | 302 alert('Please enter a valid number'); |
303 return; | 303 return; |
304 } | 304 } |
305 if (enteredNumber < node.min && node.min != null) { | 305 if (enteredNumber < node.min && node.min != null) { |
306 alert('Number is below the minimum value of '+node.min); | 306 alert('Number is below the minimum value of '+node.min); |
636 | 636 |
637 // Only other global function which must be defined in the interface class. Determines how to create the XML document. | 637 // Only other global function which must be defined in the interface class. Determines how to create the XML document. |
638 function interfaceXMLSave(){ | 638 function interfaceXMLSave(){ |
639 // Create the XML string to be exported with results | 639 // Create the XML string to be exported with results |
640 var xmlDoc = document.createElement("BrowserEvaluationResult"); | 640 var xmlDoc = document.createElement("BrowserEvaluationResult"); |
641 var projectDocument = specification.projectXML; | |
642 projectDocument.setAttribute('file-name',url); | |
643 xmlDoc.appendChild(projectDocument); | |
641 xmlDoc.appendChild(returnDateNode()); | 644 xmlDoc.appendChild(returnDateNode()); |
642 for (var i=0; i<testState.stateResults.length; i++) | 645 for (var i=0; i<testState.stateResults.length; i++) |
643 { | 646 { |
644 xmlDoc.appendChild(testState.stateResults[i]); | 647 xmlDoc.appendChild(testState.stateResults[i]); |
645 } | 648 } |
890 | 893 |
891 this.exportXMLDOM = function() { | 894 this.exportXMLDOM = function() { |
892 var root = document.createElement('audioElement'); | 895 var root = document.createElement('audioElement'); |
893 root.id = this.specification.id; | 896 root.id = this.specification.id; |
894 root.setAttribute('url',this.url); | 897 root.setAttribute('url',this.url); |
895 root.appendChild(this.interfaceDOM.exportXMLDOM(this)); | 898 var file = document.createElement('file'); |
896 root.appendChild(this.commentDOM.exportXMLDOM(this)); | 899 file.setAttribute('sampleRate',this.buffer.sampleRate); |
900 file.setAttribute('channels',this.buffer.numberOfChannels); | |
901 file.setAttribute('sampleCount',this.buffer.length); | |
902 file.setAttribute('duration',this.buffer.duration); | |
903 root.appendChild(file); | |
904 if (this.specification.type != 'outsidereference') { | |
905 root.appendChild(this.interfaceDOM.exportXMLDOM(this)); | |
906 root.appendChild(this.commentDOM.exportXMLDOM(this)); | |
907 } | |
897 root.appendChild(this.metric.exportXMLDOM()); | 908 root.appendChild(this.metric.exportXMLDOM()); |
898 return root; | 909 return root; |
899 }; | 910 }; |
900 } | 911 } |
901 | 912 |
1211 | 1222 |
1212 this.audioHolders = []; | 1223 this.audioHolders = []; |
1213 | 1224 |
1214 this.decode = function() { | 1225 this.decode = function() { |
1215 // projectXML - DOM Parsed document | 1226 // projectXML - DOM Parsed document |
1227 this.projectXML = projectXML.childNodes[0]; | |
1216 var setupNode = projectXML.getElementsByTagName('setup')[0]; | 1228 var setupNode = projectXML.getElementsByTagName('setup')[0]; |
1217 this.interfaceType = setupNode.getAttribute('interface'); | 1229 this.interfaceType = setupNode.getAttribute('interface'); |
1218 this.projectReturn = setupNode.getAttribute('projectReturn'); | 1230 this.projectReturn = setupNode.getAttribute('projectReturn'); |
1219 if (setupNode.getAttribute('randomiseOrder') == "true") { | 1231 if (setupNode.getAttribute('randomiseOrder') == "true") { |
1220 this.randomiseOrder = true; | 1232 this.randomiseOrder = true; |
1244 this.commonInterface = new function() { | 1256 this.commonInterface = new function() { |
1245 this.OptionNode = function(child) { | 1257 this.OptionNode = function(child) { |
1246 this.type = child.nodeName; | 1258 this.type = child.nodeName; |
1247 if (this.type == 'check') { | 1259 if (this.type == 'check') { |
1248 this.check = child.getAttribute('name'); | 1260 this.check = child.getAttribute('name'); |
1261 if (this.check == 'scalerange') { | |
1262 this.min = child.getAttribute('min'); | |
1263 this.max = child.getAttribute('max'); | |
1264 if (this.min == null) {this.min = 1;} | |
1265 else if (Number(this.min) > 1 && this.min != null) { | |
1266 this.min = Number(this.min)/100; | |
1267 } else { | |
1268 this.min = Number(this.min); | |
1269 } | |
1270 if (this.max == null) {this.max = 0;} | |
1271 else if (Number(this.max) > 1 && this.max != null) { | |
1272 this.max = Number(this.max)/100; | |
1273 } else { | |
1274 this.max = Number(this.max); | |
1275 } | |
1276 } | |
1249 } else if (this.type == 'anchor' || this.type == 'reference') { | 1277 } else if (this.type == 'anchor' || this.type == 'reference') { |
1250 this.value = Number(child.textContent); | 1278 this.value = Number(child.textContent); |
1251 } | 1279 } |
1252 }; | 1280 }; |
1253 this.options = []; | 1281 this.options = []; |
1343 this.type = 'audioHolder'; | 1371 this.type = 'audioHolder'; |
1344 this.interfaceNode = function(DOM) { | 1372 this.interfaceNode = function(DOM) { |
1345 var title = DOM.getElementsByTagName('title'); | 1373 var title = DOM.getElementsByTagName('title'); |
1346 if (title.length == 0) {this.title = null;} | 1374 if (title.length == 0) {this.title = null;} |
1347 else {this.title = title[0].textContent;} | 1375 else {this.title = title[0].textContent;} |
1348 | 1376 this.options = parent.commonInterface.options; |
1349 var scale = DOM.getElementsByTagName('scale'); | 1377 var scale = DOM.getElementsByTagName('scale'); |
1350 this.scale = []; | 1378 this.scale = []; |
1351 for (var i=0; i<scale.length; i++) { | 1379 for (var i=0; i<scale.length; i++) { |
1352 var arr = [null, null]; | 1380 var arr = [null, null]; |
1353 arr[0] = scale[i].getAttribute('position'); | 1381 arr[0] = scale[i].getAttribute('position'); |
1358 | 1386 |
1359 this.audioElementNode = function(parent,xml) { | 1387 this.audioElementNode = function(parent,xml) { |
1360 this.url = xml.getAttribute('url'); | 1388 this.url = xml.getAttribute('url'); |
1361 this.id = xml.id; | 1389 this.id = xml.id; |
1362 this.parent = parent; | 1390 this.parent = parent; |
1363 this.anchor = xml.getAttribute('anchor'); | 1391 this.type = xml.getAttribute('type'); |
1364 if (this.anchor == 'true') {this.anchor = true;} | 1392 if (this.type == null) {this.type = "normal";} |
1393 if (this.type == 'anchor') {this.anchor = true;} | |
1365 else {this.anchor = false;} | 1394 else {this.anchor = false;} |
1366 | 1395 if (this.type == 'reference') {this.reference = true;} |
1367 this.reference = xml.getAttribute('reference'); | |
1368 if (this.reference == 'true') {this.reference = true;} | |
1369 else {this.reference = false;} | 1396 else {this.reference = false;} |
1370 | 1397 |
1371 if (this.anchor == true && this.reference == true) { | 1398 this.marker = xml.getAttribute('marker'); |
1372 console.log('ERROR - Cannot have one audioElement be both the reference and anchor!'); | 1399 if (this.marker == null) {this.marker = undefined;} |
1373 console.log(this); | 1400 |
1374 console.log('Neither reference nor anchor will be enabled on this fragment'); | 1401 if (this.anchor == true && this.marker == undefined) { |
1375 this.anchor = false; | |
1376 this.reference = false; | |
1377 } | |
1378 if (this.anchor == true) { | |
1379 this.marker = anchor; | 1402 this.marker = anchor; |
1380 } | 1403 } |
1381 if (this.reference == true) { | 1404 else if (this.reference == true && this.marker == undefined) { |
1382 this.marker = reference; | 1405 this.marker = reference; |
1406 } | |
1407 | |
1408 if (this.marker != undefined) { | |
1409 this.marker = Number(this.marker); | |
1410 if (this.marker > 1) {this.marker /= 100;} | |
1383 } | 1411 } |
1384 }; | 1412 }; |
1385 | 1413 |
1386 this.commentQuestionNode = function(xml) { | 1414 this.commentQuestionNode = function(xml) { |
1387 this.childOption = function(element) { | 1415 this.childOption = function(element) { |
1492 this.commentBoxPrefix = "Comment on track"; | 1520 this.commentBoxPrefix = "Comment on track"; |
1493 } | 1521 } |
1494 | 1522 |
1495 this.audioElements =[]; | 1523 this.audioElements =[]; |
1496 var audioElementsDOM = xml.getElementsByTagName('audioElements'); | 1524 var audioElementsDOM = xml.getElementsByTagName('audioElements'); |
1525 this.outsideReference = null; | |
1497 for (var i=0; i<audioElementsDOM.length; i++) { | 1526 for (var i=0; i<audioElementsDOM.length; i++) { |
1498 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i])); | 1527 if (audioElementsDOM[i].getAttribute('type') == 'outsidereference') { |
1528 if (this.outsideReference == null) { | |
1529 this.outsideReference = new this.audioElementNode(this,audioElementsDOM[i]); | |
1530 } else { | |
1531 console.log('Error only one audioelement can be of type outsidereference per audioholder'); | |
1532 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i])); | |
1533 console.log('Element id '+audioElementsDOM[i].id+' made into normal node'); | |
1534 } | |
1535 } else { | |
1536 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i])); | |
1537 } | |
1538 } | |
1539 | |
1540 if (this.randomiseOrder) { | |
1541 this.audioElements = randomiseOrder(this.audioElements); | |
1499 } | 1542 } |
1500 | 1543 |
1501 // Check only one anchor and one reference per audioNode | 1544 // Check only one anchor and one reference per audioNode |
1502 var anchor = []; | 1545 var anchor = []; |
1503 var reference = []; | 1546 var reference = []; |
1547 this.anchorId = null; | |
1548 this.referenceId = null; | |
1504 for (var i=0; i<this.audioElements.length; i++) | 1549 for (var i=0; i<this.audioElements.length; i++) |
1505 { | 1550 { |
1506 if (this.audioElements[i].anchor == true) {anchor.push(i);} | 1551 if (this.audioElements[i].anchor == true) {anchor.push(i);} |
1507 if (this.audioElements[i].reference == true) {reference.push(i);} | 1552 if (this.audioElements[i].reference == true) {reference.push(i);} |
1508 } | 1553 } |
1513 for (var i=0; i<anchor.length; i++) | 1558 for (var i=0; i<anchor.length; i++) |
1514 { | 1559 { |
1515 this.audioElements[anchor[i]].anchor = false; | 1560 this.audioElements[anchor[i]].anchor = false; |
1516 this.audioElements[anchor[i]].value = undefined; | 1561 this.audioElements[anchor[i]].value = undefined; |
1517 } | 1562 } |
1518 } | 1563 } else {this.anchorId = anchor[0];} |
1519 if (reference.length > 1) { | 1564 if (reference.length > 1) { |
1520 console.log('Error - cannot have more than one anchor!'); | 1565 console.log('Error - cannot have more than one anchor!'); |
1521 console.log('Each anchor node will be a normal mode to continue the test'); | 1566 console.log('Each anchor node will be a normal mode to continue the test'); |
1522 for (var i=0; i<reference.length; i++) | 1567 for (var i=0; i<reference.length; i++) |
1523 { | 1568 { |
1524 this.audioElements[reference[i]].reference = false; | 1569 this.audioElements[reference[i]].reference = false; |
1525 this.audioElements[reference[i]].value = undefined; | 1570 this.audioElements[reference[i]].value = undefined; |
1526 } | 1571 } |
1527 } | 1572 } else {this.referenceId = reference[0];} |
1528 | 1573 |
1529 this.commentQuestions = []; | 1574 this.commentQuestions = []; |
1530 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); | 1575 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); |
1531 for (var i=0; i<commentQuestionsDOM.length; i++) { | 1576 for (var i=0; i<commentQuestionsDOM.length; i++) { |
1532 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i])); | 1577 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i])); |
1796 } | 1841 } |
1797 }; | 1842 }; |
1798 | 1843 |
1799 this.deleteCommentBoxes = function() { | 1844 this.deleteCommentBoxes = function() { |
1800 this.commentBoxes = []; | 1845 this.commentBoxes = []; |
1801 } | 1846 }; |
1802 | 1847 |
1803 this.createCommentQuestion = function(element) { | 1848 this.createCommentQuestion = function(element) { |
1804 var node; | 1849 var node; |
1805 if (element.type == 'text') { | 1850 if (element.type == 'text') { |
1806 node = new this.commentBox(element); | 1851 node = new this.commentBox(element); |
1886 this.stop = function() { | 1931 this.stop = function() { |
1887 clearInterval(this.interval); | 1932 clearInterval(this.interval); |
1888 this.interval = undefined; | 1933 this.interval = undefined; |
1889 }; | 1934 }; |
1890 }; | 1935 }; |
1936 | |
1937 // Global Checkers | |
1938 // These functions will help enforce the checkers | |
1939 this.checkHiddenAnchor = function() | |
1940 { | |
1941 var audioHolder = testState.currentStateMap[testState.currentIndex]; | |
1942 if (audioHolder.anchorId != null) | |
1943 { | |
1944 var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId]; | |
1945 if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker) | |
1946 { | |
1947 // Anchor is not set below | |
1948 console.log('Anchor node not below marker value'); | |
1949 alert('Please keep listening'); | |
1950 return false; | |
1951 } | |
1952 } | |
1953 return true; | |
1954 }; | |
1955 | |
1956 this.checkHiddenReference = function() | |
1957 { | |
1958 var audioHolder = testState.currentStateMap[testState.currentIndex]; | |
1959 if (audioHolder.referenceId != null) | |
1960 { | |
1961 var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId]; | |
1962 if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker) | |
1963 { | |
1964 // Anchor is not set below | |
1965 console.log('Reference node not above marker value'); | |
1966 alert('Please keep listening'); | |
1967 return false; | |
1968 } | |
1969 } | |
1970 return true; | |
1971 }; | |
1891 } | 1972 } |
1892 | 1973 |