changeset 662:2991b5476c7c

Updated popup button functions.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 10 Apr 2015 13:46:04 +0100
parents 97ade670d7c1
children ba6cc0a042d8
files ape.css ape.js core.js
diffstat 3 files changed, 55 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/ape.css	Fri Apr 10 12:59:23 2015 +0100
+++ b/ape.css	Fri Apr 10 13:46:04 2015 +0100
@@ -53,11 +53,11 @@
 	float: left;
 	margin: 5px;
 }
+
 div.comment-div span {
 	margin-left: 15px;
 }
 
-
 div.popupHolder {
 	width: 500px;
 	height: 250px;
@@ -67,7 +67,7 @@
 	z-index: 2;
 }
 
-button#preTestNext {
+button.popupButton {
 	/* Button for popup window
 	 */
 	width: 50px;
--- a/ape.js	Fri Apr 10 12:59:23 2015 +0100
+++ b/ape.js	Fri Apr 10 13:46:04 2015 +0100
@@ -13,6 +13,13 @@
  * 
  */
 
+var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
+// preTest - In preTest state
+// testRun-ID - In test running, test Id number at the end 'testRun-2'
+// testRunPost-ID - Post test of test ID
+// testRunPre-ID - Pre-test of test ID
+// postTest - End of test, final submission!
+
 
 // Once this is loaded and parsed, begin execution
 loadInterface(projectXML);
@@ -111,38 +118,34 @@
 	var feedbackHolder = document.createElement('div');
 	feedbackHolder.id = 'feedbackHolder';
 	
+	testContent.style.zIndex = 1;
+	insertPoint.innerHTML = null; // Clear the current schema
+	
 	// Create pre and post test questions
+	var blank = document.createElement('div');
+	blank.className = 'testHalt';
 	
-	// Inject into HTML
-	insertPoint.innerHTML = null; // Clear the current schema
-	testContent.appendChild(title); // Insert the title
-	testContent.appendChild(interfaceButtons);
-	testContent.appendChild(sliderBox);
-	testContent.appendChild(feedbackHolder);
-	insertPoint.appendChild(testContent);
+	var popupHolder = document.createElement('div');
+	popupHolder.id = 'popupHolder';
+	popupHolder.className = 'popupHolder';
+	popupHolder.style.position = 'absolute';
+	popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
+	popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
+	insertPoint.appendChild(popupHolder);
+	insertPoint.appendChild(blank);
+	hidePopup();
 	
 	var preTest = xmlSetup.find('PreTest');
 	var postTest = xmlSetup.find('PostTest');
 	preTest = preTest[0];
 	postTest = postTest[0];
-	if (preTest != undefined || postTest != undefined)
-	{
-		testContent.style.zIndex = 1;
-		var blank = document.createElement('div');
-		blank.className = 'testHalt';
-		insertPoint.appendChild(blank);
-	}
+	
+	currentState = 'preTest';
 	
 	// Create Pre-Test Box
 	if (preTest != undefined && preTest.children.length >= 1)
 	{
-		
-		var popupHolder = document.createElement('div');
-		popupHolder.id = 'popupHolder';
-		popupHolder.className = 'popupHolder';
-		popupHolder.style.position = 'absolute';
-		popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
-		popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
+		showPopup();
 		
 		// Parse the first box
 		var preTestOption = document.createElement('div');
@@ -164,15 +167,21 @@
 			preTestOption.appendChild(textEnter);
 		}
 		var nextButton = document.createElement('button');
-		nextButton.id = 'preTestNext';
+		nextButton.className = 'popupButton';
 		nextButton.value = '0';
 		nextButton.innerHTML = 'Next';
-		nextButton.onclick = preTestButtonClick;
+		nextButton.onclick = popupButtonClick;
 		
 		popupHolder.appendChild(preTestOption);
 		popupHolder.appendChild(nextButton);
-		insertPoint.appendChild(popupHolder);
 	}
+	
+	// Inject into HTML
+	testContent.appendChild(title); // Insert the title
+	testContent.appendChild(interfaceButtons);
+	testContent.appendChild(sliderBox);
+	testContent.appendChild(feedbackHolder);
+	insertPoint.appendChild(testContent);
 
 	// Load the full interface
 	loadTest(testXMLSetups[0]);
@@ -261,7 +270,17 @@
 	});
 }
 
-function preTestButtonClick()
+function popupButtonClick()
+{
+	// Global call from the 'Next' button click
+	if (currentState == 'preTest')
+	{
+		// At the start of the preTest routine!
+		this.value = preTestButtonClick(this.value);
+	}
+}
+
+function preTestButtonClick(index)
 {
 	// Called on click of pre-test button
 	// Need to find and parse preTest again!
@@ -269,19 +288,19 @@
 	var preTest = xmlSetup.find('PreTest')[0];
 	var preTestOption = document.getElementById('preTest');
 	// Check if current state is a question!
-	if (preTest.children[this.value].nodeName == 'question') {
-		var questionId = preTest.children[this.value].attributes['id'].value;
+	if (preTest.children[index].nodeName == 'question') {
+		var questionId = preTest.children[index].attributes['id'].value;
 		var questionHold = document.createElement('comment');
 		var questionResponse = document.getElementById(questionId + 'response');
 		questionHold.id = questionId;
 		questionHold.innerHTML = questionResponse.value;
 		preTestQuestions.appendChild(questionHold);
 	}
-	this.value++;
-	if (this.value < preTest.children.length)
+	index++;
+	if (index < preTest.children.length)
 	{
 		// More to process
-		var child = preTest.children[this.value];
+		var child = preTest.children[index];
 		if (child.nodeName == 'statement')
 		{
 			preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
@@ -301,13 +320,15 @@
 		// Time to clear
 		preTestOption.innerHTML = null;
 		hidePopup();
+		// Progress the state!
 	}
+	return index;
 }
 
 function showPopup()
 {
 	var popupHolder = document.getElementById('popupHolder');
-	popupHolder.style.zIndex = 2;
+	popupHolder.style.zIndex = 3;
 	popupHolder.style.visibility = 'visible';
 	var blank = document.getElementsByClassName('testHalt')[0];
 	blank.style.zIndex = 2;
--- a/core.js	Fri Apr 10 12:59:23 2015 +0100
+++ b/core.js	Fri Apr 10 13:46:04 2015 +0100
@@ -22,6 +22,7 @@
 /* create the web audio API context and store in audioContext*/
 var audioContext; // Hold the browser web audio API
 var projectXML; // Hold the parsed setup XML
+
 var testXMLSetups; // Hold the parsed test instances
 var testResultsHolders; // Hold the results from each test for publishing to XML
 var currentTestHolder; // Hold an intermediate results during test - metrics