comparison core.js @ 2049:ce79548fb1f0

Updated #1272 and #1271 preparing for #1270
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Sat, 20 Jun 2015 14:57:14 +0100
parents 66fadacad41d
children dc531fbf64c3
comparison
equal deleted inserted replaced
2048:66fadacad41d 2049:ce79548fb1f0
1380 1380
1381 this.audioElementNode = function(parent,xml) { 1381 this.audioElementNode = function(parent,xml) {
1382 this.url = xml.getAttribute('url'); 1382 this.url = xml.getAttribute('url');
1383 this.id = xml.id; 1383 this.id = xml.id;
1384 this.parent = parent; 1384 this.parent = parent;
1385 this.anchor = xml.getAttribute('anchor'); 1385 this.type = xml.getAttribute('type');
1386 if (this.anchor == 'true') {this.anchor = true;} 1386 if (this.type == null) {this.type = "normal";}
1387 if (this.type == 'anchor') {this.anchor = true;}
1387 else {this.anchor = false;} 1388 else {this.anchor = false;}
1388 1389 if (this.type == 'reference') {this.reference = true;}
1389 this.reference = xml.getAttribute('reference');
1390 if (this.reference == 'true') {this.reference = true;}
1391 else {this.reference = false;} 1390 else {this.reference = false;}
1392 1391
1393 if (this.anchor == true && this.reference == true) { 1392 this.marker = xml.getAttribute('marker');
1394 console.log('ERROR - Cannot have one audioElement be both the reference and anchor!'); 1393 if (this.marker == null) {this.marker = undefined;}
1395 console.log(this); 1394
1396 console.log('Neither reference nor anchor will be enabled on this fragment'); 1395 if (this.anchor == true && this.marker == undefined) {
1397 this.anchor = false;
1398 this.reference = false;
1399 }
1400 if (this.anchor == true) {
1401 this.marker = anchor; 1396 this.marker = anchor;
1402 } 1397 }
1403 if (this.reference == true) { 1398 else if (this.reference == true && this.marker == undefined) {
1404 this.marker = reference; 1399 this.marker = reference;
1400 }
1401
1402 if (this.marker != undefined) {
1403 this.marker = Number(this.marker);
1404 if (this.marker > 1) {this.marker /= 100;}
1405 } 1405 }
1406 }; 1406 };
1407 1407
1408 this.commentQuestionNode = function(xml) { 1408 this.commentQuestionNode = function(xml) {
1409 this.childOption = function(element) { 1409 this.childOption = function(element) {
1518 var audioElementsDOM = xml.getElementsByTagName('audioElements'); 1518 var audioElementsDOM = xml.getElementsByTagName('audioElements');
1519 for (var i=0; i<audioElementsDOM.length; i++) { 1519 for (var i=0; i<audioElementsDOM.length; i++) {
1520 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i])); 1520 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
1521 } 1521 }
1522 1522
1523 if (this.randomiseOrder) {
1524 this.audioElements = randomiseOrder(this.audioElements);
1525 }
1526
1523 // Check only one anchor and one reference per audioNode 1527 // Check only one anchor and one reference per audioNode
1524 var anchor = []; 1528 var anchor = [];
1525 var reference = []; 1529 var reference = [];
1530 this.anchorId = null;
1531 this.referenceId = null;
1526 for (var i=0; i<this.audioElements.length; i++) 1532 for (var i=0; i<this.audioElements.length; i++)
1527 { 1533 {
1528 if (this.audioElements[i].anchor == true) {anchor.push(i);} 1534 if (this.audioElements[i].anchor == true) {anchor.push(i);}
1529 if (this.audioElements[i].reference == true) {reference.push(i);} 1535 if (this.audioElements[i].reference == true) {reference.push(i);}
1530 } 1536 }
1535 for (var i=0; i<anchor.length; i++) 1541 for (var i=0; i<anchor.length; i++)
1536 { 1542 {
1537 this.audioElements[anchor[i]].anchor = false; 1543 this.audioElements[anchor[i]].anchor = false;
1538 this.audioElements[anchor[i]].value = undefined; 1544 this.audioElements[anchor[i]].value = undefined;
1539 } 1545 }
1540 } 1546 } else {this.anchorId = anchor[0];}
1541 if (reference.length > 1) { 1547 if (reference.length > 1) {
1542 console.log('Error - cannot have more than one anchor!'); 1548 console.log('Error - cannot have more than one anchor!');
1543 console.log('Each anchor node will be a normal mode to continue the test'); 1549 console.log('Each anchor node will be a normal mode to continue the test');
1544 for (var i=0; i<reference.length; i++) 1550 for (var i=0; i<reference.length; i++)
1545 { 1551 {
1546 this.audioElements[reference[i]].reference = false; 1552 this.audioElements[reference[i]].reference = false;
1547 this.audioElements[reference[i]].value = undefined; 1553 this.audioElements[reference[i]].value = undefined;
1548 } 1554 }
1549 } 1555 } else {this.referenceId = reference[0];}
1550 1556
1551 this.commentQuestions = []; 1557 this.commentQuestions = [];
1552 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); 1558 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
1553 for (var i=0; i<commentQuestionsDOM.length; i++) { 1559 for (var i=0; i<commentQuestionsDOM.length; i++) {
1554 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i])); 1560 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
1903 this.stop = function() { 1909 this.stop = function() {
1904 clearInterval(this.interval); 1910 clearInterval(this.interval);
1905 this.interval = undefined; 1911 this.interval = undefined;
1906 }; 1912 };
1907 }; 1913 };
1914
1915 // Global Checkers
1916 // These functions will help enforce the checkers
1917 this.checkHiddenAnchor = function()
1918 {
1919 var audioHolder = testState.currentStateMap[testState.currentIndex];
1920 if (audioHolder.anchorId != null)
1921 {
1922 var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId];
1923 if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker)
1924 {
1925 // Anchor is not set below
1926 console.log('Anchor node not below marker value');
1927 alert('Please keep listening');
1928 return false;
1929 }
1930 }
1931 return true;
1932 };
1933
1934 this.checkHiddenReference = function()
1935 {
1936 var audioHolder = testState.currentStateMap[testState.currentIndex];
1937 if (audioHolder.referenceId != null)
1938 {
1939 var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId];
1940 if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker)
1941 {
1942 // Anchor is not set below
1943 console.log('Reference node not above marker value');
1944 alert('Please keep listening');
1945 return false;
1946 }
1947 }
1948 return true;
1949 };
1908 } 1950 }
1909 1951