diff core.js @ 371:ad267c5e32ae

Merge of dev into default/master
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 04 Dec 2015 11:00:55 +0000
parents ed22a47dcacd
children 6139c53deba1
line wrap: on
line diff
--- a/core.js	Fri Dec 04 10:57:39 2015 +0000
+++ b/core.js	Fri Dec 04 11:00:55 2015 +0000
@@ -73,13 +73,16 @@
 		this.popupContent = document.createElement('div');
 		this.popupContent.id = 'popupContent';
 		this.popupContent.style.marginTop = '20px';
-		this.popupContent.align = 'center';
+		this.popupContent.style.marginBottom = '5px';
 		this.popup.appendChild(this.popupContent);
 		
 		var titleHolder = document.createElement('div');
 		titleHolder.id = 'popupTitleHolder';
+		titleHolder.align = 'center';
 		titleHolder.style.width = 'inherit';
-		titleHolder.style.height = '25px';
+		titleHolder.style.minHeight = '25px';
+		titleHolder.style.maxHeight = '250px';
+		titleHolder.style.overflow = 'auto';
 		titleHolder.style.marginBottom = '5px';
 		
 		this.popupTitle = document.createElement('span');
@@ -89,35 +92,29 @@
 		
 		this.popupResponse = document.createElement('div');
 		this.popupResponse.id = 'popupResponse';
+		this.popupResponse.align = 'center';
 		this.popupResponse.style.width = 'inherit';
-		this.popupResponse.style.minHeight = '170px';
+		this.popupResponse.style.minHeight = '50px';
 		this.popupResponse.style.maxHeight = '320px';
 		this.popupResponse.style.overflow = 'auto';
 		this.popupContent.appendChild(this.popupResponse);
 		
-		var buttonHolder = document.createElement('div');
-		buttonHolder.id='buttonHolder';
-		buttonHolder.width = 'inherit';
-		buttonHolder.style.height= '30px';
-		buttonHolder.align = 'left';
-		this.popupContent.appendChild(buttonHolder);
-		
 		this.buttonProceed = document.createElement('button');
 		this.buttonProceed.className = 'popupButton';
+		this.buttonProceed.position = 'relative';
 		this.buttonProceed.style.left = '390px';
-		this.buttonProceed.style.top = '2px';
 		this.buttonProceed.innerHTML = 'Next';
 		this.buttonProceed.onclick = function(){popup.proceedClicked();};
 		
 		this.buttonPrevious = document.createElement('button');
 		this.buttonPrevious.className = 'popupButton';
+		this.buttonPrevious.position = 'relative';
 		this.buttonPrevious.style.left = '10px';
-		this.buttonPrevious.style.top = '2px';
 		this.buttonPrevious.innerHTML = 'Back';
 		this.buttonPrevious.onclick = function(){popup.previousClick();};
 		
-		buttonHolder.appendChild(this.buttonPrevious);
-		buttonHolder.appendChild(this.buttonProceed);
+		this.popupContent.appendChild(this.buttonPrevious);
+		this.popupContent.appendChild(this.buttonProceed);
 		
 		this.popup.style.zIndex = -1;
 		this.popup.style.visibility = 'hidden';
@@ -139,13 +136,6 @@
 		$(window).keypress(function(e){
 			if (e.keyCode == 13 && popup.popup.style.visibility == 'visible')
 			{
-				// Enter key pressed
-				var textarea = $(popup.popupContent).find('textarea');
-				if (textarea.length != 0)
-				{
-					if (textarea[0] == document.activeElement)
-					{return;}
-				}
 				popup.buttonProceed.onclick();
 			}
 		});
@@ -158,6 +148,7 @@
 		blank.style.zIndex = -2;
 		blank.style.visibility = 'hidden';
 		this.buttonPrevious.style.visibility = 'inherit';
+		$(window).keypress(function(e){});
 	};
 	
 	this.postNode = function() {
@@ -190,12 +181,6 @@
 				textArea.rows = "10";
 				break;
 			}
-			document.onkeydown=function(){
-				if(window.event.keyCode=='13'){ // when you hit enter
-					window.event.preventDefault(); // don't make newline
-					popup.proceedClicked(); // go to the next window (or start the test or submit)
-				}
-			}
 			this.popupResponse.appendChild(textArea);
 			textArea.focus();
 		} else if (node.type == 'checkbox') {
@@ -242,6 +227,12 @@
 			if (node.step != null) {input.step = node.step;}
 			this.popupResponse.appendChild(input);
 		}
