comparison core.js @ 1576:51bbd0fdf7b4

Moved non interface specific code from loadInterface in ape.js to core.js
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 04 Jun 2015 10:43:06 +0100
parents 9eae8c728460
children 1b6f4304dedc
comparison
equal deleted inserted replaced
1575:9eae8c728460 1576:51bbd0fdf7b4
8 /* create the web audio API context and store in audioContext*/ 8 /* create the web audio API context and store in audioContext*/
9 var audioContext; // Hold the browser web audio API 9 var audioContext; // Hold the browser web audio API
10 var projectXML; // Hold the parsed setup XML 10 var projectXML; // Hold the parsed setup XML
11 var popup; // Hold the interfacePopup object 11 var popup; // Hold the interfacePopup object
12 var testState; 12 var testState;
13 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
14 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order 13 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
15 var audioEngineContext; // The custome AudioEngine object 14 var audioEngineContext; // The custome AudioEngine object
16 var projectReturn; // Hold the URL for the return 15 var projectReturn; // Hold the URL for the return
17 16
18 17
250 this.testPageCompleted = function(store, testXML, testId) { 249 this.testPageCompleted = function(store, testXML, testId) {
251 // Function called each time a test page has been completed 250 // Function called each time a test page has been completed
252 // Can be used to over-rule default behaviour 251 // Can be used to over-rule default behaviour
253 252
254 pageXMLSave(store, testXML, testId); 253 pageXMLSave(store, testXML, testId);
255 } 254 };
256 255
257 this.initialiseInnerState = function(testXML) { 256 this.initialiseInnerState = function(testXML) {
258 // Parses the received testXML for pre and post test options 257 // Parses the received testXML for pre and post test options
259 this.currentStateMap = []; 258 this.currentStateMap = [];
260 var preTest = $(testXML).find('PreTest')[0]; 259 var preTest = $(testXML).find('PreTest')[0];
264 this.currentStateMap.push(preTest); 263 this.currentStateMap.push(preTest);
265 this.currentStateMap.push(testXML); 264 this.currentStateMap.push(testXML);
266 this.currentStateMap.push(postTest); 265 this.currentStateMap.push(postTest);
267 this.currentIndex = -1; 266 this.currentIndex = -1;
268 this.advanceInnerState(); 267 this.advanceInnerState();
269 } 268 };
270 269
271 this.advanceInnerState = function() { 270 this.advanceInnerState = function() {
272 this.currentIndex++; 271 this.currentIndex++;
273 if (this.currentIndex >= this.currentStateMap.length) { 272 if (this.currentIndex >= this.currentStateMap.length) {
274 this.currentIndex = null; 273 this.currentIndex = null;
283 popup.initState(this.currentStateMap[this.currentIndex]); 282 popup.initState(this.currentStateMap[this.currentIndex]);
284 } else { 283 } else {
285 this.advanceInnerState(); 284 this.advanceInnerState();
286 } 285 }
287 } 286 }
288 } 287 };
289 288
290 this.previousState = function(){}; 289 this.previousState = function(){};
291 } 290 }
292 291
293 function testEnded(testId) 292 function testEnded(testId)
325 var decode = $.parseXML(response); 324 var decode = $.parseXML(response);
326 projectXML = $(decode); 325 projectXML = $(decode);
327 326
328 // Now extract the setup tag 327 // Now extract the setup tag
329 var xmlSetup = projectXML.find('setup'); 328 var xmlSetup = projectXML.find('setup');
329
330
331 // Create pre and post test questions
332
333 var preTest = xmlSetup.find('PreTest');
334 var postTest = xmlSetup.find('PostTest');
335 preTest = preTest[0];
336 postTest = postTest[0];
337
338 if (preTest == undefined) {preTest = document.createElement("preTest");}
339 if (postTest == undefined){postTest= document.createElement("postTest");}
340
341 testState.stateMap.push(preTest);
342
343 // Extract the different test XML DOM trees
344 var audioHolders = projectXML.find('audioHolder');
345 var testXMLSetups = [];
346 audioHolders.each(function(index,element) {
347 var repeatN = element.attributes['repeatCount'].value;
348 for (var r=0; r<=repeatN; r++) {
349 testXMLSetups.push(element);
350 }
351 });
352
353 // New check if we need to randomise the test order
354 var randomise = xmlSetup[0].attributes['randomiseOrder'];
355 if (randomise != undefined) {
356 if (randomise.value === 'true'){
357 randomise = true;
358 } else {
359 randomise = false;
360 }
361 } else {
362 randomise = false;
363 }
364
365 if (randomise)
366 {
367 testXMLSetups = randomiseOrder(testXMLSetups);
368 }
369
370 $(testXMLSetups).each(function(index,elem){
371 testState.stateMap.push(elem);
372 });
373
374 testState.stateMap.push(postTest);
375
376 // Obtain the metrics enabled
377 var metricNode = xmlSetup.find('Metric');
378 var metricNode = metricNode.find('metricEnable');
379 metricNode.each(function(index,node){
380 var enabled = node.textContent;
381 switch(enabled)
382 {
383 case 'testTimer':
384 sessionMetrics.prototype.enableTestTimer = true;
385 break;
386 case 'elementTimer':
387 sessionMetrics.prototype.enableElementTimer = true;
388 break;
389 case 'elementTracker':
390 sessionMetrics.prototype.enableElementTracker = true;
391 break;
392 case 'elementListenTracker':
393 sessionMetrics.prototype.enableElementListenTracker = true;
394 break;
395 case 'elementInitialPosition':
396 sessionMetrics.prototype.enableElementInitialPosition = true;
397 break;
398 case 'elementFlagListenedTo':
399 sessionMetrics.prototype.enableFlagListenedTo = true;
400 break;
401 case 'elementFlagMoved':
402 sessionMetrics.prototype.enableFlagMoved = true;
403 break;
404 case 'elementFlagComments':
405 sessionMetrics.prototype.enableFlagComments = true;
406 break;
407 }
408 });
409
410
411
330 // Detect the interface to use and load the relevant javascripts. 412 // Detect the interface to use and load the relevant javascripts.
331 var interfaceType = xmlSetup[0].attributes['interface']; 413 var interfaceType = xmlSetup[0].attributes['interface'];
332 var interfaceJS = document.createElement('script'); 414 var interfaceJS = document.createElement('script');
333 interfaceJS.setAttribute("type","text/javascript"); 415 interfaceJS.setAttribute("type","text/javascript");
334 if (interfaceType.value == 'APE') { 416 if (interfaceType.value == 'APE') {