nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@32
|
6 /*
|
n@32
|
7 *
|
n@32
|
8 * WARNING!!!
|
n@32
|
9 *
|
n@32
|
10 * YOU ARE VIEWING THE DEV VERSION. THERE IS NO GUARANTEE THIS WILL BE FULLY FUNCTIONAL
|
n@32
|
11 *
|
n@32
|
12 * WARNING!!!
|
n@32
|
13 *
|
n@32
|
14 */
|
n@32
|
15
|
n@38
|
16 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
|
n@38
|
17 // preTest - In preTest state
|
n@38
|
18 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
19 // testRunPost-ID - Post test of test ID
|
n@38
|
20 // testRunPre-ID - Pre-test of test ID
|
n@38
|
21 // postTest - End of test, final submission!
|
n@38
|
22
|
n@32
|
23
|
nicholas@2
|
24 // Once this is loaded and parsed, begin execution
|
nicholas@2
|
25 loadInterface(projectXML);
|
nicholas@2
|
26
|
nicholas@2
|
27 function loadInterface(xmlDoc) {
|
nicholas@2
|
28
|
n@16
|
29 // Get the dimensions of the screen available to the page
|
nicholas@2
|
30 var width = window.innerWidth;
|
nicholas@2
|
31 var height = window.innerHeight;
|
nicholas@2
|
32
|
nicholas@2
|
33 // The injection point into the HTML page
|
nicholas@2
|
34 var insertPoint = document.getElementById("topLevelBody");
|
n@22
|
35 var testContent = document.createElement('div');
|
n@22
|
36 testContent.id = 'testContent';
|
nicholas@2
|
37
|
nicholas@7
|
38
|
nicholas@2
|
39 // Decode parts of the xmlDoc that are needed
|
nicholas@2
|
40 // xmlDoc MUST already be parsed by jQuery!
|
nicholas@2
|
41 var xmlSetup = xmlDoc.find('setup');
|
nicholas@2
|
42 // Should put in an error function here incase of malprocessed or malformed XML
|
nicholas@2
|
43
|
n@34
|
44 // Extract the different test XML DOM trees
|
n@44
|
45 var audioHolders = xmlDoc.find('audioHolder');
|
n@44
|
46 audioHolders.each(function(index,element) {
|
n@44
|
47 var repeatN = element.attributes['repeatCount'].value;
|
n@44
|
48 for (var r=0; r<=repeatN; r++) {
|
n@44
|
49 testXMLSetups[testXMLSetups.length] = element;
|
n@44
|
50 }
|
n@44
|
51 });
|
n@44
|
52
|
n@44
|
53 // New check if we need to randomise the test order
|
n@45
|
54 var randomise = xmlSetup[0].attributes['randomiseOrder'];
|
n@45
|
55 if (randomise != undefined) {
|
n@44
|
56 randomise = Boolean(randomise.value);
|
n@44
|
57 } else {
|
n@44
|
58 randomise = false;
|
n@44
|
59 }
|
n@44
|
60 if (randomise)
|
n@44
|
61 {
|
n@44
|
62 // TODO: Implement Randomisation!!
|
n@44
|
63 }
|
n@44
|
64
|
n@34
|
65
|
nicholas@2
|
66 // Create the top div for the Title element
|
nicholas@2
|
67 var titleAttr = xmlSetup[0].attributes['title'];
|
nicholas@2
|
68 var title = document.createElement('div');
|
nicholas@2
|
69 title.className = "title";
|
nicholas@2
|
70 title.align = "center";
|
nicholas@2
|
71 var titleSpan = document.createElement('span');
|
nicholas@2
|
72
|
nicholas@2
|
73 // Set title to that defined in XML, else set to default
|
nicholas@2
|
74 if (titleAttr != undefined) {
|
n@25
|
75 titleSpan.innerHTML = titleAttr.value;
|
nicholas@2
|
76 } else {
|
n@25
|
77 titleSpan.innerHTML = 'APE Tool';
|
nicholas@2
|
78 }
|
nicholas@2
|
79 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
80 title.appendChild(titleSpan);
|
nicholas@2
|
81
|
n@47
|
82 var pagetitle = document.createElement('div');
|
n@47
|
83 pagetitle.className = "pageTitle";
|
n@47
|
84 pagetitle.align = "center";
|
n@47
|
85 var titleSpan = document.createElement('span');
|
n@47
|
86 titleSpan.id = "pageTitle";
|
n@47
|
87 pagetitle.appendChild(titleSpan);
|
n@47
|
88
|
nicholas@7
|
89 // Store the return URL path in global projectReturn
|
nicholas@7
|
90 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
|
nicholas@7
|
91
|
nicholas@7
|
92 // Create Interface buttons!
|
nicholas@7
|
93 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
94 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
95
|
nicholas@7
|
96 // MANUAL DOWNLOAD POINT
|
nicholas@7
|
97 // If project return is null, this MUST be specified as the location to create the download link
|
nicholas@7
|
98 var downloadPoint = document.createElement('div');
|
nicholas@7
|
99 downloadPoint.id = 'download-point';
|
nicholas@7
|
100
|
nicholas@7
|
101 // Create playback start/stop points
|
nicholas@7
|
102 var playback = document.createElement("button");
|
n@25
|
103 playback.innerHTML = 'Start';
|
n@16
|
104 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
105 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
106 playback.onclick = function() {
|
nicholas@7
|
107 if (audioEngineContext.status == 0) {
|
nicholas@7
|
108 audioEngineContext.play();
|
n@25
|
109 this.innerHTML = 'Stop';
|
nicholas@7
|
110 } else {
|
nicholas@7
|
111 audioEngineContext.stop();
|
n@25
|
112 this.innerHTML = 'Start';
|
nicholas@7
|
113 }
|
n@16
|
114 };
|
nicholas@7
|
115 // Create Submit (save) button
|
nicholas@7
|
116 var submit = document.createElement("button");
|
n@25
|
117 submit.innerHTML = 'Submit';
|
n@43
|
118 submit.onclick = buttonSubmitClick;
|
n@16
|
119 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
120 interfaceButtons.appendChild(playback);
|
nicholas@7
|
121 interfaceButtons.appendChild(submit);
|
nicholas@7
|
122 interfaceButtons.appendChild(downloadPoint);
|
nicholas@7
|
123
|
nicholas@2
|
124 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
125
|
n@16
|
126 // Create the div box to center align
|
nicholas@2
|
127 var sliderBox = document.createElement('div');
|
nicholas@2
|
128 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
129 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
130 sliderBox.align = 'center';
|
nicholas@2
|
131
|
n@16
|
132 // Create the slider box to hold the slider elements
|
nicholas@5
|
133 var canvas = document.createElement('div');
|
nicholas@2
|
134 canvas.id = 'slider';
|
n@16
|
135 // Must have a known EXACT width, as this is used later to determine the ratings
|
nicholas@5
|
136 canvas.style.width = width - 100 +"px";
|
nicholas@5
|
137 canvas.align = "left";
|
nicholas@2
|
138 sliderBox.appendChild(canvas);
|
n@16
|
139
|
n@47
|
140 // Create the div to hold any scale objects
|
n@47
|
141 var scale = document.createElement('div');
|
n@47
|
142 scale.className = 'sliderScale';
|
n@47
|
143 scale.id = 'sliderScaleHolder';
|
n@47
|
144 scale.align = 'left';
|
n@47
|
145 sliderBox.appendChild(scale);
|
n@47
|
146
|
n@16
|
147 // Global parent for the comment boxes on the page
|
nicholas@3
|
148 var feedbackHolder = document.createElement('div');
|
n@34
|
149 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
150
|
n@38
|
151 testContent.style.zIndex = 1;
|
n@38
|
152 insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
153
|
n@22
|
154 // Create pre and post test questions
|
n@38
|
155 var blank = document.createElement('div');
|
n@38
|
156 blank.className = 'testHalt';
|
n@22
|
157
|
n@38
|
158 var popupHolder = document.createElement('div');
|
n@38
|
159 popupHolder.id = 'popupHolder';
|
n@38
|
160 popupHolder.className = 'popupHolder';
|
n@38
|
161 popupHolder.style.position = 'absolute';
|
n@38
|
162 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
|
n@38
|
163 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
|
n@38
|
164 insertPoint.appendChild(popupHolder);
|
n@38
|
165 insertPoint.appendChild(blank);
|
n@38
|
166 hidePopup();
|
n@22
|
167
|
n@36
|
168 var preTest = xmlSetup.find('PreTest');
|
n@36
|
169 var postTest = xmlSetup.find('PostTest');
|
n@22
|
170 preTest = preTest[0];
|
n@22
|
171 postTest = postTest[0];
|
n@38
|
172
|
n@38
|
173 currentState = 'preTest';
|
n@22
|
174
|
n@22
|
175 // Create Pre-Test Box
|
n@22
|
176 if (preTest != undefined && preTest.children.length >= 1)
|
n@22
|
177 {
|
n@38
|
178 showPopup();
|
n@39
|
179 preTestPopupStart(preTest);
|
n@22
|
180 }
|
n@38
|
181
|
n@38
|
182 // Inject into HTML
|
n@38
|
183 testContent.appendChild(title); // Insert the title
|
n@47
|
184 testContent.appendChild(pagetitle);
|
n@38
|
185 testContent.appendChild(interfaceButtons);
|
n@38
|
186 testContent.appendChild(sliderBox);
|
n@38
|
187 testContent.appendChild(feedbackHolder);
|
n@38
|
188 insertPoint.appendChild(testContent);
|
n@22
|
189
|
n@36
|
190 // Load the full interface
|
n@39
|
191
|
nicholas@2
|
192 }
|
nicholas@5
|
193
|
n@39
|
194 function loadTest(id)
|
n@34
|
195 {
|
n@34
|
196 // Used to load a specific test page
|
n@39
|
197 var textXML = testXMLSetups[id];
|
n@34
|
198
|
n@34
|
199 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
200 var canvas = document.getElementById('slider');
|
n@34
|
201 feedbackHolder.innerHTML = null;
|
n@34
|
202 canvas.innerHTML = null;
|
n@47
|
203
|
n@47
|
204 // Setup question title
|
n@47
|
205 var interfaceObj = $(textXML).find('interface');
|
n@47
|
206 var titleNode = interfaceObj.find('title');
|
n@47
|
207 if (titleNode[0] != undefined)
|
n@47
|
208 {
|
n@47
|
209 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
|
n@47
|
210 }
|
n@47
|
211 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@47
|
212 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
|
n@47
|
213 // TODO: AUTOMATE ABOVE!!
|
n@47
|
214 var scale = document.getElementById('sliderScaleHolder');
|
n@47
|
215 scale.innerHTML = null;
|
n@47
|
216 interfaceObj.find('scale').each(function(index,scaleObj){
|
n@47
|
217 var position = Number(scaleObj.attributes['position'].value)*0.01;
|
n@47
|
218 var pixelPosition = (position*positionScale)+offset;
|
n@47
|
219 var scaleDOM = document.createElement('span');
|
n@47
|
220 scaleDOM.textContent = scaleObj.textContent;
|
n@47
|
221 scale.appendChild(scaleDOM);
|
n@47
|
222 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@47
|
223 });
|
n@34
|
224
|
n@34
|
225 // Extract the hostURL attribute. If not set, create an empty string.
|
n@34
|
226 var hostURL = textXML.attributes['hostURL'];
|
n@34
|
227 if (hostURL == undefined) {
|
n@34
|
228 hostURL = "";
|
n@34
|
229 } else {
|
n@34
|
230 hostURL = hostURL.value;
|
n@34
|
231 }
|
n@34
|
232 // Extract the sampleRate. If set, convert the string to a Number.
|
n@34
|
233 var hostFs = textXML.attributes['sampleRate'];
|
n@34
|
234 if (hostFs != undefined) {
|
n@34
|
235 hostFs = Number(hostFs.value);
|
n@34
|
236 }
|
n@34
|
237
|
n@34
|
238 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@34
|
239 if (hostFs != undefined) {
|
n@34
|
240 if (Number(hostFs) != audioContext.sampleRate) {
|
n@34
|
241 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
242 alert(errStr);
|
n@34
|
243 return;
|
n@34
|
244 }
|
n@34
|
245 }
|
n@45
|
246
|
n@46
|
247 currentTestHolder = document.createElement('audioHolder');
|
n@46
|
248 currentTestHolder.id = textXML.id;
|
n@46
|
249 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
|
n@46
|
250 var currentPreTestHolder = document.createElement('preTest');
|
n@46
|
251 var currentPostTestHolder = document.createElement('postTest');
|
n@46
|
252 currentTestHolder.appendChild(currentPreTestHolder);
|
n@46
|
253 currentTestHolder.appendChild(currentPostTestHolder);
|
n@46
|
254
|
n@45
|
255 var randomise = textXML.attributes['randomiseOrder'];
|
n@45
|
256 if (randomise != undefined) {randomise = randomise.value;}
|
n@45
|
257 else {randomise = false;}
|
n@45
|
258
|
n@34
|
259 var audioElements = $(textXML).find('audioElements');
|
n@34
|
260 audioElements.each(function(index,element){
|
n@45
|
261 // Find any blind-repeats
|
n@45
|
262 // Not implemented yet, but just incase
|
n@45
|
263 currentTrackOrder[index] = element;
|
n@45
|
264 });
|
n@45
|
265 if (randomise) {
|
n@45
|
266 // TODO: Randomise order
|
n@45
|
267 }
|
n@45
|
268
|
n@45
|
269 // Find all the audioElements from the audioHolder
|
n@45
|
270 $(currentTrackOrder).each(function(index,element){
|
n@34
|
271 // Find URL of track
|
n@34
|
272 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
273
|
n@34
|
274 // Now load each audio sample. First create the new track by passing the full URL
|
n@34
|
275 var trackURL = hostURL + this.attributes['url'].value;
|
n@34
|
276 audioEngineContext.newTrack(trackURL);
|
n@34
|
277 // Create document objects to hold the comment boxes
|
n@34
|
278 var trackComment = document.createElement('div');
|
n@37
|
279 trackComment.className = 'comment-div';
|
n@34
|
280 // Create a string next to each comment asking for a comment
|
n@34
|
281 var trackString = document.createElement('span');
|
n@34
|
282 trackString.innerHTML = 'Comment on track '+index;
|
n@34
|
283 // Create the HTML5 comment box 'textarea'
|
n@34
|
284 var trackCommentBox = document.createElement('textarea');
|
n@34
|
285 trackCommentBox.rows = '4';
|
n@34
|
286 trackCommentBox.cols = '100';
|
n@34
|
287 trackCommentBox.name = 'trackComment'+index;
|
n@34
|
288 trackCommentBox.className = 'trackComment';
|
n@34
|
289 var br = document.createElement('br');
|
n@34
|
290 // Add to the holder.
|
n@34
|
291 trackComment.appendChild(trackString);
|
n@34
|
292 trackComment.appendChild(br);
|
n@34
|
293 trackComment.appendChild(trackCommentBox);
|
n@34
|
294 feedbackHolder.appendChild(trackComment);
|
n@34
|
295
|
n@34
|
296 // Create a slider per track
|
n@34
|
297
|
n@34
|
298 var trackSliderObj = document.createElement('div');
|
n@34
|
299 trackSliderObj.className = 'track-slider';
|
n@34
|
300 trackSliderObj.id = 'track-slider-'+index;
|
n@34
|
301 // Distribute it randomnly
|
n@34
|
302 var w = window.innerWidth - 100;
|
n@34
|
303 w = Math.random()*w;
|
n@34
|
304 trackSliderObj.style.left = Math.floor(w)+50+'px';
|
n@34
|
305 trackSliderObj.innerHTML = '<span>'+index+'</span>';
|
n@34
|
306 trackSliderObj.draggable = true;
|
n@34
|
307 trackSliderObj.ondragend = dragEnd;
|
n@34
|
308
|
n@34
|
309 // Onclick, switch playback to that track
|
n@34
|
310 trackSliderObj.onclick = function() {
|
n@34
|
311 // Get the track ID from the object ID
|
n@34
|
312 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@34
|
313 audioEngineContext.selectedTrack(id);
|
n@34
|
314 };
|
n@34
|
315
|
n@34
|
316 canvas.appendChild(trackSliderObj);
|
n@34
|
317 });
|
n@39
|
318
|
n@39
|
319 // Now process any pre-test commands
|
n@39
|
320
|
n@44
|
321 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
|
n@39
|
322 if (preTest.children.length > 0)
|
n@39
|
323 {
|
n@39
|
324 currentState = 'testRunPre-'+id;
|
n@39
|
325 preTestPopupStart(preTest);
|
n@39
|
326 showPopup();
|
n@39
|
327 } else {
|
n@39
|
328 currentState = 'testRun-'+id;
|
n@39
|
329 }
|
n@39
|
330 }
|
n@39
|
331
|
n@39
|
332 function preTestPopupStart(preTest)
|
n@39
|
333 {
|
n@39
|
334 var popupHolder = document.getElementById('popupHolder');
|
n@39
|
335 popupHolder.innerHTML = null;
|
n@39
|
336 // Parse the first box
|
n@39
|
337 var preTestOption = document.createElement('div');
|
n@39
|
338 preTestOption.id = 'preTest';
|
n@39
|
339 preTestOption.style.marginTop = '25px';
|
n@39
|
340 preTestOption.align = "center";
|
n@39
|
341 var child = preTest.children[0];
|
n@39
|
342 if (child.nodeName == 'statement')
|
n@39
|
343 {
|
n@39
|
344 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@39
|
345 } else if (child.nodeName == 'question')
|
n@39
|
346 {
|
n@39
|
347 var questionId = child.attributes['id'].value;
|
n@39
|
348 var textHold = document.createElement('span');
|
n@39
|
349 textHold.innerHTML = child.innerHTML;
|
n@39
|
350 textHold.id = questionId + 'response';
|
n@39
|
351 var textEnter = document.createElement('textarea');
|
n@39
|
352 preTestOption.appendChild(textHold);
|
n@39
|
353 preTestOption.appendChild(textEnter);
|
n@39
|
354 }
|
n@39
|
355 var nextButton = document.createElement('button');
|
n@39
|
356 nextButton.className = 'popupButton';
|
n@39
|
357 nextButton.value = '0';
|
n@39
|
358 nextButton.innerHTML = 'Next';
|
n@39
|
359 nextButton.onclick = popupButtonClick;
|
n@39
|
360
|
n@39
|
361 popupHolder.appendChild(preTestOption);
|
n@39
|
362 popupHolder.appendChild(nextButton);
|
n@34
|
363 }
|
n@34
|
364
|
n@38
|
365 function popupButtonClick()
|
n@38
|
366 {
|
n@38
|
367 // Global call from the 'Next' button click
|
n@38
|
368 if (currentState == 'preTest')
|
n@38
|
369 {
|
n@38
|
370 // At the start of the preTest routine!
|
n@39
|
371 var xmlTree = projectXML.find('setup');
|
n@39
|
372 var preTest = xmlTree.find('PreTest')[0];
|
n@39
|
373 this.value = preTestButtonClick(preTest,this.value);
|
n@39
|
374 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
375 {
|
n@39
|
376 //Specific test pre-test
|
n@39
|
377 var testId = currentState.substr(11,currentState.length-10);
|
n@44
|
378 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
|
n@39
|
379 this.value = preTestButtonClick(preTest,this.value);
|
n@42
|
380 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
381 {
|
n@42
|
382 // Specific test post-test
|
n@42
|
383 var testId = currentState.substr(12,currentState.length-11);
|
n@44
|
384 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@42
|
385 this.value = preTestButtonClick(preTest,this.value);
|
n@41
|
386 } else if (currentState == 'postTest')
|
n@41
|
387 {
|
n@41
|
388 // At the end of the test, running global post test
|
n@41
|
389 var xmlTree = projectXML.find('setup');
|
n@41
|
390 var PostTest = xmlTree.find('PostTest')[0];
|
n@41
|
391 this.value = preTestButtonClick(PostTest,this.value);
|
n@38
|
392 }
|
n@38
|
393 }
|
n@38
|
394
|
n@39
|
395 function preTestButtonClick(preTest,index)
|
n@34
|
396 {
|
n@34
|
397 // Called on click of pre-test button
|
n@36
|
398 // Need to find and parse preTest again!
|
n@36
|
399 var preTestOption = document.getElementById('preTest');
|
n@36
|
400 // Check if current state is a question!
|
n@38
|
401 if (preTest.children[index].nodeName == 'question') {
|
n@38
|
402 var questionId = preTest.children[index].attributes['id'].value;
|
n@36
|
403 var questionHold = document.createElement('comment');
|
n@36
|
404 var questionResponse = document.getElementById(questionId + 'response');
|
n@36
|
405 questionHold.id = questionId;
|
n@36
|
406 questionHold.innerHTML = questionResponse.value;
|
n@46
|
407 postPopupResponse(questionHold);
|
n@36
|
408 }
|
n@38
|
409 index++;
|
n@38
|
410 if (index < preTest.children.length)
|
n@36
|
411 {
|
n@36
|
412 // More to process
|
n@38
|
413 var child = preTest.children[index];
|
n@36
|
414 if (child.nodeName == 'statement')
|
n@36
|
415 {
|
n@36
|
416 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@36
|
417 } else if (child.nodeName == 'question')
|
n@36
|
418 {
|
n@36
|
419 var textHold = document.createElement('span');
|
n@36
|
420 textHold.innerHTML = child.innerHTML;
|
n@36
|
421 var textEnter = document.createElement('textarea');
|
n@36
|
422 textEnter.id = child.attributes['id'].value + 'response';
|
n@36
|
423 var br = document.createElement('br');
|
n@36
|
424 preTestOption.innerHTML = null;
|
n@36
|
425 preTestOption.appendChild(textHold);
|
n@36
|
426 preTestOption.appendChild(br);
|
n@36
|
427 preTestOption.appendChild(textEnter);
|
n@36
|
428 }
|
n@36
|
429 } else {
|
n@36
|
430 // Time to clear
|
n@37
|
431 preTestOption.innerHTML = null;
|
n@43
|
432 if (currentState != 'postTest') {
|
n@43
|
433 hidePopup();
|
n@43
|
434 // Progress the state!
|
n@43
|
435 advanceState();
|
n@43
|
436 } else {
|
n@43
|
437 a = createProjectSave(projectReturn);
|
n@43
|
438 preTestOption.appendChild(a);
|
n@43
|
439 }
|
n@36
|
440 }
|
n@38
|
441 return index;
|
n@36
|
442 }
|
n@36
|
443
|
n@46
|
444 function postPopupResponse(response)
|
n@46
|
445 {
|
n@46
|
446 if (currentState == 'preTest') {
|
n@46
|
447 preTestQuestions.appendChild(response);
|
n@46
|
448 } else if (currentState == 'postTest') {
|
n@46
|
449 postTestQuestions.appendChild(response);
|
n@46
|
450 } else {
|
n@46
|
451 // Inside a specific test
|
n@46
|
452 if (currentState.substr(0,10) == 'testRunPre') {
|
n@46
|
453 // Pre Test
|
n@46
|
454 var store = $(currentTestHolder).find('preTest');
|
n@46
|
455 } else {
|
n@46
|
456 // Post Test
|
n@46
|
457 var store = $(currentTestHolder).find('postTest');
|
n@46
|
458 }
|
n@46
|
459 store[0].appendChild(response);
|
n@46
|
460 }
|
n@46
|
461 }
|
n@46
|
462
|
n@36
|
463 function showPopup()
|
n@36
|
464 {
|
n@37
|
465 var popupHolder = document.getElementById('popupHolder');
|
n@38
|
466 popupHolder.style.zIndex = 3;
|
n@37
|
467 popupHolder.style.visibility = 'visible';
|
n@37
|
468 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
469 blank.style.zIndex = 2;
|
n@37
|
470 blank.style.visibility = 'visible';
|
n@36
|
471 }
|
n@36
|
472
|
n@36
|
473 function hidePopup()
|
n@36
|
474 {
|
n@37
|
475 var popupHolder = document.getElementById('popupHolder');
|
n@37
|
476 popupHolder.style.zIndex = -1;
|
n@37
|
477 popupHolder.style.visibility = 'hidden';
|
n@37
|
478 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
479 blank.style.zIndex = -2;
|
n@37
|
480 blank.style.visibility = 'hidden';
|
n@34
|
481 }
|
n@34
|
482
|
nicholas@5
|
483 function dragEnd(ev) {
|
nicholas@5
|
484 // Function call when a div has been dropped
|
n@33
|
485 var slider = document.getElementById('slider');
|
nicholas@5
|
486 if (ev.x >= 50 && ev.x < window.innerWidth-50) {
|
nicholas@5
|
487 this.style.left = (ev.x)+'px';
|
nicholas@5
|
488 } else {
|
nicholas@5
|
489 if (ev.x<50) {
|
nicholas@5
|
490 this.style.left = '50px';
|
nicholas@5
|
491 } else {
|
nicholas@5
|
492 this.style.left = window.innerWidth-50 + 'px';
|
nicholas@5
|
493 }
|
nicholas@5
|
494 }
|
nicholas@5
|
495 }
|
nicholas@7
|
496
|
n@39
|
497 function advanceState()
|
n@39
|
498 {
|
n@39
|
499 console.log(currentState);
|
n@39
|
500 if (currentState == 'preTest')
|
n@39
|
501 {
|
n@39
|
502 // End of pre-test, begin the test
|
n@39
|
503 loadTest(0);
|
n@39
|
504 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
505 {
|
n@39
|
506 // Start the test
|
n@39
|
507 var testId = currentState.substr(11,currentState.length-10);
|
n@39
|
508 currentState = 'testRun-'+testId;
|
n@42
|
509 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
510 {
|
n@44
|
511 var testId = currentState.substr(12,currentState.length-11);
|
n@42
|
512 testEnded(testId);
|
n@40
|
513 } else if (currentState.substr(0,7) == 'testRun')
|
n@40
|
514 {
|
n@40
|
515 var testId = currentState.substr(8,currentState.length-7);
|
n@40
|
516 // Check if we have any post tests to perform
|
n@44
|
517 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@40
|
518 if (postXML.children.length > 0)
|
n@40
|
519 {
|
n@42
|
520 currentState = 'testRunPost-'+testId;
|
n@42
|
521 showPopup();
|
n@42
|
522 preTestPopupStart(postXML);
|
n@40
|
523 }
|
n@42
|
524 else {
|
n@40
|
525
|
n@40
|
526
|
n@42
|
527 // No post tests, check if we have another test to perform instead
|
n@42
|
528 testEnded(testId);
|
n@40
|
529 }
|
n@39
|
530 }
|
n@39
|
531 console.log(currentState);
|
n@39
|
532 }
|
n@39
|
533
|
n@42
|
534 function testEnded(testId)
|
n@42
|
535 {
|
n@45
|
536 pageXMLSave(testId);
|
n@42
|
537 if (testXMLSetups.length-1 > testId)
|
n@42
|
538 {
|
n@42
|
539 // Yes we have another test to perform
|
n@44
|
540 testId = (Number(testId)+1);
|
n@44
|
541 currentState = 'testRun-'+testId;
|
n@44
|
542 loadTest(testId);
|
n@42
|
543 } else {
|
n@42
|
544 console.log('Testing Completed!');
|
n@42
|
545 currentState = 'postTest';
|
n@42
|
546 // Check for any post tests
|
n@42
|
547 var xmlSetup = projectXML.find('setup');
|
n@42
|
548 var postTest = xmlSetup.find('PostTest')[0];
|
n@42
|
549 showPopup();
|
n@42
|
550 preTestPopupStart(postTest);
|
n@42
|
551 }
|
n@42
|
552 }
|
n@42
|
553
|
n@40
|
554 function buttonSubmitClick()
|
n@40
|
555 {
|
n@40
|
556 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
n@40
|
557 if (currentState.substr(0,7) == 'testRun')
|
n@40
|
558 {
|
n@40
|
559 advanceState();
|
n@40
|
560 }
|
n@40
|
561 }
|
n@40
|
562
|
n@44
|
563 function pageXMLSave(testId)
|
n@44
|
564 {
|
n@44
|
565 // Saves a specific test page
|
n@46
|
566 var xmlDoc = currentTestHolder;
|
n@45
|
567 var trackSliderObjects = document.getElementsByClassName('track-slider');
|
n@45
|
568 var commentObjects = document.getElementsByClassName('comment-div');
|
n@45
|
569 var rateMin = 50;
|
n@45
|
570 var rateMax = window.innerWidth-50;
|
n@45
|
571 for (var i=0; i<trackSliderObjects.length; i++)
|
n@45
|
572 {
|
n@45
|
573 var audioElement = document.createElement('audioElement');
|
n@45
|
574 audioElement.id = currentTrackOrder[i].attributes['id'].value;
|
n@45
|
575 audioElement.url = currentTrackOrder[i].attributes['url'].value;
|
n@45
|
576 var value = document.createElement("value");
|
n@45
|
577 var rate = Number(trackSliderObjects[i].style.left.substr(0,trackSliderObjects[i].style.left.length-2));
|
n@45
|
578 rate = (rate-rateMin)/rateMax;
|
n@45
|
579 value.innerHTML = Math.floor(rate*100);
|
n@45
|
580 var comment = document.createElement("comment");
|
n@45
|
581 var question = document.createElement("question");
|
n@45
|
582 var response = document.createElement("response");
|
n@45
|
583 question.textContent = commentObjects[i].children[0].textContent;
|
n@45
|
584 response.textContent = commentObjects[i].children[2].value;
|
n@45
|
585 comment.appendChild(question);
|
n@45
|
586 comment.appendChild(response);
|
n@45
|
587 audioElement.appendChild(value);
|
n@45
|
588 audioElement.appendChild(comment);
|
n@45
|
589 xmlDoc.appendChild(audioElement);
|
n@45
|
590 }
|
n@45
|
591 testResultsHolders[testId] = xmlDoc;
|
n@44
|
592 }
|
n@44
|
593
|
nicholas@7
|
594 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nicholas@7
|
595 function interfaceXMLSave(){
|
nicholas@7
|
596 // Create the XML string to be exported with results
|
nicholas@7
|
597 var xmlDoc = document.createElement("BrowserEvaluationResult");
|
n@45
|
598 for (var i=0; i<testResultsHolders.length; i++)
|
nicholas@7
|
599 {
|
n@45
|
600 xmlDoc.appendChild(testResultsHolders[i]);
|
nicholas@7
|
601 }
|
n@23
|
602 // Append Pre/Post Questions
|
n@23
|
603 xmlDoc.appendChild(preTestQuestions);
|
n@23
|
604 xmlDoc.appendChild(postTestQuestions);
|
n@23
|
605
|
nicholas@7
|
606 return xmlDoc;
|
nicholas@7
|
607 }
|
nicholas@7
|
608
|