+		var content_height = Number(this.popup.offsetHeight.toFixed());
+		content_height -= Number(this.popupContent.offsetHeight.toFixed());
+		content_height -=Number(this.buttonProceed.offsetHeight.toFixed());
+		content_height = content_height + "px";
+		this.buttonProceed.style.top = content_height;
+		this.buttonPrevious.style.top = content_height;
 		if(this.currentIndex+1 == this.popupOptions.length) {
 			if (this.responses.nodeName == "PRETEST") {
 				this.buttonProceed.textContent = 'Start';
@@ -727,6 +718,7 @@
 	projectDocument.setAttribute('file-name',url);
 	xmlDoc.appendChild(projectDocument);
 	xmlDoc.appendChild(returnDateNode());
+	xmlDoc.appendChild(interfaceContext.returnNavigator());
 	for (var i=0; i<testState.stateResults.length; i++)
 	{
 		xmlDoc.appendChild(testState.stateResults[i]);
@@ -952,7 +944,8 @@
 			this.bufferNode.loop = audioEngineContext.loopPlayback;
 			this.bufferNode.onended = function(event) {
 				// Safari does not like using 'this' to reference the calling object!
-				event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
+				//event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
+				event.currentTarget.owner.stop();
 			};
 			if (this.bufferNode.loop == false) {
 				this.metric.startListening(audioEngineContext.timer.getTestTime());
@@ -975,7 +968,7 @@
 		if (this.bufferNode != undefined) {
 			if (this.bufferNode.loop == true) {
 				if (audioEngineContext.status  == 1) {
-					return time%this.buffer.duration;
+					return (time-this.metric.listenStart)%this.buffer.duration;
 				} else {
 					return 0;
 				}
@@ -1318,14 +1311,14 @@
 function Specification() {
 	// Handles the decoding of the project specification XML into a simple JavaScript Object.
 	
-	this.interfaceType;
-	this.commonInterface;
-	this.projectReturn;
-	this.randomiseOrder;
-	this.collectMetrics;
-	this.testPages;
-	this.preTest;
-	this.postTest;
+	this.interfaceType = null;
+	this.commonInterface = null;
+	this.projectReturn = null;
+	this.randomiseOrder = null;
+	this.collectMetrics = null;
+	this.testPages = null;
+	this.preTest = null;
+	this.postTest = null;
 	this.metrics =[];
 	
 	this.audioHolders = [];
@@ -1395,10 +1388,7 @@
 						}
 					}
 				} else if (this.type == 'anchor' || this.type == 'reference') {
-					this.value = Number(child.textContent);
-					this.enforce = child.getAttribute('enforce');
-					if (this.enforce == 'true') {this.enforce = true;}
-					else {this.enforce = false;}
+					Console.log("WARNING: Anchor and Reference tags in the <interface> node are depricated");
 				}
 			};
 			this.options = [];
@@ -1543,24 +1533,32 @@
 			if (this.type == 'reference') {this.reference = true;}
 			else {this.reference = false;}
 			
-			this.marker = xml.getAttribute('marker');
-			if (this.marker == null) {this.marker = undefined;}
-			
-			if (this.anchor == true) {
-				if (this.marker != undefined) {this.enforce = true;}
-				else {this.enforce = enforceAnchor;}
-				this.marker = anchor;
+			if (this.anchor == true || this.reference == true)
+			{
+				this.marker = xml.getAttribute('marker');
+				if (this.marker != undefined)
+				{
+					this.marker = Number(this.marker);
+					if (isNaN(this.marker) == false)
+					{
+						if (this.marker > 1)
+						{	this.marker /= 100.0;}
+						if (this.marker >= 0 && this.marker <= 1)
+						{
+							this.enforce = true;
+							return;
+						} else {
+							console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!");
+							console.log("ERROR - Marker not enforced!");
+						}
+					} else {
+						console.log("ERROR - Marker of audioElement "+this.id+" is not a number!");
+						console.log("ERROR - Marker not enforced!");
+					}
+				}
 			}
-			else if (this.reference == true) {
-				if (this.marker != undefined) {this.enforce = true;}
-				else {this.enforce = enforceReference;}
-				this.marker = reference;
-			}
-			
-			if (this.marker != undefined) {
-				this.marker = Number(this.marker);
-				if (this.marker > 1) {this.marker /= 100;}
-			}
+			this.marker = false;
+			this.enforce = false;
 		};
 		
 		this.commentQuestionNode = function(xml) {
@@ -1616,50 +1614,6 @@
 		if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
 		else {this.elementComments = false;}
 		
-		var anchor = xml.getElementsByTagName('anchor');
-		var enforceAnchor = false;
-		if (anchor.length == 0) {
-			// Find anchor in commonInterface;
-			for (var i=0; i<parent.commonInterface.options.length; i++) {
-				if(parent.commonInterface.options[i].type == 'anchor') {
-					anchor = parent.commonInterface.options[i].value;
-					enforceAnchor = parent.commonInterface.options[i].enforce;
-					break;
-				}
-			}
-			if (typeof(anchor) == "object") {
-				anchor = null;
-			}
-		} else {
-			anchor = anchor[0].textContent;
-		}
-		
-		var reference = xml.getElementsByTagName('anchor');
-		var enforceReference = false;
-		if (reference.length == 0) {
-			// Find anchor in commonInterface;
-			for (var i=0; i<parent.commonInterface.options.length; i++) {
-				if(parent.commonInterface.options[i].type == 'reference') {
-					reference = parent.commonInterface.options[i].value;
-					enforceReference = parent.commonInterface.options[i].enforce;
-					break;
-				}
-			}
-			if (typeof(reference) == "object") {
-				reference = null;
-			}
-		} else {
-			reference = reference[0].textContent;
-		}
-		
-		if (typeof(anchor) == 'number') {
-			if (anchor > 1 && anchor < 100) {anchor /= 100.0;}
-		}
-		
-		if (typeof(reference) == 'number') {
-			if (reference > 1 && reference < 100) {reference /= 100.0;}
-		}
-		
 		this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
 		this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest'));
 		
@@ -1697,36 +1651,6 @@
 			this.audioElements = randomiseOrder(this.audioElements);
 		}
 		
-		// Check only one anchor and one reference per audioNode
-		var anchor = [];
-		var reference = [];
-		this.anchorId = null;
-		this.referenceId = null;
-		for (var i=0; i<this.audioElements.length; i++)
-		{
-			if (this.audioElements[i].anchor == true) {anchor.push(i);}
-			if (this.audioElements[i].reference == true) {reference.push(i);}
-		}
-		
-		if (anchor.length > 1) {
-			console.log('Error - cannot have more than one anchor!');
-			console.log('Each anchor node will be a normal mode to continue the test');
-			for (var i=0; i<anchor.length; i++)
-			{
-				this.audioElements[anchor[i]].anchor = false;
-				this.audioElements[anchor[i]].value = undefined;
-			}
-		} else {this.anchorId = anchor[0];}
-		if (reference.length > 1) {
-			console.log('Error - cannot have more than one anchor!');
-			console.log('Each anchor node will be a normal mode to continue the test');
-			for (var i=0; i<reference.length; i++)
-			{
-				this.audioElements[reference[i]].reference = false;
-				this.audioElements[reference[i]].value = undefined;
-			}
-		} else {this.referenceId = reference[0];}
-		
 		this.commentQuestions = [];
 		var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
 		for (var i=0; i<commentQuestionsDOM.length; i++) {
@@ -1763,6 +1687,21 @@
 		}
 	};
 	
+	this.returnNavigator = function()
+	{
+		var node = document.createElement("navigator");
+		var platform = document.createElement("platform");
+		platform.textContent = navigator.platform;
+		var vendor = document.createElement("vendor");
+		vendor.textContent = navigator.vendor;
+		var userAgent = document.createElement("uagent");
+		userAgent.textContent = navigator.userAgent;
+		node.appendChild(platform);
+		node.appendChild(vendor);
+		node.appendChild(userAgent);
+		return node;
+	};
+	
 	this.commentBoxes = [];
 	this.elementCommentBox = function(audioObject) {
 		var element = audioObject.specification;
@@ -2247,4 +2186,57 @@
 		}
 		return true;
 	};
+	
+	this.checkFragmentsFullyPlayed = function ()
+	{
+		// Checks the entire file has been played back
+		// NOTE ! This will return true IF playback is Looped!!!
+		if (audioEngineContext.loopPlayback)
+		{
+			console.log("WARNING - Looped source: Cannot check fragments are fully played");
+			return true;
+		}
+		var check_pass = true;
+		var error_obj = [];
+		for (var i = 0; i<audioEngineContext.audioObjects.length; i++)
+		{
+			var object = audioEngineContext.audioObjects[i];
+			var time = object.buffer.duration;
+			var metric = object.metric;
+			var passed = false;
+			for (var j=0; j<metric.listenTracker.length; j++)
+			{
+				var bt = metric.listenTracker[j].getElementsByTagName('buffertime');
+				var start_time = Number(bt[0].getAttribute('start'));
+				var stop_time = Number(bt[0].getAttribute('stop'));
+				var delta = stop_time - start_time;
+				if (delta >= time)
+				{
+					passed = true;
+					break;
+				}
+			}
+			if (passed == false)
+			{
+				check_pass = false;
+				console.log("Continue listening to track-"+i);
+				error_obj.push(i);
+			}
+		}
+		if (check_pass == false)
+		{
+			var str_start = "You have not listened to fragments ";
+			for (var i=0; i<error_obj.length; i++)
+			{
+				str_start += error_obj[i];
+				if (i != error_obj.length-1)
+				{
+					str_start += ', ';
+				}
+			}
+			str_start += ". Please keep listening";
+			console.log("[ALERT]: "+str_start);
+			alert(str_start);
+		}
+	};
 }
\ No newline at end of file