nickjillings@1318
|
1 /**
|
nickjillings@1318
|
2 * core.js
|
nickjillings@1318
|
3 *
|
nickjillings@1318
|
4 * Main script to run, calls all other core functions and manages loading/store to backend.
|
nickjillings@1318
|
5 * Also contains all global variables.
|
nickjillings@1318
|
6 */
|
nickjillings@1318
|
7
|
nickjillings@1318
|
8 /* create the web audio API context and store in audioContext*/
|
nickjillings@1318
|
9 var audioContext; // Hold the browser web audio API
|
nickjillings@1318
|
10 var projectXML; // Hold the parsed setup XML
|
nickjillings@1324
|
11 var schemaXSD; // Hold the parsed schema XSD
|
nickjillings@1318
|
12 var specification;
|
nickjillings@1318
|
13 var interfaceContext;
|
nickjillings@1324
|
14 var storage;
|
nickjillings@1318
|
15 var popup; // Hold the interfacePopup object
|
nickjillings@1318
|
16 var testState;
|
nickjillings@1318
|
17 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
|
nickjillings@1318
|
18 var audioEngineContext; // The custome AudioEngine object
|
nickjillings@1318
|
19 var projectReturn; // Hold the URL for the return
|
nickjillings@1318
|
20
|
nickjillings@1318
|
21
|
nickjillings@1318
|
22 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
|
nickjillings@1318
|
23 AudioBufferSourceNode.prototype.owner = undefined;
|
nickjillings@1318
|
24 // Add a prototype to the bufferNode to hold the desired LINEAR gain
|
nickjillings@1320
|
25 AudioBuffer.prototype.playbackGain = undefined;
|
nickjillings@1318
|
26 // Add a prototype to the bufferNode to hold the computed LUFS loudness
|
nickjillings@1318
|
27 AudioBuffer.prototype.lufs = undefined;
|
nickjillings@1318
|
28
|
nickjillings@1348
|
29 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1348
|
30 // and there is no searchAll style command, this custom function will
|
nickjillings@1348
|
31 // search all children recusrively for the name. Used for XSD where all
|
nickjillings@1348
|
32 // element nodes must have a name and therefore can pull the schema node
|
nickjillings@1348
|
33 XMLDocument.prototype.getAllElementsByName = function(name)
|
nickjillings@1348
|
34 {
|
nickjillings@1348
|
35 name = String(name);
|
nickjillings@1348
|
36 var selected = this.documentElement.getAllElementsByName(name);
|
nickjillings@1348
|
37 return selected;
|
nickjillings@1348
|
38 }
|
nickjillings@1348
|
39
|
nickjillings@1348
|
40 Element.prototype.getAllElementsByName = function(name)
|
nickjillings@1348
|
41 {
|
nickjillings@1348
|
42 name = String(name);
|
nickjillings@1348
|
43 var selected = [];
|
nickjillings@1348
|
44 var node = this.firstElementChild;
|
nickjillings@1348
|
45 while(node != null)
|
nickjillings@1348
|
46 {
|
nickjillings@1348
|
47 if (node.getAttribute('name') == name)
|
nickjillings@1348
|
48 {
|
nickjillings@1348
|
49 selected.push(node);
|
nickjillings@1348
|
50 }
|
nickjillings@1348
|
51 if (node.childElementCount > 0)
|
nickjillings@1348
|
52 {
|
nickjillings@1348
|
53 selected = selected.concat(node.getAllElementsByName(name));
|
nickjillings@1348
|
54 }
|
nickjillings@1348
|
55 node = node.nextElementSibling;
|
nickjillings@1348
|
56 }
|
nickjillings@1348
|
57 return selected;
|
nickjillings@1348
|
58 }
|
nickjillings@1348
|
59
|
nickjillings@1348
|
60 XMLDocument.prototype.getAllElementsByTagName = function(name)
|
nickjillings@1348
|
61 {
|
nickjillings@1348
|
62 name = String(name);
|
nickjillings@1348
|
63 var selected = this.documentElement.getAllElementsByTagName(name);
|
nickjillings@1348
|
64 return selected;
|
nickjillings@1348
|
65 }
|
nickjillings@1348
|
66
|
nickjillings@1348
|
67 Element.prototype.getAllElementsByTagName = function(name)
|
nickjillings@1348
|
68 {
|
nickjillings@1348
|
69 name = String(name);
|
nickjillings@1348
|
70 var selected = [];
|
nickjillings@1348
|
71 var node = this.firstElementChild;
|
nickjillings@1348
|
72 while(node != null)
|
nickjillings@1348
|
73 {
|
nickjillings@1348
|
74 if (node.nodeName == name)
|
nickjillings@1348
|
75 {
|
nickjillings@1348
|
76 selected.push(node);
|
nickjillings@1348
|
77 }
|
nickjillings@1348
|
78 if (node.childElementCount > 0)
|
nickjillings@1348
|
79 {
|
nickjillings@1348
|
80 selected = selected.concat(node.getAllElementsByTagName(name));
|
nickjillings@1348
|
81 }
|
nickjillings@1348
|
82 node = node.nextElementSibling;
|
nickjillings@1348
|
83 }
|
nickjillings@1348
|
84 return selected;
|
nickjillings@1348
|
85 }
|
nickjillings@1348
|
86
|
nickjillings@1348
|
87 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1348
|
88 if (typeof XMLDocument.prototype.getElementsByName != "function") {
|
nickjillings@1348
|
89 XMLDocument.prototype.getElementsByName = function(name)
|
nickjillings@1348
|
90 {
|
nickjillings@1348
|
91 name = String(name);
|
nickjillings@1348
|
92 var node = this.documentElement.firstElementChild;
|
nickjillings@1348
|
93 var selected = [];
|
nickjillings@1348
|
94 while(node != null)
|
nickjillings@1348
|
95 {
|
nickjillings@1348
|
96 if (node.getAttribute('name') == name)
|
nickjillings@1348
|
97 {
|
nickjillings@1348
|
98 selected.push(node);
|
nickjillings@1348
|
99 }
|
nickjillings@1348
|
100 node = node.nextElementSibling;
|
nickjillings@1348
|
101 }
|
nickjillings@1348
|
102 return selected;
|
nickjillings@1348
|
103 }
|
nickjillings@1348
|
104 }
|
nickjillings@1348
|
105
|
nickjillings@1318
|
106 window.onload = function() {
|
nickjillings@1318
|
107 // Function called once the browser has loaded all files.
|
nickjillings@1318
|
108 // This should perform any initial commands such as structure / loading documents
|
nickjillings@1318
|
109
|
nickjillings@1318
|
110 // Create a web audio API context
|
nickjillings@1318
|
111 // Fixed for cross-browser support
|
nickjillings@1318
|
112 var AudioContext = window.AudioContext || window.webkitAudioContext;
|
nickjillings@1318
|
113 audioContext = new AudioContext;
|
nickjillings@1318
|
114
|
nickjillings@1318
|
115 // Create test state
|
nickjillings@1318
|
116 testState = new stateMachine();
|
nickjillings@1318
|
117
|
nickjillings@1318
|
118 // Create the popup interface object
|
nickjillings@1318
|
119 popup = new interfacePopup();
|
nickjillings@1318
|
120
|
nickjillings@1318
|
121 // Create the specification object
|
nickjillings@1318
|
122 specification = new Specification();
|
nickjillings@1318
|
123
|
nickjillings@1318
|
124 // Create the interface object
|
nickjillings@1318
|
125 interfaceContext = new Interface(specification);
|
nickjillings@1324
|
126
|
nickjillings@1324
|
127 // Create the storage object
|
nickjillings@1324
|
128 storage = new Storage();
|
nickjillings@1318
|
129 // Define window callbacks for interface
|
nickjillings@1318
|
130 window.onresize = function(event){interfaceContext.resizeWindow(event);};
|
nickjillings@1318
|
131 };
|
nickjillings@1318
|
132
|
nickjillings@1318
|
133 function loadProjectSpec(url) {
|
nickjillings@1318
|
134 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
|
nickjillings@1318
|
135 // If url is null, request client to upload project XML document
|
nickjillings@1324
|
136 var xmlhttp = new XMLHttpRequest();
|
nickjillings@1324
|
137 xmlhttp.open("GET",'test-schema.xsd',true);
|
nickjillings@1324
|
138 xmlhttp.onload = function()
|
nickjillings@1324
|
139 {
|
nickjillings@1324
|
140 schemaXSD = xmlhttp.response;
|
nickjillings@1324
|
141 var parse = new DOMParser();
|
nickjillings@1324
|
142 specification.schema = parse.parseFromString(xmlhttp.response,'text/xml');
|
nickjillings@1324
|
143 var r = new XMLHttpRequest();
|
nickjillings@1324
|
144 r.open('GET',url,true);
|
nickjillings@1324
|
145 r.onload = function() {
|
nickjillings@1324
|
146 loadProjectSpecCallback(r.response);
|
nickjillings@1324
|
147 };
|
nickjillings@1324
|
148 r.send();
|
nickjillings@1318
|
149 };
|
nickjillings@1324
|
150 xmlhttp.send();
|
nickjillings@1318
|
151 };
|
nickjillings@1318
|
152
|
nickjillings@1318
|
153 function loadProjectSpecCallback(response) {
|
nickjillings@1318
|
154 // Function called after asynchronous download of XML project specification
|
nickjillings@1318
|
155 //var decode = $.parseXML(response);
|
nickjillings@1318
|
156 //projectXML = $(decode);
|
nickjillings@1318
|
157
|
nickjillings@1324
|
158 // First perform XML schema validation
|
nickjillings@1324
|
159 var Module = {
|
nickjillings@1324
|
160 xml: response,
|
nickjillings@1324
|
161 schema: schemaXSD,
|
nickjillings@1324
|
162 arguments:["--noout", "--schema", 'test-schema.xsd','document.xml']
|
nickjillings@1324
|
163 };
|
nickjillings@1324
|
164
|
nickjillings@1324
|
165 var xmllint = validateXML(Module);
|
nickjillings@1324
|
166 console.log(xmllint);
|
nickjillings@1324
|
167 if(xmllint != 'document.xml validates\n')
|
nickjillings@1324
|
168 {
|
nickjillings@1324
|
169 document.getElementsByTagName('body')[0].innerHTML = null;
|
nickjillings@1324
|
170 var msg = document.createElement("h3");
|
nickjillings@1324
|
171 msg.textContent = "FATAL ERROR";
|
nickjillings@1324
|
172 var span = document.createElement("h4");
|
nickjillings@1324
|
173 span.textContent = "The XML validator returned the following errors when decoding your XML file";
|
nickjillings@1324
|
174 document.getElementsByTagName('body')[0].appendChild(msg);
|
nickjillings@1324
|
175 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1324
|
176 xmllint = xmllint.split('\n');
|
nickjillings@1324
|
177 for (var i in xmllint)
|
nickjillings@1324
|
178 {
|
nickjillings@1324
|
179 document.getElementsByTagName('body')[0].appendChild(document.createElement('br'));
|
nickjillings@1324
|
180 var span = document.createElement("span");
|
nickjillings@1324
|
181 span.textContent = xmllint[i];
|
nickjillings@1324
|
182 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1324
|
183 }
|
nickjillings@1324
|
184 return;
|
nickjillings@1324
|
185 }
|
nickjillings@1324
|
186
|
nickjillings@1318
|
187 var parse = new DOMParser();
|
nickjillings@1318
|
188 projectXML = parse.parseFromString(response,'text/xml');
|
nickjillings@1318
|
189 var errorNode = projectXML.getElementsByTagName('parsererror');
|
nickjillings@1318
|
190 if (errorNode.length >= 1)
|
nickjillings@1318
|
191 {
|
nickjillings@1318
|
192 var msg = document.createElement("h3");
|
nickjillings@1318
|
193 msg.textContent = "FATAL ERROR";
|
nickjillings@1318
|
194 var span = document.createElement("span");
|
nickjillings@1318
|
195 span.textContent = "The XML parser returned the following errors when decoding your XML file";
|
nickjillings@1318
|
196 document.getElementsByTagName('body')[0].innerHTML = null;
|
nickjillings@1318
|
197 document.getElementsByTagName('body')[0].appendChild(msg);
|
nickjillings@1318
|
198 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1318
|
199 document.getElementsByTagName('body')[0].appendChild(errorNode[0]);
|
nickjillings@1318
|
200 return;
|
nickjillings@1318
|
201 }
|
nickjillings@1318
|
202
|
nickjillings@1318
|
203 // Build the specification
|
nickjillings@1318
|
204 specification.decode(projectXML);
|
nickjillings@1324
|
205 storage.initialise();
|
nickjillings@1339
|
206 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
nickjillings@1339
|
207 if (specification.sampleRate != undefined) {
|
nickjillings@1339
|
208 if (Number(specification.sampleRate) != audioContext.sampleRate) {
|
nickjillings@1339
|
209 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
nickjillings@1339
|
210 alert(errStr);
|
nickjillings@1339
|
211 return;
|
nickjillings@1339
|
212 }
|
nickjillings@1339
|
213 }
|
nickjillings@1318
|
214
|
nickjillings@1318
|
215 // Detect the interface to use and load the relevant javascripts.
|
nickjillings@1318
|
216 var interfaceJS = document.createElement('script');
|
nickjillings@1318
|
217 interfaceJS.setAttribute("type","text/javascript");
|
nickjillings@1329
|
218 switch(specification.interface)
|
nickjillings@1329
|
219 {
|
nickjillings@1329
|
220 case "APE":
|
nickjillings@1341
|
221 interfaceJS.setAttribute("src","interfaces/ape.js");
|
nickjillings@1318
|
222
|
nickjillings@1318
|
223 // APE comes with a css file
|
nickjillings@1318
|
224 var css = document.createElement('link');
|
nickjillings@1318
|
225 css.rel = 'stylesheet';
|
nickjillings@1318
|
226 css.type = 'text/css';
|
nickjillings@1341
|
227 css.href = 'interfaces/ape.css';
|
nickjillings@1318
|
228
|
nickjillings@1318
|
229 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1329
|
230 break;
|
nickjillings@1329
|
231
|
nickjillings@1329
|
232 case "MUSHRA":
|
nickjillings@1341
|
233 interfaceJS.setAttribute("src","interfaces/mushra.js");
|
nickjillings@1318
|
234
|
nickjillings@1318
|
235 // MUSHRA comes with a css file
|
nickjillings@1318
|
236 var css = document.createElement('link');
|
nickjillings@1318
|
237 css.rel = 'stylesheet';
|
nickjillings@1318
|
238 css.type = 'text/css';
|
nickjillings@1341
|
239 css.href = 'interfaces/mushra.css';
|
nickjillings@1318
|
240
|
nickjillings@1318
|
241 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1329
|
242 break;
|
nickjillings@1329
|
243
|
nickjillings@1329
|
244 case "AB":
|
nickjillings@1341
|
245 interfaceJS.setAttribute("src","interfaces/AB.js");
|
nickjillings@1329
|
246
|
nickjillings@1329
|
247 // AB comes with a css file
|
nickjillings@1329
|
248 var css = document.createElement('link');
|
nickjillings@1329
|
249 css.rel = 'stylesheet';
|
nickjillings@1329
|
250 css.type = 'text/css';
|
nickjillings@1341
|
251 css.href = 'interfaces/AB.css';
|
nickjillings@1329
|
252
|
nickjillings@1329
|
253 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
254 break;
|
nickjillings@1345
|
255 case "Bipolar":
|
nickjillings@1345
|
256 case "ACR":
|
nickjillings@1345
|
257 case "DCR":
|
nickjillings@1345
|
258 case "CCR":
|
nickjillings@1343
|
259 case "ABC":
|
nickjillings@1343
|
260 // Above enumerate to horizontal sliders
|
nickjillings@1343
|
261 interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js");
|
nickjillings@1343
|
262
|
nickjillings@1343
|
263 // horizontal-sliders comes with a css file
|
nickjillings@1343
|
264 var css = document.createElement('link');
|
nickjillings@1343
|
265 css.rel = 'stylesheet';
|
nickjillings@1343
|
266 css.type = 'text/css';
|
nickjillings@1343
|
267 css.href = 'interfaces/horizontal-sliders.css';
|
nickjillings@1343
|
268
|
nickjillings@1343
|
269 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
270 break;
|
nickjillings@1345
|
271 case "discrete":
|
nickjillings@1345
|
272 case "likert":
|
nickjillings@1345
|
273 // Above enumerate to horizontal discrete radios
|
nickjillings@1345
|
274 interfaceJS.setAttribute("src","interfaces/discrete.js");
|
nickjillings@1345
|
275
|
nickjillings@1345
|
276 // horizontal-sliders comes with a css file
|
nickjillings@1345
|
277 var css = document.createElement('link');
|
nickjillings@1345
|
278 css.rel = 'stylesheet';
|
nickjillings@1345
|
279 css.type = 'text/css';
|
nickjillings@1345
|
280 css.href = 'interfaces/discrete.css';
|
nickjillings@1345
|
281
|
nickjillings@1345
|
282 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
283 break;
|
nickjillings@1318
|
284 }
|
nickjillings@1318
|
285 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
|
nickjillings@1318
|
286
|
nickjillings@1318
|
287 // Create the audio engine object
|
nickjillings@1318
|
288 audioEngineContext = new AudioEngine(specification);
|
nickjillings@1318
|
289
|
nickjillings@1324
|
290 $(specification.pages).each(function(index,elem){
|
nickjillings@1318
|
291 $(elem.audioElements).each(function(i,audioElem){
|
nickjillings@1324
|
292 var URL = elem.hostURL + audioElem.url;
|
nickjillings@1318
|
293 var buffer = null;
|
nickjillings@1318
|
294 for (var i=0; i<audioEngineContext.buffers.length; i++)
|
nickjillings@1318
|
295 {
|
nickjillings@1318
|
296 if (URL == audioEngineContext.buffers[i].url)
|
nickjillings@1318
|
297 {
|
nickjillings@1318
|
298 buffer = audioEngineContext.buffers[i];
|
nickjillings@1318
|
299 break;
|
nickjillings@1318
|
300 }
|
nickjillings@1318
|
301 }
|
nickjillings@1318
|
302 if (buffer == null)
|
nickjillings@1318
|
303 {
|
nickjillings@1318
|
304 buffer = new audioEngineContext.bufferObj();
|
nickjillings@1318
|
305 buffer.getMedia(URL);
|
nickjillings@1318
|
306 audioEngineContext.buffers.push(buffer);
|
nickjillings@1318
|
307 }
|
nickjillings@1318
|
308 });
|
nickjillings@1318
|
309 });
|
nickjillings@1318
|
310 }
|
nickjillings@1318
|
311
|
nickjillings@1318
|
312 function createProjectSave(destURL) {
|
nickjillings@1318
|
313 // Save the data from interface into XML and send to destURL
|
nickjillings@1318
|
314 // If destURL is null then download XML in client
|
nickjillings@1318
|
315 // Now time to render file locally
|
nickjillings@1318
|
316 var xmlDoc = interfaceXMLSave();
|
nickjillings@1318
|
317 var parent = document.createElement("div");
|
nickjillings@1318
|
318 parent.appendChild(xmlDoc);
|
nickjillings@1318
|
319 var file = [parent.innerHTML];
|
nickjillings@1318
|
320 if (destURL == "null" || destURL == undefined) {
|
nickjillings@1318
|
321 var bb = new Blob(file,{type : 'application/xml'});
|
nickjillings@1318
|
322 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1318
|
323 var a = document.createElement("a");
|
nickjillings@1318
|
324 a.hidden = '';
|
nickjillings@1318
|
325 a.href = dnlk;
|
nickjillings@1318
|
326 a.download = "save.xml";
|
nickjillings@1318
|
327 a.textContent = "Save File";
|
nickjillings@1318
|
328
|
nickjillings@1318
|
329 popup.showPopup();
|
nickjillings@1332
|
330 popup.popupContent.innerHTML = "</span>Please save the file below to give to your test supervisor</span><br>";
|
nickjillings@1318
|
331 popup.popupContent.appendChild(a);
|
nickjillings@1318
|
332 } else {
|
nickjillings@1318
|
333 var xmlhttp = new XMLHttpRequest;
|
nickjillings@1318
|
334 xmlhttp.open("POST",destURL,true);
|
nickjillings@1318
|
335 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
|
nickjillings@1318
|
336 xmlhttp.onerror = function(){
|
nickjillings@1318
|
337 console.log('Error saving file to server! Presenting download locally');
|
nickjillings@1318
|
338 createProjectSave(null);
|
nickjillings@1318
|
339 };
|
nickjillings@1318
|
340 xmlhttp.onreadystatechange = function() {
|
nickjillings@1318
|
341 console.log(xmlhttp.status);
|
nickjillings@1318
|
342 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
|
nickjillings@1318
|
343 createProjectSave(null);
|
nickjillings@1318
|
344 } else {
|
nickjillings@1318
|
345 if (xmlhttp.responseXML == null)
|
nickjillings@1318
|
346 {
|
nickjillings@1324
|
347 createProjectSave('null');
|
nickjillings@1318
|
348 }
|
nickjillings@1318
|
349 var response = xmlhttp.responseXML.childNodes[0];
|
nickjillings@1318
|
350 if (response.getAttribute('state') == "OK")
|
nickjillings@1318
|
351 {
|
nickjillings@1318
|
352 var file = response.getElementsByTagName('file')[0];
|
nickjillings@1318
|
353 console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B');
|
nickjillings@1318
|
354 popup.showPopup();
|
nickjillings@1318
|
355 popup.popupContent.innerHTML = null;
|
nickjillings@1318
|
356 popup.popupContent.textContent = "Thank you!";
|
nickjillings@1318
|
357 } else {
|
nickjillings@1318
|
358 var message = response.getElementsByTagName('message')[0];
|
nickjillings@1318
|
359 errorSessionDump(message.textContent);
|
nickjillings@1318
|
360 }
|
nickjillings@1318
|
361 }
|
nickjillings@1318
|
362 };
|
nickjillings@1318
|
363 xmlhttp.send(file);
|
nickjillings@1332
|
364 popup.showPopup();
|
nickjillings@1332
|
365 popup.popupContent.innerHTML = null;
|
nickjillings@1332
|
366 popup.popupContent.textContent = "Submitting. Please Wait";
|
nickjillings@1318
|
367 }
|
nickjillings@1318
|
368 }
|
nickjillings@1318
|
369
|
nickjillings@1318
|
370 function errorSessionDump(msg){
|
nickjillings@1318
|
371 // Create the partial interface XML save
|
nickjillings@1318
|
372 // Include error node with message on why the dump occured
|
nickjillings@1318
|
373 popup.showPopup();
|
nickjillings@1318
|
374 popup.popupContent.innerHTML = null;
|
nickjillings@1318
|
375 var err = document.createElement('error');
|
nickjillings@1318
|
376 var parent = document.createElement("div");
|
nickjillings@1318
|
377 if (typeof msg === "object")
|
nickjillings@1318
|
378 {
|
nickjillings@1318
|
379 err.appendChild(msg);
|
nickjillings@1318
|
380 popup.popupContent.appendChild(msg);
|
nickjillings@1318
|
381
|
nickjillings@1318
|
382 } else {
|
nickjillings@1318
|
383 err.textContent = msg;
|
nickjillings@1318
|
384 popup.popupContent.innerHTML = "ERROR : "+msg;
|
nickjillings@1318
|
385 }
|
nickjillings@1318
|
386 var xmlDoc = interfaceXMLSave();
|
nickjillings@1318
|
387 xmlDoc.appendChild(err);
|
nickjillings@1318
|
388 parent.appendChild(xmlDoc);
|
nickjillings@1318
|
389 var file = [parent.innerHTML];
|
nickjillings@1318
|
390 var bb = new Blob(file,{type : 'application/xml'});
|
nickjillings@1318
|
391 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1318
|
392 var a = document.createElement("a");
|
nickjillings@1318
|
393 a.hidden = '';
|
nickjillings@1318
|
394 a.href = dnlk;
|
nickjillings@1318
|
395 a.download = "save.xml";
|
nickjillings@1318
|
396 a.textContent = "Save File";
|
nickjillings@1318
|
397
|
nickjillings@1318
|
398
|
nickjillings@1318
|
399
|
nickjillings@1318
|
400 popup.popupContent.appendChild(a);
|
nickjillings@1318
|
401 }
|
nickjillings@1318
|
402
|
nickjillings@1318
|
403 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nickjillings@1318
|
404 function interfaceXMLSave(){
|
nickjillings@1318
|
405 // Create the XML string to be exported with results
|
nickjillings@1324
|
406 return storage.finish();
|
nickjillings@1318
|
407 }
|
nickjillings@1318
|
408
|
nickjillings@1318
|
409 function linearToDecibel(gain)
|
nickjillings@1318
|
410 {
|
nickjillings@1318
|
411 return 20.0*Math.log10(gain);
|
nickjillings@1318
|
412 }
|
nickjillings@1318
|
413
|
nickjillings@1318
|
414 function decibelToLinear(gain)
|
nickjillings@1318
|
415 {
|
nickjillings@1318
|
416 return Math.pow(10,gain/20.0);
|
nickjillings@1318
|
417 }
|
nickjillings@1318
|
418
|
nickjillings@1318
|
419 function interfacePopup() {
|
nickjillings@1318
|
420 // Creates an object to manage the popup
|
nickjillings@1318
|
421 this.popup = null;
|
nickjillings@1318
|
422 this.popupContent = null;
|
nickjillings@1318
|
423 this.popupTitle = null;
|
nickjillings@1318
|
424 this.popupResponse = null;
|
nickjillings@1318
|
425 this.buttonProceed = null;
|
nickjillings@1318
|
426 this.buttonPrevious = null;
|
nickjillings@1318
|
427 this.popupOptions = null;
|
nickjillings@1318
|
428 this.currentIndex = null;
|
nickjillings@1324
|
429 this.node = null;
|
nickjillings@1324
|
430 this.store = null;
|
nickjillings@1318
|
431 $(window).keypress(function(e){
|
nickjillings@1318
|
432 if (e.keyCode == 13 && popup.popup.style.visibility == 'visible')
|
nickjillings@1318
|
433 {
|
nickjillings@1318
|
434 console.log(e);
|
nickjillings@1318
|
435 popup.buttonProceed.onclick();
|
nickjillings@1318
|
436 e.preventDefault();
|
nickjillings@1318
|
437 }
|
nickjillings@1318
|
438 });
|
nickjillings@1318
|
439
|
nickjillings@1318
|
440 this.createPopup = function(){
|
nickjillings@1318
|
441 // Create popup window interface
|
nickjillings@1318
|
442 var insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1318
|
443 var blank = document.createElement('div');
|
nickjillings@1318
|
444 blank.className = 'testHalt';
|
nickjillings@1318
|
445
|
nickjillings@1318
|
446 this.popup = document.createElement('div');
|
nickjillings@1318
|
447 this.popup.id = 'popupHolder';
|
nickjillings@1318
|
448 this.popup.className = 'popupHolder';
|
nickjillings@1318
|
449 this.popup.style.position = 'absolute';
|
nickjillings@1318
|
450 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
|
nickjillings@1318
|
451 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
|
nickjillings@1318
|
452
|
nickjillings@1318
|
453 this.popupContent = document.createElement('div');
|
nickjillings@1318
|
454 this.popupContent.id = 'popupContent';
|
nickjillings@1318
|
455 this.popupContent.style.marginTop = '20px';
|
nickjillings@1318
|
456 this.popupContent.style.marginBottom = '5px';
|
nickjillings@1318
|
457 this.popup.appendChild(this.popupContent);
|
nickjillings@1318
|
458
|
nickjillings@1318
|
459 var titleHolder = document.createElement('div');
|
nickjillings@1318
|
460 titleHolder.id = 'popupTitleHolder';
|
nickjillings@1318
|
461 titleHolder.align = 'center';
|
nickjillings@1318
|
462 titleHolder.style.width = 'inherit';
|
nickjillings@1318
|
463 titleHolder.style.minHeight = '25px';
|
nickjillings@1318
|
464 titleHolder.style.maxHeight = '250px';
|
nickjillings@1318
|
465 titleHolder.style.overflow = 'auto';
|
nickjillings@1318
|
466 titleHolder.style.marginBottom = '5px';
|
nickjillings@1318
|
467
|
nickjillings@1318
|
468 this.popupTitle = document.createElement('span');
|
nickjillings@1318
|
469 this.popupTitle.id = 'popupTitle';
|
nickjillings@1318
|
470 titleHolder.appendChild(this.popupTitle);
|
nickjillings@1318
|
471 this.popupContent.appendChild(titleHolder);
|
nickjillings@1318
|
472
|
nickjillings@1318
|
473 this.popupResponse = document.createElement('div');
|
nickjillings@1318
|
474 this.popupResponse.id = 'popupResponse';
|
nickjillings@1318
|
475 this.popupResponse.align = 'center';
|
nickjillings@1318
|
476 this.popupResponse.style.width = 'inherit';
|
nickjillings@1318
|
477 this.popupResponse.style.minHeight = '50px';
|
nickjillings@1318
|
478 this.popupResponse.style.maxHeight = '320px';
|
nickjillings@1318
|
479 this.popupResponse.style.overflow = 'auto';
|
nickjillings@1318
|
480 this.popupContent.appendChild(this.popupResponse);
|
nickjillings@1318
|
481
|
nickjillings@1318
|
482 this.buttonProceed = document.createElement('button');
|
nickjillings@1318
|
483 this.buttonProceed.className = 'popupButton';
|
nickjillings@1318
|
484 this.buttonProceed.position = 'relative';
|
nickjillings@1318
|
485 this.buttonProceed.style.left = '390px';
|
nickjillings@1318
|
486 this.buttonProceed.innerHTML = 'Next';
|
nickjillings@1318
|
487 this.buttonProceed.onclick = function(){popup.proceedClicked();};
|
nickjillings@1318
|
488
|
nickjillings@1318
|
489 this.buttonPrevious = document.createElement('button');
|
nickjillings@1318
|
490 this.buttonPrevious.className = 'popupButton';
|
nickjillings@1318
|
491 this.buttonPrevious.position = 'relative';
|
nickjillings@1318
|
492 this.buttonPrevious.style.left = '10px';
|
nickjillings@1318
|
493 this.buttonPrevious.innerHTML = 'Back';
|
nickjillings@1318
|
494 this.buttonPrevious.onclick = function(){popup.previousClick();};
|
nickjillings@1318
|
495
|
nickjillings@1318
|
496 this.popupContent.appendChild(this.buttonPrevious);
|
nickjillings@1318
|
497 this.popupContent.appendChild(this.buttonProceed);
|
nickjillings@1318
|
498
|
nickjillings@1318
|
499 this.popup.style.zIndex = -1;
|
nickjillings@1318
|
500 this.popup.style.visibility = 'hidden';
|
nickjillings@1318
|
501 blank.style.zIndex = -2;
|
nickjillings@1318
|
502 blank.style.visibility = 'hidden';
|
nickjillings@1318
|
503 insertPoint.appendChild(this.popup);
|
nickjillings@1318
|
504 insertPoint.appendChild(blank);
|
nickjillings@1318
|
505 };
|
nickjillings@1318
|
506
|
nickjillings@1318
|
507 this.showPopup = function(){
|
nickjillings@1318
|
508 if (this.popup == null) {
|
nickjillings@1318
|
509 this.createPopup();
|
nickjillings@1318
|
510 }
|
nickjillings@1318
|
511 this.popup.style.zIndex = 3;
|
nickjillings@1318
|
512 this.popup.style.visibility = 'visible';
|
nickjillings@1318
|
513 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1318
|
514 blank.style.zIndex = 2;
|
nickjillings@1318
|
515 blank.style.visibility = 'visible';
|
nickjillings@1318
|
516 };
|
nickjillings@1318
|
517
|
nickjillings@1318
|
518 this.hidePopup = function(){
|
nickjillings@1318
|
519 this.popup.style.zIndex = -1;
|
nickjillings@1318
|
520 this.popup.style.visibility = 'hidden';
|
nickjillings@1318
|
521 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1318
|
522 blank.style.zIndex = -2;
|
nickjillings@1318
|
523 blank.style.visibility = 'hidden';
|
nickjillings@1318
|
524 this.buttonPrevious.style.visibility = 'inherit';
|
nickjillings@1318
|
525 };
|
nickjillings@1318
|
526
|
nickjillings@1318
|
527 this.postNode = function() {
|
nickjillings@1318
|
528 // This will take the node from the popupOptions and display it
|
nickjillings@1318
|
529 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1318
|
530 this.popupResponse.innerHTML = null;
|
nickjillings@1324
|
531 this.popupTitle.textContent = node.specification.statement;
|
nickjillings@1324
|
532 if (node.specification.type == 'question') {
|
nickjillings@1318
|
533 var textArea = document.createElement('textarea');
|
nickjillings@1324
|
534 switch (node.specification.boxsize) {
|
nickjillings@1318
|
535 case 'small':
|
nickjillings@1318
|
536 textArea.cols = "20";
|
nickjillings@1318
|
537 textArea.rows = "1";
|
nickjillings@1318
|
538 break;
|
nickjillings@1318
|
539 case 'normal':
|
nickjillings@1318
|
540 textArea.cols = "30";
|
nickjillings@1318
|
541 textArea.rows = "2";
|
nickjillings@1318
|
542 break;
|
nickjillings@1318
|
543 case 'large':
|
nickjillings@1318
|
544 textArea.cols = "40";
|
nickjillings@1318
|
545 textArea.rows = "5";
|
nickjillings@1318
|
546 break;
|
nickjillings@1318
|
547 case 'huge':
|
nickjillings@1318
|
548 textArea.cols = "50";
|
nickjillings@1318
|
549 textArea.rows = "10";
|
nickjillings@1318
|
550 break;
|
nickjillings@1318
|
551 }
|
nickjillings@1318
|
552 this.popupResponse.appendChild(textArea);
|
nickjillings@1318
|
553 textArea.focus();
|
nickjillings@1324
|
554 } else if (node.specification.type == 'checkbox') {
|
nickjillings@1324
|
555 for (var option of node.specification.options) {
|
nickjillings@1318
|
556 var input = document.createElement('input');
|
nickjillings@1320
|
557 input.id = option.name;
|
nickjillings@1318
|
558 input.type = 'checkbox';
|
nickjillings@1318
|
559 var span = document.createElement('span');
|
nickjillings@1318
|
560 span.textContent = option.text;
|
nickjillings@1318
|
561 var hold = document.createElement('div');
|
nickjillings@1318
|
562 hold.setAttribute('name','option');
|
nickjillings@1318
|
563 hold.style.padding = '4px';
|
nickjillings@1318
|
564 hold.appendChild(input);
|
nickjillings@1318
|
565 hold.appendChild(span);
|
nickjillings@1324
|
566 this.popupResponse.appendChild(hold);
|
nickjillings@1318
|
567 }
|
nickjillings@1324
|
568 } else if (node.specification.type == 'radio') {
|
nickjillings@1324
|
569 for (var option of node.specification.options) {
|
nickjillings@1318
|
570 var input = document.createElement('input');
|
nickjillings@1318
|
571 input.id = option.name;
|
nickjillings@1318
|
572 input.type = 'radio';
|
nickjillings@1324
|
573 input.name = node.specification.id;
|
nickjillings@1318
|
574 var span = document.createElement('span');
|
nickjillings@1318
|
575 span.textContent = option.text;
|
nickjillings@1318
|
576 var hold = document.createElement('div');
|
nickjillings@1318
|
577 hold.setAttribute('name','option');
|
nickjillings@1318
|
578 hold.style.padding = '4px';
|
nickjillings@1318
|
579 hold.appendChild(input);
|
nickjillings@1318
|
580 hold.appendChild(span);
|
nickjillings@1324
|
581 this.popupResponse.appendChild(hold);
|
nickjillings@1318
|
582 }
|
nickjillings@1324
|
583 } else if (node.specification.type == 'number') {
|
nickjillings@1318
|
584 var input = document.createElement('input');
|
nickjillings@1318
|
585 input.type = 'textarea';
|
nickjillings@1324
|
586 if (node.min != null) {input.min = node.specification.min;}
|
nickjillings@1324
|
587 if (node.max != null) {input.max = node.specification.max;}
|
nickjillings@1324
|
588 if (node.step != null) {input.step = node.specification.step;}
|
nickjillings@1318
|
589 this.popupResponse.appendChild(input);
|
nickjillings@1318
|
590 }
|
nickjillings@1318
|
591 var content_height = Number(this.popup.offsetHeight.toFixed());
|
nickjillings@1318
|
592 content_height -= Number(this.popupContent.offsetHeight.toFixed());
|
nickjillings@1318
|
593 content_height -=Number(this.buttonProceed.offsetHeight.toFixed());
|
nickjillings@1318
|
594 content_height = content_height + "px";
|
nickjillings@1318
|
595 this.buttonProceed.style.top = content_height;
|
nickjillings@1318
|
596 this.buttonPrevious.style.top = content_height;
|
nickjillings@1318
|
597 if(this.currentIndex+1 == this.popupOptions.length) {
|
nickjillings@1324
|
598 if (this.node.location == "pre") {
|
nickjillings@1318
|
599 this.buttonProceed.textContent = 'Start';
|
nickjillings@1318
|
600 } else {
|
nickjillings@1318
|
601 this.buttonProceed.textContent = 'Submit';
|
nickjillings@1318
|
602 }
|
nickjillings@1318
|
603 } else {
|
nickjillings@1318
|
604 this.buttonProceed.textContent = 'Next';
|
nickjillings@1318
|
605 }
|
nickjillings@1318
|
606 if(this.currentIndex > 0)
|
nickjillings@1318
|
607 this.buttonPrevious.style.visibility = 'visible';
|
nickjillings@1318
|
608 else
|
nickjillings@1318
|
609 this.buttonPrevious.style.visibility = 'hidden';
|
nickjillings@1318
|
610 };
|
nickjillings@1318
|
611
|
nickjillings@1324
|
612 this.initState = function(node,store) {
|
nickjillings@1318
|
613 //Call this with your preTest and postTest nodes when needed to
|
nickjillings@1318
|
614 // initialise the popup procedure.
|
nickjillings@1324
|
615 if (node.options.length > 0) {
|
nickjillings@1324
|
616 this.popupOptions = [];
|
nickjillings@1324
|
617 this.node = node;
|
nickjillings@1324
|
618 this.store = store;
|
nickjillings@1324
|
619 for (var opt of node.options)
|
nickjillings@1324
|
620 {
|
nickjillings@1324
|
621 this.popupOptions.push({
|
nickjillings@1324
|
622 specification: opt,
|
nickjillings@1324
|
623 response: null
|
nickjillings@1324
|
624 });
|
nickjillings@1324
|
625 }
|
nickjillings@1318
|
626 this.currentIndex = 0;
|
nickjillings@1318
|
627 this.showPopup();
|
nickjillings@1318
|
628 this.postNode();
|
nickjillings@1318
|
629 } else {
|
nickjillings@1318
|
630 advanceState();
|
nickjillings@1318
|
631 }
|
nickjillings@1318
|
632 };
|
nickjillings@1318
|
633
|
nickjillings@1318
|
634 this.proceedClicked = function() {
|
nickjillings@1318
|
635 // Each time the popup button is clicked!
|
nickjillings@1318
|
636 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1324
|
637 if (node.specification.type == 'question') {
|
nickjillings@1318
|
638 // Must extract the question data
|
nickjillings@1318
|
639 var textArea = $(popup.popupContent).find('textarea')[0];
|
nickjillings@1324
|
640 if (node.specification.mandatory == true && textArea.value.length == 0) {
|
nickjillings@1318
|
641 alert('This question is mandatory');
|
nickjillings@1318
|
642 return;
|
nickjillings@1318
|
643 } else {
|
nickjillings@1318
|
644 // Save the text content
|
nickjillings@1324
|
645 console.log("Question: "+ node.specification.statement);
|
nickjillings@1318
|
646 console.log("Question Response: "+ textArea.value);
|
nickjillings@1324
|
647 node.response = textArea.value;
|
nickjillings@1318
|
648 }
|
nickjillings@1324
|
649 } else if (node.specification.type == 'checkbox') {
|
nickjillings@1318
|
650 // Must extract checkbox data
|
nickjillings@1326
|
651 console.log("Checkbox: "+ node.specification.statement);
|
nickjillings@1324
|
652 var inputs = this.popupResponse.getElementsByTagName('input');
|
nickjillings@1324
|
653 node.response = [];
|
nickjillings@1324
|
654 for (var i=0; i<node.specification.options.length; i++) {
|
nickjillings@1324
|
655 node.response.push({
|
nickjillings@1324
|
656 name: node.specification.options[i].name,
|
nickjillings@1324
|
657 text: node.specification.options[i].text,
|
nickjillings@1324
|
658 checked: inputs[i].checked
|
nickjillings@1324
|
659 });
|
nickjillings@1326
|
660 console.log(node.specification.options[i].name+": "+ inputs[i].checked);
|
nickjillings@1324
|
661 }
|
nickjillings@1324
|
662 } else if (node.specification.type == "radio") {
|
nickjillings@1318
|
663 var optHold = this.popupResponse;
|
nickjillings@1324
|
664 console.log("Radio: "+ node.specification.statement);
|
nickjillings@1324
|
665 node.response = null;
|
nickjillings@1318
|
666 var i=0;
|
nickjillings@1324
|
667 var inputs = optHold.getElementsByTagName('input');
|
nickjillings@1324
|
668 while(node.response == null) {
|
nickjillings@1324
|
669 if (i == inputs.length)
|
nickjillings@1324
|
670 {
|
nickjillings@1324
|
671 if (node.specification.mandatory == true)
|
nickjillings@1324
|
672 {
|
nickjillings@1324
|
673 alert("This radio is mandatory");
|
nickjillings@1324
|
674 } else {
|
nickjillings@1324
|
675 node.response = -1;
|
nickjillings@1324
|
676 }
|
nickjillings@1324
|
677 return;
|
nickjillings@1324
|
678 }
|
nickjillings@1324
|
679 if (inputs[i].checked == true) {
|
nickjillings@1324
|
680 node.response = node.specification.options[i];
|
nickjillings@1324
|
681 console.log("Selected: "+ node.specification.options[i].name);
|
nickjillings@1318
|
682 }
|
nickjillings@1318
|
683 i++;
|
nickjillings@1318
|
684 }
|
nickjillings@1324
|
685 } else if (node.specification.type == "number") {
|
nickjillings@1318
|
686 var input = this.popupContent.getElementsByTagName('input')[0];
|
nickjillings@1318
|
687 if (node.mandatory == true && input.value.length == 0) {
|
nickjillings@1318
|
688 alert('This question is mandatory. Please enter a number');
|
nickjillings@1318
|
689 return;
|
nickjillings@1318
|
690 }
|
nickjillings@1318
|
691 var enteredNumber = Number(input.value);
|
nickjillings@1318
|
692 if (isNaN(enteredNumber)) {
|
nickjillings@1318
|
693 alert('Please enter a valid number');
|
nickjillings@1318
|
694 return;
|
nickjillings@1318
|
695 }
|
nickjillings@1318
|
696 if (enteredNumber < node.min && node.min != null) {
|
nickjillings@1318
|
697 alert('Number is below the minimum value of '+node.min);
|
nickjillings@1318
|
698 return;
|
nickjillings@1318
|
699 }
|
nickjillings@1318
|
700 if (enteredNumber > node.max && node.max != null) {
|
nickjillings@1318
|
701 alert('Number is above the maximum value of '+node.max);
|
nickjillings@1318
|
702 return;
|
nickjillings@1318
|
703 }
|
nickjillings@1324
|
704 node.response = input.value;
|
nickjillings@1318
|
705 }
|
nickjillings@1318
|
706 this.currentIndex++;
|
nickjillings@1318
|
707 if (this.currentIndex < this.popupOptions.length) {
|
nickjillings@1318
|
708 this.postNode();
|
nickjillings@1318
|
709 } else {
|
nickjillings@1318
|
710 // Reached the end of the popupOptions
|
nickjillings@1318
|
711 this.hidePopup();
|
nickjillings@1324
|
712 for (var node of this.popupOptions)
|
nickjillings@1324
|
713 {
|
nickjillings@1324
|
714 this.store.postResult(node);
|
nickjillings@1318
|
715 }
|
nickjillings@1318
|
716 advanceState();
|
nickjillings@1318
|
717 }
|
nickjillings@1318
|
718 };
|
nickjillings@1318
|
719
|
nickjillings@1318
|
720 this.previousClick = function() {
|
nickjillings@1318
|
721 // Triggered when the 'Back' button is clicked in the survey
|
nickjillings@1318
|
722 if (this.currentIndex > 0) {
|
nickjillings@1318
|
723 this.currentIndex--;
|
nickjillings@1318
|
724 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1318
|
725 if (node.type != 'statement') {
|
nickjillings@1318
|
726 var prevResp = this.responses.childNodes[this.responses.childElementCount-1];
|
nickjillings@1318
|
727 this.responses.removeChild(prevResp);
|
nickjillings@1318
|
728 }
|
nickjillings@1318
|
729 this.postNode();
|
nickjillings@1318
|
730 if (node.type == 'question') {
|
nickjillings@1318
|
731 this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent;
|
nickjillings@1318
|
732 } else if (node.type == 'checkbox') {
|
nickjillings@1318
|
733 var options = this.popupContent.getElementsByTagName('input');
|
nickjillings@1318
|
734 var savedOptions = prevResp.getElementsByTagName('option');
|
nickjillings@1318
|
735 for (var i=0; i<options.length; i++) {
|
nickjillings@1318
|
736 var id = options[i].id;
|
nickjillings@1318
|
737 for (var j=0; j<savedOptions.length; j++) {
|
nickjillings@1318
|
738 if (savedOptions[j].getAttribute('name') == id) {
|
nickjillings@1318
|
739 if (savedOptions[j].textContent == 'true') {options[i].checked = true;}
|
nickjillings@1318
|
740 else {options[i].checked = false;}
|
nickjillings@1318
|
741 break;
|
nickjillings@1318
|
742 }
|
nickjillings@1318
|
743 }
|
nickjillings@1318
|
744 }
|
nickjillings@1318
|
745 } else if (node.type == 'number') {
|
nickjillings@1318
|
746 this.popupContent.getElementsByTagName('input')[0].value = prevResp.textContent;
|
nickjillings@1318
|
747 } else if (node.type == 'radio') {
|
nickjillings@1318
|
748 var options = this.popupContent.getElementsByTagName('input');
|
nickjillings@1318
|
749 var name = prevResp.getAttribute('name');
|
nickjillings@1318
|
750 for (var i=0; i<options.length; i++) {
|
nickjillings@1318
|
751 if (options[i].id == name) {
|
nickjillings@1318
|
752 options[i].checked = true;
|
nickjillings@1318
|
753 break;
|
nickjillings@1318
|
754 }
|
nickjillings@1318
|
755 }
|
nickjillings@1318
|
756 }
|
nickjillings@1318
|
757 }
|
nickjillings@1318
|
758 };
|
nickjillings@1318
|
759
|
nickjillings@1318
|
760 this.resize = function(event)
|
nickjillings@1318
|
761 {
|
nickjillings@1318
|
762 // Called on window resize;
|
nickjillings@1344
|
763 if (this.popup != null) {
|
nickjillings@1344
|
764 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
|
nickjillings@1344
|
765 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
|
nickjillings@1344
|
766 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1344
|
767 blank.style.width = window.innerWidth;
|
nickjillings@1344
|
768 blank.style.height = window.innerHeight;
|
nickjillings@1344
|
769 }
|
nickjillings@1318
|
770 };
|
nickjillings@1318
|
771 }
|
nickjillings@1318
|
772
|
nickjillings@1318
|
773 function advanceState()
|
nickjillings@1318
|
774 {
|
nickjillings@1318
|
775 // Just for complete clarity
|
nickjillings@1318
|
776 testState.advanceState();
|
nickjillings@1318
|
777 }
|
nickjillings@1318
|
778
|
nickjillings@1318
|
779 function stateMachine()
|
nickjillings@1318
|
780 {
|
nickjillings@1318
|
781 // Object prototype for tracking and managing the test state
|
nickjillings@1318
|
782 this.stateMap = [];
|
nickjillings@1324
|
783 this.preTestSurvey = null;
|
nickjillings@1324
|
784 this.postTestSurvey = null;
|
nickjillings@1318
|
785 this.stateIndex = null;
|
nickjillings@1324
|
786 this.currentStateMap = null;
|
nickjillings@1324
|
787 this.currentStatePosition = null;
|
nickjillings@1318
|
788 this.currentTestId = 0;
|
nickjillings@1318
|
789 this.stateResults = [];
|
nickjillings@1318
|
790 this.timerCallBackHolders = null;
|
nickjillings@1318
|
791 this.initialise = function(){
|
nickjillings@1324
|
792
|
nickjillings@1324
|
793 // Get the data from Specification
|
nickjillings@1324
|
794 var pageHolder = [];
|
nickjillings@1324
|
795 for (var page of specification.pages)
|
nickjillings@1324
|
796 {
|
nickjillings@1324
|
797 pageHolder.push(page);
|
nickjillings@1324
|
798 }
|
nickjillings@1324
|
799 if (specification.randomiseOrder)
|
nickjillings@1324
|
800 {
|
nickjillings@1324
|
801 pageHolder = randomiseOrder(pageHolder);
|
nickjillings@1324
|
802 }
|
nickjillings@1324
|
803 for (var i=0; i<pageHolder.length; i++)
|
nickjillings@1324
|
804 {
|
nickjillings@1324
|
805 pageHolder[i].presentedId = i;
|
nickjillings@1324
|
806 }
|
nickjillings@1324
|
807 for (var i=0; i<specification.pages.length; i++)
|
nickjillings@1324
|
808 {
|
nickjillings@1324
|
809 if (specification.testPages < i && specification.testPages != 0) {break;}
|
nickjillings@1324
|
810 this.stateMap.push(pageHolder[i]);
|
nickjillings@1324
|
811
|
nickjillings@1324
|
812 }
|
nickjillings@1324
|
813 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;}
|
nickjillings@1324
|
814 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;}
|
nickjillings@1324
|
815
|
nickjillings@1318
|
816 if (this.stateMap.length > 0) {
|
nickjillings@1318
|
817 if(this.stateIndex != null) {
|
nickjillings@1318
|
818 console.log('NOTE - State already initialise');
|
nickjillings@1318
|
819 }
|
nickjillings@1318
|
820 this.stateIndex = -1;
|
nickjillings@1318
|
821 var that = this;
|
nickjillings@1318
|
822 var aH_pId = 0;
|
nickjillings@1318
|
823 for (var id=0; id<this.stateMap.length; id++){
|
nickjillings@1318
|
824 var name = this.stateMap[id].type;
|
nickjillings@1318
|
825 var obj = document.createElement(name);
|
nickjillings@1318
|
826 if (name == 'audioHolder') {
|
nickjillings@1318
|
827 obj.id = this.stateMap[id].id;
|
nickjillings@1318
|
828 obj.setAttribute('presentedid',aH_pId);
|
nickjillings@1318
|
829 aH_pId+=1;
|
nickjillings@1318
|
830 }
|
nickjillings@1318
|
831 this.stateResults.push(obj);
|
nickjillings@1318
|
832 }
|
nickjillings@1318
|
833 } else {
|
nickjillings@1318
|
834 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
|
nickjillings@1318
|
835 }
|
nickjillings@1318
|
836 };
|
nickjillings@1318
|
837 this.advanceState = function(){
|
nickjillings@1318
|
838 if (this.stateIndex == null) {
|
nickjillings@1318
|
839 this.initialise();
|
nickjillings@1318
|
840 }
|
nickjillings@1318
|
841 if (this.stateIndex == -1) {
|
nickjillings@1342
|
842 this.stateIndex++;
|
nickjillings@1318
|
843 console.log('Starting test...');
|
nickjillings@1324
|
844 if (this.preTestSurvey != null)
|
nickjillings@1324
|
845 {
|
nickjillings@1324
|
846 popup.initState(this.preTestSurvey,storage.globalPreTest);
|
nickjillings@1342
|
847 } else {
|
nickjillings@1342
|
848 this.advanceState();
|
nickjillings@1318
|
849 }
|
nickjillings@1324
|
850 } else if (this.stateIndex == this.stateMap.length)
|
nickjillings@1324
|
851 {
|
nickjillings@1324
|
852 // All test pages complete, post test
|
nickjillings@1324
|
853 console.log('Ending test ...');
|
nickjillings@1324
|
854 this.stateIndex++;
|
nickjillings@1324
|
855 if (this.postTestSurvey == null) {
|
nickjillings@1324
|
856 this.advanceState();
|
nickjillings@1318
|
857 } else {
|
nickjillings@1324
|
858 popup.initState(this.postTestSurvey,storage.globalPostTest);
|
nickjillings@1324
|
859 }
|
nickjillings@1324
|
860 } else if (this.stateIndex > this.stateMap.length)
|
nickjillings@1324
|
861 {
|
nickjillings@1324
|
862 createProjectSave(specification.projectReturn);
|
nickjillings@1324
|
863 }
|
nickjillings@1324
|
864 else
|
nickjillings@1324
|
865 {
|
nickjillings@1324
|
866 if (this.currentStateMap == null)
|
nickjillings@1324
|
867 {
|
nickjillings@1318
|
868 this.currentStateMap = this.stateMap[this.stateIndex];
|
nickjillings@1334
|
869 if (this.currentStateMap.randomiseOrder)
|
nickjillings@1334
|
870 {
|
nickjillings@1334
|
871 this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements);
|
nickjillings@1334
|
872 }
|
nickjillings@1324
|
873 storage.createTestPageStore(this.currentStateMap);
|
nickjillings@1324
|
874 if (this.currentStateMap.preTest != null)
|
nickjillings@1324
|
875 {
|
nickjillings@1324
|
876 this.currentStatePosition = 'pre';
|
nickjillings@1324
|
877 popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest);
|
nickjillings@1318
|
878 } else {
|
nickjillings@1324
|
879 this.currentStatePosition = 'test';
|
nickjillings@1324
|
880 }
|
nickjillings@1324
|
881 interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]);
|
nickjillings@1324
|
882 return;
|
nickjillings@1324
|
883 }
|
nickjillings@1324
|
884 switch(this.currentStatePosition)
|
nickjillings@1324
|
885 {
|
nickjillings@1324
|
886 case 'pre':
|
nickjillings@1324
|
887 this.currentStatePosition = 'test';
|
nickjillings@1324
|
888 break;
|
nickjillings@1324
|
889 case 'test':
|
nickjillings@1324
|
890 this.currentStatePosition = 'post';
|
nickjillings@1324
|
891 // Save the data
|
nickjillings@1324
|
892 this.testPageCompleted();
|
nickjillings@1324
|
893 if (this.currentStateMap.postTest == null)
|
nickjillings@1324
|
894 {
|
nickjillings@1318
|
895 this.advanceState();
|
nickjillings@1324
|
896 return;
|
nickjillings@1324
|
897 } else {
|
nickjillings@1324
|
898 popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest);
|
nickjillings@1318
|
899 }
|
nickjillings@1324
|
900 break;
|
nickjillings@1324
|
901 case 'post':
|
nickjillings@1324
|
902 this.stateIndex++;
|
nickjillings@1324
|
903 this.currentStateMap = null;
|
nickjillings@1324
|
904 this.advanceState();
|
nickjillings@1324
|
905 break;
|
nickjillings@1324
|
906 };
|
nickjillings@1318
|
907 }
|
nickjillings@1318
|
908 };
|
nickjillings@1318
|
909
|
nickjillings@1324
|
910 this.testPageCompleted = function() {
|
nickjillings@1318
|
911 // Function called each time a test page has been completed
|
nickjillings@1324
|
912 var storePoint = storage.testPages[this.stateIndex];
|
nickjillings@1324
|
913 // First get the test metric
|
nickjillings@1324
|
914
|
nickjillings@1324
|
915 var metric = storePoint.XMLDOM.getElementsByTagName('metric')[0];
|
nickjillings@1318
|
916 if (audioEngineContext.metric.enableTestTimer)
|
nickjillings@1318
|
917 {
|
nickjillings@1324
|
918 var testTime = storePoint.parent.document.createElement('metricresult');
|
nickjillings@1318
|
919 testTime.id = 'testTime';
|
nickjillings@1318
|
920 testTime.textContent = audioEngineContext.timer.testDuration;
|
nickjillings@1318
|
921 metric.appendChild(testTime);
|
nickjillings@1318
|
922 }
|
nickjillings@1324
|
923
|
nickjillings@1318
|
924 var audioObjects = audioEngineContext.audioObjects;
|
nickjillings@1324
|
925 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
926 {
|
nickjillings@1324
|
927 ao.exportXMLDOM();
|
nickjillings@1318
|
928 }
|
nickjillings@1324
|
929 for (var element of interfaceContext.commentQuestions)
|
nickjillings@1324
|
930 {
|
nickjillings@1324
|
931 element.exportXMLDOM(storePoint);
|
nickjillings@1324
|
932 }
|
nickjillings@1324
|
933 pageXMLSave(storePoint.XMLDOM, this.currentStateMap);
|
nickjillings@1318
|
934 };
|
nickjillings@1318
|
935 }
|
nickjillings@1318
|
936
|
nickjillings@1318
|
937 function AudioEngine(specification) {
|
nickjillings@1318
|
938
|
nickjillings@1318
|
939 // Create two output paths, the main outputGain and fooGain.
|
nickjillings@1318
|
940 // Output gain is default to 1 and any items for playback route here
|
nickjillings@1318
|
941 // Foo gain is used for analysis to ensure paths get processed, but are not heard
|
nickjillings@1318
|
942 // because web audio will optimise and any route which does not go to the destination gets ignored.
|
nickjillings@1318
|
943 this.outputGain = audioContext.createGain();
|
nickjillings@1318
|
944 this.fooGain = audioContext.createGain();
|
nickjillings@1318
|
945 this.fooGain.gain = 0;
|
nickjillings@1318
|
946
|
nickjillings@1318
|
947 // Use this to detect playback state: 0 - stopped, 1 - playing
|
nickjillings@1318
|
948 this.status = 0;
|
nickjillings@1318
|
949
|
nickjillings@1318
|
950 // Connect both gains to output
|
nickjillings@1318
|
951 this.outputGain.connect(audioContext.destination);
|
nickjillings@1318
|
952 this.fooGain.connect(audioContext.destination);
|
nickjillings@1318
|
953
|
nickjillings@1318
|
954 // Create the timer Object
|
nickjillings@1318
|
955 this.timer = new timer();
|
nickjillings@1318
|
956 // Create session metrics
|
nickjillings@1318
|
957 this.metric = new sessionMetrics(this,specification);
|
nickjillings@1318
|
958
|
nickjillings@1318
|
959 this.loopPlayback = false;
|
nickjillings@1318
|
960
|
nickjillings@1324
|
961 this.pageStore = null;
|
nickjillings@1324
|
962
|
nickjillings@1318
|
963 // Create store for new audioObjects
|
nickjillings@1318
|
964 this.audioObjects = [];
|
nickjillings@1318
|
965
|
nickjillings@1318
|
966 this.buffers = [];
|
nickjillings@1318
|
967 this.bufferObj = function()
|
nickjillings@1318
|
968 {
|
nickjillings@1318
|
969 this.url = null;
|
nickjillings@1318
|
970 this.buffer = null;
|
nickjillings@1318
|
971 this.xmlRequest = new XMLHttpRequest();
|
nickjillings@1318
|
972 this.xmlRequest.parent = this;
|
nickjillings@1318
|
973 this.users = [];
|
nickjillings@1342
|
974 this.ready = function()
|
nickjillings@1342
|
975 {
|
nickjillings@1342
|
976 for (var i=0; i<this.users.length; i++)
|
nickjillings@1342
|
977 {
|
nickjillings@1342
|
978 this.users[i].state = 1;
|
nickjillings@1342
|
979 if (this.users[i].interfaceDOM != null)
|
nickjillings@1342
|
980 {
|
nickjillings@1342
|
981 this.users[i].bufferLoaded(this);
|
nickjillings@1342
|
982 }
|
nickjillings@1342
|
983 }
|
nickjillings@1342
|
984 };
|
nickjillings@1318
|
985 this.getMedia = function(url) {
|
nickjillings@1318
|
986 this.url = url;
|
nickjillings@1318
|
987 this.xmlRequest.open('GET',this.url,true);
|
nickjillings@1318
|
988 this.xmlRequest.responseType = 'arraybuffer';
|
nickjillings@1318
|
989
|
nickjillings@1318
|
990 var bufferObj = this;
|
nickjillings@1318
|
991
|
nickjillings@1318
|
992 // Create callback to decode the data asynchronously
|
nickjillings@1318
|
993 this.xmlRequest.onloadend = function() {
|
nickjillings@1353
|
994 // Use inbuilt WAVE decoder first
|
nickjillings@1353
|
995 var waveObj = new WAVE();
|
nickjillings@1353
|
996 if (waveObj.open(bufferObj.xmlRequest.response) == 0)
|
nickjillings@1353
|
997 {
|
nickjillings@1353
|
998 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
|
nickjillings@1353
|
999 for (var c=0; c<waveObj.num_channels; c++)
|
nickjillings@1353
|
1000 {
|
nickjillings@1353
|
1001 var buffer_ptr = bufferObj.buffer.getChannelData(c);
|
nickjillings@1353
|
1002 for (var n=0; n<waveObj.num_samples; n++)
|
nickjillings@1353
|
1003 {
|
nickjillings@1353
|
1004 buffer_ptr[n] = waveObj.decoded_data[c][n];
|
nickjillings@1353
|
1005 }
|
nickjillings@1353
|
1006 }
|
nickjillings@1353
|
1007 delete waveObj;
|
nickjillings@1353
|
1008 } else {
|
nickjillings@1353
|
1009 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
|
nickjillings@1353
|
1010 bufferObj.buffer = decodedData;
|
nickjillings@1353
|
1011 }, function(e){
|
nickjillings@1353
|
1012 // Should only be called if there was an error, but sometimes gets called continuously
|
nickjillings@1353
|
1013 // Check here if the error is genuine
|
nickjillings@1353
|
1014 if (bufferObj.xmlRequest.response == undefined) {
|
nickjillings@1353
|
1015 // Genuine error
|
nickjillings@1353
|
1016 console.log('FATAL - Error loading buffer on '+audioObj.id);
|
nickjillings@1353
|
1017 if (request.status == 404)
|
nickjillings@1353
|
1018 {
|
nickjillings@1353
|
1019 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
|
nickjillings@1353
|
1020 console.log('URL: '+audioObj.url);
|
nickjillings@1353
|
1021 errorSessionDump('Fragment '+audioObj.id+' 404 error');
|
nickjillings@1353
|
1022 }
|
nickjillings@1353
|
1023 }
|
nickjillings@1353
|
1024 });
|
nickjillings@1353
|
1025 }
|
nickjillings@1353
|
1026 if (bufferObj.buffer != undefined)
|
nickjillings@1353
|
1027 {
|
nickjillings@1353
|
1028 calculateLoudness(bufferObj,"I");
|
nickjillings@1353
|
1029 }
|
nickjillings@1318
|
1030 };
|
nickjillings@1318
|
1031 this.progress = 0;
|
nickjillings@1318
|
1032 this.progressCallback = function(event){
|
nickjillings@1318
|
1033 if (event.lengthComputable)
|
nickjillings@1318
|
1034 {
|
nickjillings@1318
|
1035 this.parent.progress = event.loaded / event.total;
|
nickjillings@1318
|
1036 for (var i=0; i<this.parent.users.length; i++)
|
nickjillings@1318
|
1037 {
|
nickjillings@1318
|
1038 if(this.parent.users[i].interfaceDOM != null)
|
nickjillings@1318
|
1039 {
|
nickjillings@1318
|
1040 if (typeof this.parent.users[i].interfaceDOM.updateLoading === "function")
|
nickjillings@1318
|
1041 {
|
nickjillings@1318
|
1042 this.parent.users[i].interfaceDOM.updateLoading(this.parent.progress*100);
|
nickjillings@1318
|
1043 }
|
nickjillings@1318
|
1044 }
|
nickjillings@1318
|
1045 }
|
nickjillings@1318
|
1046 }
|
nickjillings@1318
|
1047 };
|
nickjillings@1318
|
1048 this.xmlRequest.addEventListener("progress", this.progressCallback);
|
nickjillings@1318
|
1049 this.xmlRequest.send();
|
nickjillings@1318
|
1050 };
|
nickjillings@1318
|
1051 };
|
nickjillings@1318
|
1052
|
nickjillings@1318
|
1053 this.play = function(id) {
|
nickjillings@1318
|
1054 // Start the timer and set the audioEngine state to playing (1)
|
nickjillings@1318
|
1055 if (this.status == 0 && this.loopPlayback) {
|
nickjillings@1318
|
1056 // Check if all audioObjects are ready
|
nickjillings@1318
|
1057 if(this.checkAllReady())
|
nickjillings@1318
|
1058 {
|
nickjillings@1318
|
1059 this.status = 1;
|
nickjillings@1318
|
1060 this.setSynchronousLoop();
|
nickjillings@1318
|
1061 }
|
nickjillings@1318
|
1062 }
|
nickjillings@1318
|
1063 else
|
nickjillings@1318
|
1064 {
|
nickjillings@1318
|
1065 this.status = 1;
|
nickjillings@1318
|
1066 }
|
nickjillings@1318
|
1067 if (this.status== 1) {
|
nickjillings@1318
|
1068 this.timer.startTest();
|
nickjillings@1318
|
1069 if (id == undefined) {
|
nickjillings@1318
|
1070 id = -1;
|
nickjillings@1318
|
1071 console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
|
nickjillings@1318
|
1072 return;
|
nickjillings@1318
|
1073 } else {
|
nickjillings@1318
|
1074 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
|
nickjillings@1318
|
1075 }
|
nickjillings@1318
|
1076 if (this.loopPlayback) {
|
nickjillings@1318
|
1077 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1078 {
|
nickjillings@1318
|
1079 this.audioObjects[i].play(this.timer.getTestTime()+1);
|
nickjillings@1318
|
1080 if (id == i) {
|
nickjillings@1318
|
1081 this.audioObjects[i].loopStart();
|
nickjillings@1318
|
1082 } else {
|
nickjillings@1318
|
1083 this.audioObjects[i].loopStop();
|
nickjillings@1318
|
1084 }
|
nickjillings@1318
|
1085 }
|
nickjillings@1318
|
1086 } else {
|
nickjillings@1318
|
1087 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1088 {
|
nickjillings@1318
|
1089 if (i != id) {
|
nickjillings@1318
|
1090 this.audioObjects[i].outputGain.gain.value = 0.0;
|
nickjillings@1318
|
1091 this.audioObjects[i].stop();
|
nickjillings@1318
|
1092 } else if (i == id) {
|
nickjillings@1324
|
1093 this.audioObjects[id].outputGain.gain.value = this.audioObjects[id].onplayGain;
|
nickjillings@1318
|
1094 this.audioObjects[id].play(audioContext.currentTime+0.01);
|
nickjillings@1318
|
1095 }
|
nickjillings@1318
|
1096 }
|
nickjillings@1318
|
1097 }
|
nickjillings@1318
|
1098 interfaceContext.playhead.start();
|
nickjillings@1318
|
1099 }
|
nickjillings@1318
|
1100 };
|
nickjillings@1318
|
1101
|
nickjillings@1318
|
1102 this.stop = function() {
|
nickjillings@1318
|
1103 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1)
|
nickjillings@1318
|
1104 if (this.status == 1) {
|
nickjillings@1318
|
1105 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1106 {
|
nickjillings@1318
|
1107 this.audioObjects[i].stop();
|
nickjillings@1318
|
1108 }
|
nickjillings@1318
|
1109 interfaceContext.playhead.stop();
|
nickjillings@1318
|
1110 this.status = 0;
|
nickjillings@1318
|
1111 }
|
nickjillings@1318
|
1112 };
|
nickjillings@1318
|
1113
|
nickjillings@1318
|
1114 this.newTrack = function(element) {
|
nickjillings@1318
|
1115 // Pull data from given URL into new audio buffer
|
nickjillings@1318
|
1116 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
|
nickjillings@1318
|
1117
|
nickjillings@1318
|
1118 // Create the audioObject with ID of the new track length;
|
nickjillings@1318
|
1119 audioObjectId = this.audioObjects.length;
|
nickjillings@1318
|
1120 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
|
nickjillings@1318
|
1121
|
nickjillings@1318
|
1122 // Check if audioObject buffer is currently stored by full URL
|
nickjillings@1324
|
1123 var URL = testState.currentStateMap.hostURL + element.url;
|
nickjillings@1318
|
1124 var buffer = null;
|
nickjillings@1318
|
1125 for (var i=0; i<this.buffers.length; i++)
|
nickjillings@1318
|
1126 {
|
nickjillings@1318
|
1127 if (URL == this.buffers[i].url)
|
nickjillings@1318
|
1128 {
|
nickjillings@1318
|
1129 buffer = this.buffers[i];
|
nickjillings@1318
|
1130 break;
|
nickjillings@1318
|
1131 }
|
nickjillings@1318
|
1132 }
|
nickjillings@1318
|
1133 if (buffer == null)
|
nickjillings@1318
|
1134 {
|
nickjillings@1318
|
1135 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL);
|
nickjillings@1318
|
1136 buffer = new this.bufferObj();
|
nickjillings@1318
|
1137 buffer.getMedia(URL);
|
nickjillings@1318
|
1138 this.buffers.push(buffer);
|
nickjillings@1318
|
1139 }
|
nickjillings@1318
|
1140 this.audioObjects[audioObjectId].specification = element;
|
nickjillings@1318
|
1141 this.audioObjects[audioObjectId].url = URL;
|
nickjillings@1318
|
1142 buffer.users.push(this.audioObjects[audioObjectId]);
|
nickjillings@1324
|
1143 // Obtain store node
|
nickjillings@1324
|
1144 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement');
|
nickjillings@1324
|
1145 for (var i=0; i<aeNodes.length; i++)
|
nickjillings@1324
|
1146 {
|
nickjillings@1324
|
1147 if(aeNodes[i].id == element.id)
|
nickjillings@1324
|
1148 {
|
nickjillings@1324
|
1149 this.audioObjects[audioObjectId].storeDOM = aeNodes[i];
|
nickjillings@1324
|
1150 break;
|
nickjillings@1324
|
1151 }
|
nickjillings@1324
|
1152 }
|
nickjillings@1318
|
1153 if (buffer.buffer != null)
|
nickjillings@1318
|
1154 {
|
nickjillings@1318
|
1155 this.audioObjects[audioObjectId].bufferLoaded(buffer);
|
nickjillings@1318
|
1156 }
|
nickjillings@1318
|
1157 return this.audioObjects[audioObjectId];
|
nickjillings@1318
|
1158 };
|
nickjillings@1318
|
1159
|
nickjillings@1324
|
1160 this.newTestPage = function(store) {
|
nickjillings@1324
|
1161 this.pageStore = store;
|
nickjillings@1318
|
1162 this.state = 0;
|
nickjillings@1318
|
1163 this.audioObjectsReady = false;
|
nickjillings@1318
|
1164 this.metric.reset();
|
nickjillings@1318
|
1165 for (var i=0; i < this.buffers.length; i++)
|
nickjillings@1318
|
1166 {
|
nickjillings@1318
|
1167 this.buffers[i].users = [];
|
nickjillings@1318
|
1168 }
|
nickjillings@1318
|
1169 this.audioObjects = [];
|
nickjillings@1318
|
1170 };
|
nickjillings@1318
|
1171
|
nickjillings@1318
|
1172 this.checkAllPlayed = function() {
|
nickjillings@1318
|
1173 arr = [];
|
nickjillings@1318
|
1174 for (var id=0; id<this.audioObjects.length; id++) {
|
nickjillings@1318
|
1175 if (this.audioObjects[id].metric.wasListenedTo == false) {
|
nickjillings@1318
|
1176 arr.push(this.audioObjects[id].id);
|
nickjillings@1318
|
1177 }
|
nickjillings@1318
|
1178 }
|
nickjillings@1318
|
1179 return arr;
|
nickjillings@1318
|
1180 };
|
nickjillings@1318
|
1181
|
nickjillings@1318
|
1182 this.checkAllReady = function() {
|
nickjillings@1318
|
1183 var ready = true;
|
nickjillings@1318
|
1184 for (var i=0; i<this.audioObjects.length; i++) {
|
nickjillings@1318
|
1185 if (this.audioObjects[i].state == 0) {
|
nickjillings@1318
|
1186 // Track not ready
|
nickjillings@1318
|
1187 console.log('WAIT -- audioObject '+i+' not ready yet!');
|
nickjillings@1318
|
1188 ready = false;
|
nickjillings@1318
|
1189 };
|
nickjillings@1318
|
1190 }
|
nickjillings@1318
|
1191 return ready;
|
nickjillings@1318
|
1192 };
|
nickjillings@1318
|
1193
|
nickjillings@1318
|
1194 this.setSynchronousLoop = function() {
|
nickjillings@1318
|
1195 // Pads the signals so they are all exactly the same length
|
nickjillings@1318
|
1196 var length = 0;
|
nickjillings@1318
|
1197 var maxId;
|
nickjillings@1318
|
1198 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1199 {
|
nickjillings@1318
|
1200 if (length < this.audioObjects[i].buffer.buffer.length)
|
nickjillings@1318
|
1201 {
|
nickjillings@1318
|
1202 length = this.audioObjects[i].buffer.buffer.length;
|
nickjillings@1318
|
1203 maxId = i;
|
nickjillings@1318
|
1204 }
|
nickjillings@1318
|
1205 }
|
nickjillings@1318
|
1206 // Extract the audio and zero-pad
|
nickjillings@1318
|
1207 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1208 {
|
nickjillings@1318
|
1209 var orig = this.audioObjects[i].buffer.buffer;
|
nickjillings@1318
|
1210 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate);
|
nickjillings@1318
|
1211 for (var c=0; c<orig.numberOfChannels; c++)
|
nickjillings@1318
|
1212 {
|
nickjillings@1318
|
1213 var inData = hold.getChannelData(c);
|
nickjillings@1318
|
1214 var outData = orig.getChannelData(c);
|
nickjillings@1318
|
1215 for (var n=0; n<orig.length; n++)
|
nickjillings@1318
|
1216 {inData[n] = outData[n];}
|
nickjillings@1318
|
1217 }
|
nickjillings@1320
|
1218 hold.playbackGain = orig.playbackGain;
|
nickjillings@1318
|
1219 hold.lufs = orig.lufs;
|
nickjillings@1318
|
1220 this.audioObjects[i].buffer.buffer = hold;
|
nickjillings@1318
|
1221 }
|
nickjillings@1318
|
1222 };
|
nickjillings@1318
|
1223
|
nickjillings@1318
|
1224 }
|
nickjillings@1318
|
1225
|
nickjillings@1318
|
1226 function audioObject(id) {
|
nickjillings@1318
|
1227 // The main buffer object with common control nodes to the AudioEngine
|
nickjillings@1318
|
1228
|
nickjillings@1318
|
1229 this.specification;
|
nickjillings@1318
|
1230 this.id = id;
|
nickjillings@1318
|
1231 this.state = 0; // 0 - no data, 1 - ready
|
nickjillings@1318
|
1232 this.url = null; // Hold the URL given for the output back to the results.
|
nickjillings@1318
|
1233 this.metric = new metricTracker(this);
|
nickjillings@1324
|
1234 this.storeDOM = null;
|
nickjillings@1318
|
1235
|
nickjillings@1318
|
1236 // Bindings for GUI
|
nickjillings@1318
|
1237 this.interfaceDOM = null;
|
nickjillings@1318
|
1238 this.commentDOM = null;
|
nickjillings@1318
|
1239
|
nickjillings@1318
|
1240 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
|
nickjillings@1318
|
1241 this.bufferNode = undefined;
|
nickjillings@1318
|
1242 this.outputGain = audioContext.createGain();
|
nickjillings@1318
|
1243
|
nickjillings@1318
|
1244 // Default output gain to be zero
|
nickjillings@1318
|
1245 this.outputGain.gain.value = 0.0;
|
nickjillings@1324
|
1246 this.onplayGain = 1.0;
|
nickjillings@1318
|
1247
|
nickjillings@1318
|
1248 // Connect buffer to the audio graph
|
nickjillings@1318
|
1249 this.outputGain.connect(audioEngineContext.outputGain);
|
nickjillings@1318
|
1250
|
nickjillings@1318
|
1251 // the audiobuffer is not designed for multi-start playback
|
nickjillings@1318
|
1252 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
|
nickjillings@1318
|
1253 this.buffer;
|
nickjillings@1318
|
1254
|
nickjillings@1318
|
1255 this.bufferLoaded = function(callee)
|
nickjillings@1318
|
1256 {
|
nickjillings@1318
|
1257 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the
|
nickjillings@1318
|
1258 // audioObject and trigger the interfaceDOM.enable() function for user feedback
|
nickjillings@1318
|
1259 if (audioEngineContext.loopPlayback){
|
nickjillings@1318
|
1260 // First copy the buffer into this.buffer
|
nickjillings@1318
|
1261 this.buffer = new audioEngineContext.bufferObj();
|
nickjillings@1318
|
1262 this.buffer.url = callee.url;
|
nickjillings@1318
|
1263 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate);
|
nickjillings@1318
|
1264 for (var c=0; c<callee.buffer.numberOfChannels; c++)
|
nickjillings@1318
|
1265 {
|
nickjillings@1318
|
1266 var src = callee.buffer.getChannelData(c);
|
nickjillings@1318
|
1267 var dst = this.buffer.buffer.getChannelData(c);
|
nickjillings@1318
|
1268 for (var n=0; n<src.length; n++)
|
nickjillings@1318
|
1269 {
|
nickjillings@1318
|
1270 dst[n] = src[n];
|
nickjillings@1318
|
1271 }
|
nickjillings@1318
|
1272 }
|
nickjillings@1318
|
1273 } else {
|
nickjillings@1318
|
1274 this.buffer = callee;
|
nickjillings@1318
|
1275 }
|
nickjillings@1318
|
1276 this.state = 1;
|
nickjillings@1320
|
1277 this.buffer.buffer.playbackGain = callee.buffer.playbackGain;
|
nickjillings@1318
|
1278 this.buffer.buffer.lufs = callee.buffer.lufs;
|
nickjillings@1348
|
1279 var targetLUFS = this.specification.parent.loudness || specification.loudness;
|
nickjillings@1318
|
1280 if (typeof targetLUFS === "number")
|
nickjillings@1318
|
1281 {
|
nickjillings@1320
|
1282 this.buffer.buffer.playbackGain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs);
|
nickjillings@1318
|
1283 } else {
|
nickjillings@1320
|
1284 this.buffer.buffer.playbackGain = 1.0;
|
nickjillings@1318
|
1285 }
|
nickjillings@1318
|
1286 if (this.interfaceDOM != null) {
|
nickjillings@1318
|
1287 this.interfaceDOM.enable();
|
nickjillings@1318
|
1288 }
|
nickjillings@1324
|
1289 this.onplayGain = decibelToLinear(this.specification.gain)*this.buffer.buffer.playbackGain;
|
nickjillings@1324
|
1290 this.storeDOM.setAttribute('playGain',linearToDecibel(this.onplayGain));
|
nickjillings@1318
|
1291 };
|
nickjillings@1325
|
1292
|
nickjillings@1325
|
1293 this.bindInterface = function(interfaceObject)
|
nickjillings@1325
|
1294 {
|
nickjillings@1325
|
1295 this.interfaceDOM = interfaceObject;
|
nickjillings@1325
|
1296 this.metric.initialise(interfaceObject.getValue());
|
nickjillings@1325
|
1297 if (this.state == 1)
|
nickjillings@1325
|
1298 {
|
nickjillings@1325
|
1299 this.interfaceDOM.enable();
|
nickjillings@1325
|
1300 }
|
nickjillings@1338
|
1301 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId());
|
nickjillings@1325
|
1302 };
|
nickjillings@1318
|
1303
|
nickjillings@1318
|
1304 this.loopStart = function() {
|
nickjillings@1324
|
1305 this.outputGain.gain.value = this.onplayGain;
|
nickjillings@1318
|
1306 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1318
|
1307 };
|
nickjillings@1318
|
1308
|
nickjillings@1318
|
1309 this.loopStop = function() {
|
nickjillings@1318
|
1310 if (this.outputGain.gain.value != 0.0) {
|
nickjillings@1318
|
1311 this.outputGain.gain.value = 0.0;
|
nickjillings@1318
|
1312 this.metric.stopListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1318
|
1313 }
|
nickjillings@1318
|
1314 };
|
nickjillings@1318
|
1315
|
nickjillings@1318
|
1316 this.play = function(startTime) {
|
nickjillings@1318
|
1317 if (this.bufferNode == undefined && this.buffer.buffer != undefined) {
|
nickjillings@1318
|
1318 this.bufferNode = audioContext.createBufferSource();
|
nickjillings@1318
|
1319 this.bufferNode.owner = this;
|
nickjillings@1318
|
1320 this.bufferNode.connect(this.outputGain);
|
nickjillings@1318
|
1321 this.bufferNode.buffer = this.buffer.buffer;
|
nickjillings@1318
|
1322 this.bufferNode.loop = audioEngineContext.loopPlayback;
|
nickjillings@1318
|
1323 this.bufferNode.onended = function(event) {
|
nickjillings@1318
|
1324 // Safari does not like using 'this' to reference the calling object!
|
nickjillings@1318
|
1325 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
|
nickjillings@1318
|
1326 event.currentTarget.owner.stop();
|
nickjillings@1318
|
1327 };
|
nickjillings@1318
|
1328 if (this.bufferNode.loop == false) {
|
nickjillings@1318
|
1329 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1318
|
1330 }
|
nickjillings@1318
|
1331 this.bufferNode.start(startTime);
|
nickjillings@1318
|
1332 }
|
nickjillings@1318
|
1333 };
|
nickjillings@1318
|
1334
|
nickjillings@1318
|
1335 this.stop = function() {
|
nickjillings@1318
|
1336 if (this.bufferNode != undefined)
|
nickjillings@1318
|
1337 {
|
nickjillings@1318
|
1338 this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition());
|
nickjillings@1318
|
1339 this.bufferNode.stop(0);
|
nickjillings@1318
|
1340 this.bufferNode = undefined;
|
nickjillings@1318
|
1341 }
|
nickjillings@1318
|
1342 };
|
nickjillings@1318
|
1343
|
nickjillings@1318
|
1344 this.getCurrentPosition = function() {
|
nickjillings@1318
|
1345 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1318
|
1346 if (this.bufferNode != undefined) {
|
nickjillings@1318
|
1347 if (this.bufferNode.loop == true) {
|
nickjillings@1318
|
1348 if (audioEngineContext.status == 1) {
|
nickjillings@1318
|
1349 return (time-this.metric.listenStart)%this.buffer.buffer.duration;
|
nickjillings@1318
|
1350 } else {
|
nickjillings@1318
|
1351 return 0;
|
nickjillings@1318
|
1352 }
|
nickjillings@1318
|
1353 } else {
|
nickjillings@1318
|
1354 if (this.metric.listenHold) {
|
nickjillings@1318
|
1355 return time - this.metric.listenStart;
|
nickjillings@1318
|
1356 } else {
|
nickjillings@1318
|
1357 return 0;
|
nickjillings@1318
|
1358 }
|
nickjillings@1318
|
1359 }
|
nickjillings@1318
|
1360 } else {
|
nickjillings@1318
|
1361 return 0;
|
nickjillings@1318
|
1362 }
|
nickjillings@1318
|
1363 };
|
nickjillings@1318
|
1364
|
nickjillings@1318
|
1365 this.exportXMLDOM = function() {
|
nickjillings@1324
|
1366 var file = storage.document.createElement('file');
|
nickjillings@1318
|
1367 file.setAttribute('sampleRate',this.buffer.buffer.sampleRate);
|
nickjillings@1318
|
1368 file.setAttribute('channels',this.buffer.buffer.numberOfChannels);
|
nickjillings@1318
|
1369 file.setAttribute('sampleCount',this.buffer.buffer.length);
|
nickjillings@1318
|
1370 file.setAttribute('duration',this.buffer.buffer.duration);
|
nickjillings@1324
|
1371 this.storeDOM.appendChild(file);
|
nickjillings@1324
|
1372 if (this.specification.type != 'outside-reference') {
|
nickjillings@1318
|
1373 var interfaceXML = this.interfaceDOM.exportXMLDOM(this);
|
nickjillings@1340
|
1374 if (interfaceXML != null)
|
nickjillings@1340
|
1375 {
|
nickjillings@1340
|
1376 if (interfaceXML.length == undefined) {
|
nickjillings@1340
|
1377 this.storeDOM.appendChild(interfaceXML);
|
nickjillings@1340
|
1378 } else {
|
nickjillings@1340
|
1379 for (var i=0; i<interfaceXML.length; i++)
|
nickjillings@1340
|
1380 {
|
nickjillings@1340
|
1381 this.storeDOM.appendChild(interfaceXML[i]);
|
nickjillings@1340
|
1382 }
|
nickjillings@1318
|
1383 }
|
nickjillings@1318
|
1384 }
|
nickjillings@1330
|
1385 if (this.commentDOM != null) {
|
nickjillings@1330
|
1386 this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this));
|
nickjillings@1330
|
1387 }
|
nickjillings@1318
|
1388 }
|
nickjillings@1324
|
1389 var nodes = this.metric.exportXMLDOM();
|
nickjillings@1324
|
1390 var mroot = this.storeDOM.getElementsByTagName('metric')[0];
|
nickjillings@1324
|
1391 for (var i=0; i<nodes.length; i++)
|
nickjillings@1324
|
1392 {
|
nickjillings@1324
|
1393 mroot.appendChild(nodes[i]);
|
nickjillings@1324
|
1394 }
|
nickjillings@1318
|
1395 };
|
nickjillings@1318
|
1396 }
|
nickjillings@1318
|
1397
|
nickjillings@1318
|
1398 function timer()
|
nickjillings@1318
|
1399 {
|
nickjillings@1318
|
1400 /* Timer object used in audioEngine to keep track of session timings
|
nickjillings@1318
|
1401 * Uses the timer of the web audio API, so sample resolution
|
nickjillings@1318
|
1402 */
|
nickjillings@1318
|
1403 this.testStarted = false;
|
nickjillings@1318
|
1404 this.testStartTime = 0;
|
nickjillings@1318
|
1405 this.testDuration = 0;
|
nickjillings@1318
|
1406 this.minimumTestTime = 0; // No minimum test time
|
nickjillings@1318
|
1407 this.startTest = function()
|
nickjillings@1318
|
1408 {
|
nickjillings@1318
|
1409 if (this.testStarted == false)
|
nickjillings@1318
|
1410 {
|
nickjillings@1318
|
1411 this.testStartTime = audioContext.currentTime;
|
nickjillings@1318
|
1412 this.testStarted = true;
|
nickjillings@1318
|
1413 this.updateTestTime();
|
nickjillings@1318
|
1414 audioEngineContext.metric.initialiseTest();
|
nickjillings@1318
|
1415 }
|
nickjillings@1318
|
1416 };
|
nickjillings@1318
|
1417 this.stopTest = function()
|
nickjillings@1318
|
1418 {
|
nickjillings@1318
|
1419 if (this.testStarted)
|
nickjillings@1318
|
1420 {
|
nickjillings@1318
|
1421 this.testDuration = this.getTestTime();
|
nickjillings@1318
|
1422 this.testStarted = false;
|
nickjillings@1318
|
1423 } else {
|
nickjillings@1318
|
1424 console.log('ERR: Test tried to end before beginning');
|
nickjillings@1318
|
1425 }
|
nickjillings@1318
|
1426 };
|
nickjillings@1318
|
1427 this.updateTestTime = function()
|
nickjillings@1318
|
1428 {
|
nickjillings@1318
|
1429 if (this.testStarted)
|
nickjillings@1318
|
1430 {
|
nickjillings@1318
|
1431 this.testDuration = audioContext.currentTime - this.testStartTime;
|
nickjillings@1318
|
1432 }
|
nickjillings@1318
|
1433 };
|
nickjillings@1318
|
1434 this.getTestTime = function()
|
nickjillings@1318
|
1435 {
|
nickjillings@1318
|
1436 this.updateTestTime();
|
nickjillings@1318
|
1437 return this.testDuration;
|
nickjillings@1318
|
1438 };
|
nickjillings@1318
|
1439 }
|
nickjillings@1318
|
1440
|
nickjillings@1318
|
1441 function sessionMetrics(engine,specification)
|
nickjillings@1318
|
1442 {
|
nickjillings@1318
|
1443 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
|
nickjillings@1318
|
1444 */
|
nickjillings@1318
|
1445 this.engine = engine;
|
nickjillings@1318
|
1446 this.lastClicked = -1;
|
nickjillings@1318
|
1447 this.data = -1;
|
nickjillings@1318
|
1448 this.reset = function() {
|
nickjillings@1318
|
1449 this.lastClicked = -1;
|
nickjillings@1318
|
1450 this.data = -1;
|
nickjillings@1318
|
1451 };
|
nickjillings@1318
|
1452
|
nickjillings@1318
|
1453 this.enableElementInitialPosition = false;
|
nickjillings@1318
|
1454 this.enableElementListenTracker = false;
|
nickjillings@1318
|
1455 this.enableElementTimer = false;
|
nickjillings@1318
|
1456 this.enableElementTracker = false;
|
nickjillings@1318
|
1457 this.enableFlagListenedTo = false;
|
nickjillings@1318
|
1458 this.enableFlagMoved = false;
|
nickjillings@1318
|
1459 this.enableTestTimer = false;
|
nickjillings@1318
|
1460 // Obtain the metrics enabled
|
nickjillings@1324
|
1461 for (var i=0; i<specification.metrics.enabled.length; i++)
|
nickjillings@1318
|
1462 {
|
nickjillings@1324
|
1463 var node = specification.metrics.enabled[i];
|
nickjillings@1324
|
1464 switch(node)
|
nickjillings@1318
|
1465 {
|
nickjillings@1318
|
1466 case 'testTimer':
|
nickjillings@1318
|
1467 this.enableTestTimer = true;
|
nickjillings@1318
|
1468 break;
|
nickjillings@1318
|
1469 case 'elementTimer':
|
nickjillings@1318
|
1470 this.enableElementTimer = true;
|
nickjillings@1318
|
1471 break;
|
nickjillings@1318
|
1472 case 'elementTracker':
|
nickjillings@1318
|
1473 this.enableElementTracker = true;
|
nickjillings@1318
|
1474 break;
|
nickjillings@1318
|
1475 case 'elementListenTracker':
|
nickjillings@1318
|
1476 this.enableElementListenTracker = true;
|
nickjillings@1318
|
1477 break;
|
nickjillings@1318
|
1478 case 'elementInitialPosition':
|
nickjillings@1318
|
1479 this.enableElementInitialPosition = true;
|
nickjillings@1318
|
1480 break;
|
nickjillings@1318
|
1481 case 'elementFlagListenedTo':
|
nickjillings@1318
|
1482 this.enableFlagListenedTo = true;
|
nickjillings@1318
|
1483 break;
|
nickjillings@1318
|
1484 case 'elementFlagMoved':
|
nickjillings@1318
|
1485 this.enableFlagMoved = true;
|
nickjillings@1318
|
1486 break;
|
nickjillings@1318
|
1487 case 'elementFlagComments':
|
nickjillings@1318
|
1488 this.enableFlagComments = true;
|
nickjillings@1318
|
1489 break;
|
nickjillings@1318
|
1490 }
|
nickjillings@1318
|
1491 }
|
nickjillings@1318
|
1492 this.initialiseTest = function(){};
|
nickjillings@1318
|
1493 }
|
nickjillings@1318
|
1494
|
nickjillings@1318
|
1495 function metricTracker(caller)
|
nickjillings@1318
|
1496 {
|
nickjillings@1318
|
1497 /* Custom object to track and collect metric data
|
nickjillings@1318
|
1498 * Used only inside the audioObjects object.
|
nickjillings@1318
|
1499 */
|
nickjillings@1318
|
1500
|
nickjillings@1318
|
1501 this.listenedTimer = 0;
|
nickjillings@1318
|
1502 this.listenStart = 0;
|
nickjillings@1318
|
1503 this.listenHold = false;
|
nickjillings@1318
|
1504 this.initialPosition = -1;
|
nickjillings@1318
|
1505 this.movementTracker = [];
|
nickjillings@1318
|
1506 this.listenTracker =[];
|
nickjillings@1318
|
1507 this.wasListenedTo = false;
|
nickjillings@1318
|
1508 this.wasMoved = false;
|
nickjillings@1318
|
1509 this.hasComments = false;
|
nickjillings@1318
|
1510 this.parent = caller;
|
nickjillings@1318
|
1511
|
nickjillings@1324
|
1512 this.initialise = function(position)
|
nickjillings@1318
|
1513 {
|
nickjillings@1318
|
1514 if (this.initialPosition == -1) {
|
nickjillings@1318
|
1515 this.initialPosition = position;
|
nickjillings@1325
|
1516 this.moved(0,position);
|
nickjillings@1318
|
1517 }
|
nickjillings@1318
|
1518 };
|
nickjillings@1318
|
1519
|
nickjillings@1318
|
1520 this.moved = function(time,position)
|
nickjillings@1318
|
1521 {
|
nickjillings@1325
|
1522 if (time > 0) {this.wasMoved = true;}
|
nickjillings@1318
|
1523 this.movementTracker[this.movementTracker.length] = [time, position];
|
nickjillings@1318
|
1524 };
|
nickjillings@1318
|
1525
|
nickjillings@1318
|
1526 this.startListening = function(time)
|
nickjillings@1318
|
1527 {
|
nickjillings@1318
|
1528 if (this.listenHold == false)
|
nickjillings@1318
|
1529 {
|
nickjillings@1318
|
1530 this.wasListenedTo = true;
|
nickjillings@1318
|
1531 this.listenStart = time;
|
nickjillings@1318
|
1532 this.listenHold = true;
|
nickjillings@1318
|
1533
|
nickjillings@1318
|
1534 var evnt = document.createElement('event');
|
nickjillings@1318
|
1535 var testTime = document.createElement('testTime');
|
nickjillings@1318
|
1536 testTime.setAttribute('start',time);
|
nickjillings@1318
|
1537 var bufferTime = document.createElement('bufferTime');
|
nickjillings@1318
|
1538 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
|
nickjillings@1318
|
1539 evnt.appendChild(testTime);
|
nickjillings@1318
|
1540 evnt.appendChild(bufferTime);
|
nickjillings@1318
|
1541 this.listenTracker.push(evnt);
|
nickjillings@1318
|
1542
|
nickjillings@1318
|
1543 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1318
|
1544 }
|
nickjillings@1318
|
1545 };
|
nickjillings@1318
|
1546
|
nickjillings@1318
|
1547 this.stopListening = function(time,bufferStopTime)
|
nickjillings@1318
|
1548 {
|
nickjillings@1318
|
1549 if (this.listenHold == true)
|
nickjillings@1318
|
1550 {
|
nickjillings@1318
|
1551 var diff = time - this.listenStart;
|
nickjillings@1318
|
1552 this.listenedTimer += (diff);
|
nickjillings@1318
|
1553 this.listenStart = 0;
|
nickjillings@1318
|
1554 this.listenHold = false;
|
nickjillings@1318
|
1555
|
nickjillings@1318
|
1556 var evnt = this.listenTracker[this.listenTracker.length-1];
|
nickjillings@1318
|
1557 var testTime = evnt.getElementsByTagName('testTime')[0];
|
nickjillings@1318
|
1558 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
|
nickjillings@1318
|
1559 testTime.setAttribute('stop',time);
|
nickjillings@1318
|
1560 if (bufferStopTime == undefined) {
|
nickjillings@1318
|
1561 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
|
nickjillings@1318
|
1562 } else {
|
nickjillings@1318
|
1563 bufferTime.setAttribute('stop',bufferStopTime);
|
nickjillings@1318
|
1564 }
|
nickjillings@1318
|
1565 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1318
|
1566 }
|
nickjillings@1318
|
1567 };
|
nickjillings@1318
|
1568
|
nickjillings@1318
|
1569 this.exportXMLDOM = function() {
|
nickjillings@1324
|
1570 var storeDOM = [];
|
nickjillings@1318
|
1571 if (audioEngineContext.metric.enableElementTimer) {
|
nickjillings@1324
|
1572 var mElementTimer = storage.document.createElement('metricresult');
|
nickjillings@1318
|
1573 mElementTimer.setAttribute('name','enableElementTimer');
|
nickjillings@1318
|
1574 mElementTimer.textContent = this.listenedTimer;
|
nickjillings@1324
|
1575 storeDOM.push(mElementTimer);
|
nickjillings@1318
|
1576 }
|
nickjillings@1318
|
1577 if (audioEngineContext.metric.enableElementTracker) {
|
nickjillings@1324
|
1578 var elementTrackerFull = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1579 elementTrackerFull.setAttribute('name','elementTrackerFull');
|
nickjillings@1318
|
1580 for (var k=0; k<this.movementTracker.length; k++)
|
nickjillings@1318
|
1581 {
|
nickjillings@1324
|
1582 var timePos = storage.document.createElement('timePos');
|
nickjillings@1318
|
1583 timePos.id = k;
|
nickjillings@1324
|
1584 var time = storage.document.createElement('time');
|
nickjillings@1318
|
1585 time.textContent = this.movementTracker[k][0];
|
nickjillings@1318
|
1586 var position = document.createElement('position');
|
nickjillings@1318
|
1587 position.textContent = this.movementTracker[k][1];
|
nickjillings@1318
|
1588 timePos.appendChild(time);
|
nickjillings@1318
|
1589 timePos.appendChild(position);
|
nickjillings@1318
|
1590 elementTrackerFull.appendChild(timePos);
|
nickjillings@1318
|
1591 }
|
nickjillings@1324
|
1592 storeDOM.push(elementTrackerFull);
|
nickjillings@1318
|
1593 }
|
nickjillings@1318
|
1594 if (audioEngineContext.metric.enableElementListenTracker) {
|
nickjillings@1324
|
1595 var elementListenTracker = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1596 elementListenTracker.setAttribute('name','elementListenTracker');
|
nickjillings@1318
|
1597 for (var k=0; k<this.listenTracker.length; k++) {
|
nickjillings@1318
|
1598 elementListenTracker.appendChild(this.listenTracker[k]);
|
nickjillings@1318
|
1599 }
|
nickjillings@1324
|
1600 storeDOM.push(elementListenTracker);
|
nickjillings@1318
|
1601 }
|
nickjillings@1318
|
1602 if (audioEngineContext.metric.enableElementInitialPosition) {
|
nickjillings@1324
|
1603 var elementInitial = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1604 elementInitial.setAttribute('name','elementInitialPosition');
|
nickjillings@1318
|
1605 elementInitial.textContent = this.initialPosition;
|
nickjillings@1324
|
1606 storeDOM.push(elementInitial);
|
nickjillings@1318
|
1607 }
|
nickjillings@1318
|
1608 if (audioEngineContext.metric.enableFlagListenedTo) {
|
nickjillings@1324
|
1609 var flagListenedTo = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1610 flagListenedTo.setAttribute('name','elementFlagListenedTo');
|
nickjillings@1318
|
1611 flagListenedTo.textContent = this.wasListenedTo;
|
nickjillings@1324
|
1612 storeDOM.push(flagListenedTo);
|
nickjillings@1318
|
1613 }
|
nickjillings@1318
|
1614 if (audioEngineContext.metric.enableFlagMoved) {
|
nickjillings@1324
|
1615 var flagMoved = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1616 flagMoved.setAttribute('name','elementFlagMoved');
|
nickjillings@1318
|
1617 flagMoved.textContent = this.wasMoved;
|
nickjillings@1324
|
1618 storeDOM.push(flagMoved);
|
nickjillings@1318
|
1619 }
|
nickjillings@1318
|
1620 if (audioEngineContext.metric.enableFlagComments) {
|
nickjillings@1324
|
1621 var flagComments = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1622 flagComments.setAttribute('name','elementFlagComments');
|
nickjillings@1318
|
1623 if (this.parent.commentDOM == null)
|
nickjillings@1318
|
1624 {flag.textContent = 'false';}
|
nickjillings@1318
|
1625 else if (this.parent.commentDOM.textContent.length == 0)
|
nickjillings@1318
|
1626 {flag.textContent = 'false';}
|
nickjillings@1318
|
1627 else
|
nickjillings@1318
|
1628 {flag.textContet = 'true';}
|
nickjillings@1324
|
1629 storeDOM.push(flagComments);
|
nickjillings@1318
|
1630 }
|
nickjillings@1324
|
1631 return storeDOM;
|
nickjillings@1318
|
1632 };
|
nickjillings@1318
|
1633 }
|
nickjillings@1318
|
1634
|
nickjillings@1318
|
1635 function randomiseOrder(input)
|
nickjillings@1318
|
1636 {
|
nickjillings@1318
|
1637 // This takes an array of information and randomises the order
|
nickjillings@1318
|
1638 var N = input.length;
|
nickjillings@1318
|
1639
|
nickjillings@1318
|
1640 var inputSequence = []; // For safety purposes: keep track of randomisation
|
nickjillings@1318
|
1641 for (var counter = 0; counter < N; ++counter)
|
nickjillings@1318
|
1642 inputSequence.push(counter) // Fill array
|
nickjillings@1318
|
1643 var inputSequenceClone = inputSequence.slice(0);
|
nickjillings@1318
|
1644
|
nickjillings@1318
|
1645 var holdArr = [];
|
nickjillings@1318
|
1646 var outputSequence = [];
|
nickjillings@1318
|
1647 for (var n=0; n<N; n++)
|
nickjillings@1318
|
1648 {
|
nickjillings@1318
|
1649 // First pick a random number
|
nickjillings@1318
|
1650 var r = Math.random();
|
nickjillings@1318
|
1651 // Multiply and floor by the number of elements left
|
nickjillings@1318
|
1652 r = Math.floor(r*input.length);
|
nickjillings@1318
|
1653 // Pick out that element and delete from the array
|
nickjillings@1318
|
1654 holdArr.push(input.splice(r,1)[0]);
|
nickjillings@1318
|
1655 // Do the same with sequence
|
nickjillings@1318
|
1656 outputSequence.push(inputSequence.splice(r,1)[0]);
|
nickjillings@1318
|
1657 }
|
nickjillings@1318
|
1658 console.log(inputSequenceClone.toString()); // print original array to console
|
nickjillings@1318
|
1659 console.log(outputSequence.toString()); // print randomised array to console
|
nickjillings@1318
|
1660 return holdArr;
|
nickjillings@1318
|
1661 }
|
nickjillings@1318
|
1662
|
nickjillings@1318
|
1663 function returnDateNode()
|
nickjillings@1318
|
1664 {
|
nickjillings@1318
|
1665 // Create an XML Node for the Date and Time a test was conducted
|
nickjillings@1318
|
1666 // Structure is
|
nickjillings@1318
|
1667 // <datetime>
|
nickjillings@1318
|
1668 // <date year="##" month="##" day="##">DD/MM/YY</date>
|
nickjillings@1318
|
1669 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
|
nickjillings@1318
|
1670 // </datetime>
|
nickjillings@1318
|
1671 var dateTime = new Date();
|
nickjillings@1318
|
1672 var year = document.createAttribute('year');
|
nickjillings@1318
|
1673 var month = document.createAttribute('month');
|
nickjillings@1318
|
1674 var day = document.createAttribute('day');
|
nickjillings@1318
|
1675 var hour = document.createAttribute('hour');
|
nickjillings@1318
|
1676 var minute = document.createAttribute('minute');
|
nickjillings@1318
|
1677 var secs = document.createAttribute('secs');
|
nickjillings@1318
|
1678
|
nickjillings@1318
|
1679 year.nodeValue = dateTime.getFullYear();
|
nickjillings@1318
|
1680 month.nodeValue = dateTime.getMonth()+1;
|
nickjillings@1318
|
1681 day.nodeValue = dateTime.getDate();
|
nickjillings@1318
|
1682 hour.nodeValue = dateTime.getHours();
|
nickjillings@1318
|
1683 minute.nodeValue = dateTime.getMinutes();
|
nickjillings@1318
|
1684 secs.nodeValue = dateTime.getSeconds();
|
nickjillings@1318
|
1685
|
nickjillings@1318
|
1686 var hold = document.createElement("datetime");
|
nickjillings@1318
|
1687 var date = document.createElement("date");
|
nickjillings@1318
|
1688 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
|
nickjillings@1318
|
1689 var time = document.createElement("time");
|
nickjillings@1318
|
1690 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
|
nickjillings@1318
|
1691
|
nickjillings@1318
|
1692 date.setAttributeNode(year);
|
nickjillings@1318
|
1693 date.setAttributeNode(month);
|
nickjillings@1318
|
1694 date.setAttributeNode(day);
|
nickjillings@1318
|
1695 time.setAttributeNode(hour);
|
nickjillings@1318
|
1696 time.setAttributeNode(minute);
|
nickjillings@1318
|
1697 time.setAttributeNode(secs);
|
nickjillings@1318
|
1698
|
nickjillings@1318
|
1699 hold.appendChild(date);
|
nickjillings@1318
|
1700 hold.appendChild(time);
|
nickjillings@1318
|
1701 return hold;
|
nickjillings@1318
|
1702
|
nickjillings@1318
|
1703 }
|
nickjillings@1318
|
1704
|
nickjillings@1318
|
1705 function Specification() {
|
nickjillings@1318
|
1706 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
nickjillings@1318
|
1707
|
nickjillings@1324
|
1708 this.interface = null;
|
nickjillings@1324
|
1709 this.projectReturn = null;
|
nickjillings@1324
|
1710 this.randomiseOrder = null;
|
nickjillings@1324
|
1711 this.testPages = null;
|
nickjillings@1324
|
1712 this.pages = [];
|
nickjillings@1324
|
1713 this.metrics = null;
|
nickjillings@1324
|
1714 this.interfaces = null;
|
nickjillings@1324
|
1715 this.loudness = null;
|
nickjillings@1324
|
1716 this.errors = [];
|
nickjillings@1324
|
1717 this.schema = null;
|
nickjillings@1318
|
1718
|
nickjillings@1318
|
1719 this.randomiseOrder = function(input)
|
nickjillings@1318
|
1720 {
|
nickjillings@1318
|
1721 // This takes an array of information and randomises the order
|
nickjillings@1318
|
1722 var N = input.length;
|
nickjillings@1318
|
1723
|
nickjillings@1318
|
1724 var inputSequence = []; // For safety purposes: keep track of randomisation
|
nickjillings@1318
|
1725 for (var counter = 0; counter < N; ++counter)
|
nickjillings@1318
|
1726 inputSequence.push(counter) // Fill array
|
nickjillings@1318
|
1727 var inputSequenceClone = inputSequence.slice(0);
|
nickjillings@1318
|
1728
|
nickjillings@1318
|
1729 var holdArr = [];
|
nickjillings@1318
|
1730 var outputSequence = [];
|
nickjillings@1318
|
1731 for (var n=0; n<N; n++)
|
nickjillings@1318
|
1732 {
|
nickjillings@1318
|
1733 // First pick a random number
|
nickjillings@1318
|
1734 var r = Math.random();
|
nickjillings@1318
|
1735 // Multiply and floor by the number of elements left
|
nickjillings@1318
|
1736 r = Math.floor(r*input.length);
|
nickjillings@1318
|
1737 // Pick out that element and delete from the array
|
nickjillings@1318
|
1738 holdArr.push(input.splice(r,1)[0]);
|
nickjillings@1318
|
1739 // Do the same with sequence
|
nickjillings@1318
|
1740 outputSequence.push(inputSequence.splice(r,1)[0]);
|
nickjillings@1318
|
1741 }
|
nickjillings@1318
|
1742 console.log(inputSequenceClone.toString()); // print original array to console
|
nickjillings@1318
|
1743 console.log(outputSequence.toString()); // print randomised array to console
|
nickjillings@1318
|
1744 return holdArr;
|
nickjillings@1318
|
1745 };
|
nickjillings@1324
|
1746
|
nickjillings@1324
|
1747 this.processAttribute = function(attribute,schema)
|
nickjillings@1324
|
1748 {
|
nickjillings@1324
|
1749 // attribute is the string returned from getAttribute on the XML
|
nickjillings@1324
|
1750 // schema is the <xs:attribute> node
|
nickjillings@1324
|
1751 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
|
nickjillings@1324
|
1752 {
|
nickjillings@1348
|
1753 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
nickjillings@1324
|
1754 }
|
nickjillings@1324
|
1755 var defaultOpt = schema.getAttribute('default');
|
nickjillings@1324
|
1756 if (attribute == null) {
|
nickjillings@1324
|
1757 attribute = defaultOpt;
|
nickjillings@1324
|
1758 }
|
nickjillings@1324
|
1759 var dataType = schema.getAttribute('type');
|
nickjillings@1324
|
1760 if (typeof dataType == "string") { dataType = dataType.substr(3);}
|
nickjillings@1324
|
1761 else {dataType = "string";}
|
nickjillings@1324
|
1762 if (attribute == null)
|
nickjillings@1324
|
1763 {
|
nickjillings@1324
|
1764 return attribute;
|
nickjillings@1324
|
1765 }
|
nickjillings@1324
|
1766 switch(dataType)
|
nickjillings@1324
|
1767 {
|
nickjillings@1324
|
1768 case "boolean":
|
nickjillings@1324
|
1769 if (attribute == 'true'){attribute = true;}else{attribute=false;}
|
nickjillings@1324
|
1770 break;
|
nickjillings@1324
|
1771 case "negativeInteger":
|
nickjillings@1324
|
1772 case "positiveInteger":
|
nickjillings@1324
|
1773 case "nonNegativeInteger":
|
nickjillings@1324
|
1774 case "nonPositiveInteger":
|
nickjillings@1324
|
1775 case "integer":
|
nickjillings@1324
|
1776 case "decimal":
|
nickjillings@1324
|
1777 case "short":
|
nickjillings@1324
|
1778 attribute = Number(attribute);
|
nickjillings@1324
|
1779 break;
|
nickjillings@1324
|
1780 case "string":
|
nickjillings@1324
|
1781 default:
|
nickjillings@1324
|
1782 attribute = String(attribute);
|
nickjillings@1324
|
1783 break;
|
nickjillings@1324
|
1784 }
|
nickjillings@1324
|
1785 return attribute;
|
nickjillings@1324
|
1786 };
|
nickjillings@1318
|
1787
|
nickjillings@1318
|
1788 this.decode = function(projectXML) {
|
nickjillings@1324
|
1789 this.errors = [];
|
nickjillings@1318
|
1790 // projectXML - DOM Parsed document
|
nickjillings@1318
|
1791 this.projectXML = projectXML.childNodes[0];
|
nickjillings@1318
|
1792 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
nickjillings@1348
|
1793 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1324
|
1794 // First decode the attributes
|
nickjillings@1348
|
1795 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
1796 for (var i in attributes)
|
nickjillings@1318
|
1797 {
|
nickjillings@1324
|
1798 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1799 var attributeName = attributes[i].getAttribute('name');
|
nickjillings@1324
|
1800 var projectAttr = setupNode.getAttribute(attributeName);
|
nickjillings@1324
|
1801 projectAttr = this.processAttribute(projectAttr,attributes[i]);
|
nickjillings@1324
|
1802 switch(typeof projectAttr)
|
nickjillings@1318
|
1803 {
|
nickjillings@1324
|
1804 case "number":
|
nickjillings@1324
|
1805 case "boolean":
|
nickjillings@1324
|
1806 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
1807 break;
|
nickjillings@1324
|
1808 case "string":
|
nickjillings@1324
|
1809 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
1810 break;
|
nickjillings@1318
|
1811 }
|
nickjillings@1324
|
1812
|
nickjillings@1318
|
1813 }
|
nickjillings@1318
|
1814
|
nickjillings@1324
|
1815 this.metrics = {
|
nickjillings@1324
|
1816 enabled: [],
|
nickjillings@1324
|
1817 decode: function(parent, xml) {
|
nickjillings@1324
|
1818 var children = xml.getElementsByTagName('metricenable');
|
nickjillings@1324
|
1819 for (var i in children) {
|
nickjillings@1324
|
1820 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1821 this.enabled.push(children[i].textContent);
|
nickjillings@1324
|
1822 }
|
nickjillings@1324
|
1823 },
|
nickjillings@1324
|
1824 encode: function(root) {
|
nickjillings@1324
|
1825 var node = root.createElement('metric');
|
nickjillings@1324
|
1826 for (var i in this.enabled)
|
nickjillings@1324
|
1827 {
|
nickjillings@1324
|
1828 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1829 var child = root.createElement('metricenable');
|
nickjillings@1324
|
1830 child.textContent = this.enabled[i];
|
nickjillings@1324
|
1831 node.appendChild(child);
|
nickjillings@1324
|
1832 }
|
nickjillings@1324
|
1833 return node;
|
nickjillings@1324
|
1834 }
|
nickjillings@1324
|
1835 };
|
nickjillings@1318
|
1836
|
nickjillings@1324
|
1837 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
|
nickjillings@1324
|
1838
|
nickjillings@1324
|
1839 // Now process the survey node options
|
nickjillings@1324
|
1840 var survey = setupNode.getElementsByTagName('survey');
|
nickjillings@1348
|
1841 var surveySchema = specification.schema.getAllElementsByName('survey')[0];
|
nickjillings@1324
|
1842 for (var i in survey) {
|
nickjillings@1324
|
1843 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1844 var location = survey[i].getAttribute('location');
|
nickjillings@1324
|
1845 if (location == 'pre' || location == 'before')
|
nickjillings@1324
|
1846 {
|
nickjillings@1324
|
1847 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
1848 else {
|
nickjillings@1324
|
1849 this.preTest = new this.surveyNode();
|
nickjillings@1324
|
1850 this.preTest.decode(this,survey[i],surveySchema);
|
nickjillings@1324
|
1851 }
|
nickjillings@1324
|
1852 } else if (location == 'post' || location == 'after') {
|
nickjillings@1324
|
1853 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
1854 else {
|
nickjillings@1324
|
1855 this.postTest = new this.surveyNode();
|
nickjillings@1324
|
1856 this.postTest.decode(this,survey[i],surveySchema);
|
nickjillings@1324
|
1857 }
|
nickjillings@1318
|
1858 }
|
nickjillings@1318
|
1859 }
|
nickjillings@1318
|
1860
|
nickjillings@1324
|
1861 var interfaceNode = setupNode.getElementsByTagName('interface');
|
nickjillings@1324
|
1862 if (interfaceNode.length > 1)
|
nickjillings@1324
|
1863 {
|
nickjillings@1324
|
1864 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
|
nickjillings@1324
|
1865 }
|
nickjillings@1324
|
1866 this.interfaces = new this.interfaceNode();
|
nickjillings@1324
|
1867 if (interfaceNode.length != 0)
|
nickjillings@1324
|
1868 {
|
nickjillings@1324
|
1869 interfaceNode = interfaceNode[0];
|
nickjillings@1348
|
1870 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1318
|
1871 }
|
nickjillings@1318
|
1872
|
nickjillings@1324
|
1873 // Page tags
|
nickjillings@1324
|
1874 var pageTags = projectXML.getElementsByTagName('page');
|
nickjillings@1348
|
1875 var pageSchema = this.schema.getAllElementsByName('page')[0];
|
nickjillings@1324
|
1876 for (var i=0; i<pageTags.length; i++)
|
nickjillings@1318
|
1877 {
|
nickjillings@1324
|
1878 var node = new this.page();
|
nickjillings@1324
|
1879 node.decode(this,pageTags[i],pageSchema);
|
nickjillings@1324
|
1880 this.pages.push(node);
|
nickjillings@1318
|
1881 }
|
nickjillings@1318
|
1882 };
|
nickjillings@1318
|
1883
|
nickjillings@1318
|
1884 this.encode = function()
|
nickjillings@1318
|
1885 {
|
nickjillings@1324
|
1886 var root = document.implementation.createDocument(null,"waet");
|
nickjillings@1318
|
1887
|
nickjillings@1324
|
1888 // Build setup node
|
nickjillings@1318
|
1889
|
nickjillings@1318
|
1890 return root;
|
nickjillings@1318
|
1891 };
|
nickjillings@1318
|
1892
|
nickjillings@1324
|
1893 this.surveyNode = function() {
|
nickjillings@1324
|
1894 this.location = null;
|
nickjillings@1318
|
1895 this.options = [];
|
nickjillings@1324
|
1896 this.schema = null;
|
nickjillings@1318
|
1897
|
nickjillings@1318
|
1898 this.OptionNode = function() {
|
nickjillings@1318
|
1899 this.type = undefined;
|
nickjillings@1324
|
1900 this.schema = undefined;
|
nickjillings@1318
|
1901 this.id = undefined;
|
nickjillings@1318
|
1902 this.mandatory = undefined;
|
nickjillings@1318
|
1903 this.statement = undefined;
|
nickjillings@1318
|
1904 this.boxsize = undefined;
|
nickjillings@1318
|
1905 this.options = [];
|
nickjillings@1318
|
1906 this.min = undefined;
|
nickjillings@1318
|
1907 this.max = undefined;
|
nickjillings@1318
|
1908 this.step = undefined;
|
nickjillings@1318
|
1909
|
nickjillings@1324
|
1910 this.decode = function(parent,child,schema)
|
nickjillings@1318
|
1911 {
|
nickjillings@1324
|
1912 this.schema = schema;
|
nickjillings@1348
|
1913 var attributeMap = schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
1914 for (var i in attributeMap){
|
nickjillings@1324
|
1915 if(isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1916 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
1917 var projectAttr = child.getAttribute(attributeName);
|
nickjillings@1324
|
1918 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
1919 switch(typeof projectAttr)
|
nickjillings@1324
|
1920 {
|
nickjillings@1324
|
1921 case "number":
|
nickjillings@1324
|
1922 case "boolean":
|
nickjillings@1324
|
1923 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
1924 break;
|
nickjillings@1324
|
1925 case "string":
|
nickjillings@1324
|
1926 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
1927 break;
|
nickjillings@1318
|
1928 }
|
nickjillings@1324
|
1929 }
|
nickjillings@1324
|
1930 this.statement = child.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1324
|
1931 if (this.type == "checkbox" || this.type == "radio") {
|
nickjillings@1324
|
1932 var children = child.getElementsByTagName('option');
|
nickjillings@1324
|
1933 if (children.length == null) {
|
nickjillings@1318
|
1934 console.log('Malformed' +child.nodeName+ 'entry');
|
nickjillings@1318
|
1935 this.statement = 'Malformed' +child.nodeName+ 'entry';
|
nickjillings@1318
|
1936 this.type = 'statement';
|
nickjillings@1318
|
1937 } else {
|
nickjillings@1318
|
1938 this.options = [];
|
nickjillings@1324
|
1939 for (var i in children)
|
nickjillings@1324
|
1940 {
|
nickjillings@1324
|
1941 if (isNaN(Number(i))==true){break;}
|
nickjillings@1324
|
1942 this.options.push({
|
nickjillings@1324
|
1943 name: children[i].getAttribute('name'),
|
nickjillings@1324
|
1944 text: children[i].textContent
|
nickjillings@1324
|
1945 });
|
nickjillings@1318
|
1946 }
|
nickjillings@1318
|
1947 }
|
nickjillings@1318
|
1948 }
|
nickjillings@1318
|
1949 };
|
nickjillings@1318
|
1950
|
nickjillings@1318
|
1951 this.exportXML = function(root)
|
nickjillings@1318
|
1952 {
|
nickjillings@1324
|
1953 var node = root.createElement('surveyelement');
|
nickjillings@1324
|
1954 node.setAttribute('type',this.type);
|
nickjillings@1324
|
1955 var statement = root.createElement('statement');
|
nickjillings@1324
|
1956 statement.textContent = this.statement;
|
nickjillings@1324
|
1957 node.appendChild(statement);
|
nickjillings@1318
|
1958 switch(this.type)
|
nickjillings@1318
|
1959 {
|
nickjillings@1318
|
1960 case "statement":
|
nickjillings@1318
|
1961 break;
|
nickjillings@1318
|
1962 case "question":
|
nickjillings@1318
|
1963 node.id = this.id;
|
nickjillings@1318
|
1964 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1318
|
1965 node.setAttribute("boxsize",this.boxsize);
|
nickjillings@1318
|
1966 break;
|
nickjillings@1318
|
1967 case "number":
|
nickjillings@1318
|
1968 node.id = this.id;
|
nickjillings@1318
|
1969 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1318
|
1970 node.setAttribute("min", this.min);
|
nickjillings@1318
|
1971 node.setAttribute("max", this.max);
|
nickjillings@1318
|
1972 node.setAttribute("step", this.step);
|
nickjillings@1318
|
1973 break;
|
nickjillings@1318
|
1974 case "checkbox":
|
nickjillings@1318
|
1975 case "radio":
|
nickjillings@1318
|
1976 node.id = this.id;
|
nickjillings@1318
|
1977 for (var i=0; i<this.options.length; i++)
|
nickjillings@1318
|
1978 {
|
nickjillings@1318
|
1979 var option = this.options[i];
|
nickjillings@1318
|
1980 var optionNode = root.createElement("option");
|
nickjillings@1318
|
1981 optionNode.setAttribute("name",option.name);
|
nickjillings@1318
|
1982 optionNode.textContent = option.text;
|
nickjillings@1318
|
1983 node.appendChild(optionNode);
|
nickjillings@1318
|
1984 }
|
nickjillings@1318
|
1985 break;
|
nickjillings@1318
|
1986 }
|
nickjillings@1318
|
1987 return node;
|
nickjillings@1318
|
1988 };
|
nickjillings@1318
|
1989 };
|
nickjillings@1324
|
1990 this.decode = function(parent,xml,schema) {
|
nickjillings@1324
|
1991 this.schema = schema;
|
nickjillings@1324
|
1992 this.location = xml.getAttribute('location');
|
nickjillings@1324
|
1993 if (this.location == 'before'){this.location = 'pre';}
|
nickjillings@1324
|
1994 else if (this.location == 'after'){this.location = 'post';}
|
nickjillings@1348
|
1995 var surveyentrySchema = schema.getAllElementsByName('surveyentry')[0];
|
nickjillings@1324
|
1996 for (var i in xml.children)
|
nickjillings@1324
|
1997 {
|
nickjillings@1324
|
1998 if(isNaN(Number(i))==true){break;}
|
nickjillings@1318
|
1999 var node = new this.OptionNode();
|
nickjillings@1324
|
2000 node.decode(parent,xml.children[i],surveyentrySchema);
|
nickjillings@1318
|
2001 this.options.push(node);
|
nickjillings@1324
|
2002 }
|
nickjillings@1324
|
2003 };
|
nickjillings@1324
|
2004 this.encode = function(root) {
|
nickjillings@1324
|
2005 var node = root.createElement('survey');
|
nickjillings@1324
|
2006 node.setAttribute('location',this.location);
|
nickjillings@1324
|
2007 for (var i=0; i<this.options.length; i++)
|
nickjillings@1324
|
2008 {
|
nickjillings@1324
|
2009 node.appendChild(this.options[i].exportXML());
|
nickjillings@1324
|
2010 }
|
nickjillings@1324
|
2011 return node;
|
nickjillings@1324
|
2012 };
|
nickjillings@1324
|
2013 };
|
nickjillings@1324
|
2014
|
nickjillings@1324
|
2015 this.interfaceNode = function()
|
nickjillings@1324
|
2016 {
|
nickjillings@1324
|
2017 this.title = null;
|
nickjillings@1324
|
2018 this.name = null;
|
nickjillings@1324
|
2019 this.options = [];
|
nickjillings@1324
|
2020 this.scales = [];
|
nickjillings@1324
|
2021 this.schema = null;
|
nickjillings@1324
|
2022
|
nickjillings@1324
|
2023 this.decode = function(parent,xml,schema) {
|
nickjillings@1324
|
2024 this.schema = schema;
|
nickjillings@1324
|
2025 this.name = xml.getAttribute('name');
|
nickjillings@1324
|
2026 var titleNode = xml.getElementsByTagName('title');
|
nickjillings@1324
|
2027 if (titleNode.length == 1)
|
nickjillings@1324
|
2028 {
|
nickjillings@1324
|
2029 this.title = titleNode[0].textContent;
|
nickjillings@1324
|
2030 }
|
nickjillings@1324
|
2031 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
|
nickjillings@1324
|
2032 // Extract interfaceoption node schema
|
nickjillings@1348
|
2033 var interfaceOptionNodeSchema = schema.getAllElementsByName('interfaceoption')[0];
|
nickjillings@1348
|
2034 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
2035 for (var i=0; i<interfaceOptionNodes.length; i++)
|
nickjillings@1324
|
2036 {
|
nickjillings@1324
|
2037 var ioNode = interfaceOptionNodes[i];
|
nickjillings@1324
|
2038 var option = {};
|
nickjillings@1324
|
2039 for (var j=0; j<attributeMap.length; j++)
|
nickjillings@1324
|
2040 {
|
nickjillings@1324
|
2041 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
|
nickjillings@1324
|
2042 var projectAttr = ioNode.getAttribute(attributeName);
|
nickjillings@1324
|
2043 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
|
nickjillings@1324
|
2044 switch(typeof projectAttr)
|
nickjillings@1324
|
2045 {
|
nickjillings@1324
|
2046 case "number":
|
nickjillings@1324
|
2047 case "boolean":
|
nickjillings@1324
|
2048 eval('option.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
2049 break;
|
nickjillings@1324
|
2050 case "string":
|
nickjillings@1324
|
2051 eval('option.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
2052 break;
|
nickjillings@1324
|
2053 }
|
nickjillings@1324
|
2054 }
|
nickjillings@1324
|
2055 this.options.push(option);
|
nickjillings@1324
|
2056 }
|
nickjillings@1324
|
2057
|
nickjillings@1324
|
2058 // Now the scales nodes
|
nickjillings@1324
|
2059 var scaleParent = xml.getElementsByTagName('scales');
|
nickjillings@1324
|
2060 if (scaleParent.length == 1) {
|
nickjillings@1324
|
2061 scaleParent = scaleParent[0];
|
nickjillings@1324
|
2062 for (var i=0; i<scaleParent.children.length; i++) {
|
nickjillings@1324
|
2063 var child = scaleParent.children[i];
|
nickjillings@1324
|
2064 this.scales.push({
|
nickjillings@1324
|
2065 text: child.textContent,
|
nickjillings@1324
|
2066 position: Number(child.getAttribute('position'))
|
nickjillings@1324
|
2067 });
|
nickjillings@1318
|
2068 }
|
nickjillings@1318
|
2069 }
|
nickjillings@1318
|
2070 };
|
nickjillings@1324
|
2071
|
nickjillings@1324
|
2072 this.encode = function(root) {
|
nickjillings@1324
|
2073
|
nickjillings@1324
|
2074 };
|
nickjillings@1318
|
2075 };
|
nickjillings@1318
|
2076
|
nickjillings@1324
|
2077 this.page = function() {
|
nickjillings@1318
|
2078 this.presentedId = undefined;
|
nickjillings@1318
|
2079 this.id = undefined;
|
nickjillings@1318
|
2080 this.hostURL = undefined;
|
nickjillings@1318
|
2081 this.randomiseOrder = undefined;
|
nickjillings@1318
|
2082 this.loop = undefined;
|
nickjillings@1324
|
2083 this.showElementComments = undefined;
|
nickjillings@1318
|
2084 this.outsideReference = null;
|
nickjillings@1318
|
2085 this.loudness = null;
|
nickjillings@1324
|
2086 this.preTest = null;
|
nickjillings@1324
|
2087 this.postTest = null;
|
nickjillings@1318
|
2088 this.interfaces = [];
|
nickjillings@1318
|
2089 this.commentBoxPrefix = "Comment on track";
|
nickjillings@1318
|
2090 this.audioElements = [];
|
nickjillings@1318
|
2091 this.commentQuestions = [];
|
nickjillings@1324
|
2092 this.schema = null;
|
nickjillings@1318
|
2093
|
nickjillings@1324
|
2094 this.decode = function(parent,xml,schema)
|
nickjillings@1318
|
2095 {
|
nickjillings@1324
|
2096 this.schema = schema;
|
nickjillings@1348
|
2097 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
2098 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1318
|
2099 {
|
nickjillings@1324
|
2100 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
2101 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1324
|
2102 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
2103 switch(typeof projectAttr)
|
nickjillings@1318
|
2104 {
|
nickjillings@1324
|
2105 case "number":
|
nickjillings@1324
|
2106 case "boolean":
|
nickjillings@1324
|
2107 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
2108 break;
|
nickjillings@1324
|
2109 case "string":
|
nickjillings@1324
|
2110 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
2111 break;
|
nickjillings@1318
|
2112 }
|
nickjillings@1318
|
2113 }
|
nickjillings@1318
|
2114
|
nickjillings@1324
|
2115 // Get the Comment Box Prefix
|
nickjillings@1324
|
2116 var CBP = xml.getElementsByTagName('commentboxprefix');
|
nickjillings@1324
|
2117 if (CBP.length != 0) {
|
nickjillings@1324
|
2118 this.commentBoxPrefix = CBP[0].textContent;
|
nickjillings@1318
|
2119 }
|
nickjillings@1318
|
2120
|
nickjillings@1324
|
2121 // Now decode the interfaces
|
nickjillings@1324
|
2122 var interfaceNode = xml.getElementsByTagName('interface');
|
nickjillings@1324
|
2123 for (var i=0; i<interfaceNode.length; i++)
|
nickjillings@1324
|
2124 {
|
nickjillings@1324
|
2125 var node = new parent.interfaceNode();
|
nickjillings@1348
|
2126 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1324
|
2127 this.interfaces.push(node);
|
nickjillings@1324
|
2128 }
|
nickjillings@1318
|
2129
|
nickjillings@1324
|
2130 // Now process the survey node options
|
nickjillings@1324
|
2131 var survey = xml.getElementsByTagName('survey');
|
nickjillings@1348
|
2132 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
|
nickjillings@1324
|
2133 for (var i in survey) {
|
nickjillings@1324
|
2134 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
2135 var location = survey[i].getAttribute('location');
|
nickjillings@1324
|
2136 if (location == 'pre' || location == 'before')
|
nickjillings@1324
|
2137 {
|
nickjillings@1324
|
2138 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
2139 else {
|
nickjillings@1324
|
2140 this.preTest = new parent.surveyNode();
|
nickjillings@1324
|
2141 this.preTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1324
|
2142 }
|
nickjillings@1324
|
2143 } else if (location == 'post' || location == 'after') {
|
nickjillings@1324
|
2144 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
2145 else {
|
nickjillings@1324
|
2146 this.postTest = new parent.surveyNode();
|
nickjillings@1324
|
2147 this.postTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1324
|
2148 }
|
nickjillings@1324
|
2149 }
|
nickjillings@1324
|
2150 }
|
nickjillings@1324
|
2151
|
nickjillings@1324
|
2152 // Now process the audioelement tags
|
nickjillings@1324
|
2153 var audioElements = xml.getElementsByTagName('audioelement');
|
nickjillings@1348
|
2154 var audioElementSchema = parent.schema.getAllElementsByName('audioelement')[0];
|
nickjillings@1324
|
2155 for (var i=0; i<audioElements.length; i++)
|
nickjillings@1324
|
2156 {
|
nickjillings@1324
|
2157 var node = new this.audioElementNode();
|
nickjillings@1324
|
2158 node.decode(this,audioElements[i],audioElementSchema);
|
nickjillings@1324
|
2159 this.audioElements.push(node);
|
nickjillings@1324
|
2160 }
|
nickjillings@1324
|
2161
|
nickjillings@1324
|
2162 // Now decode the commentquestions
|
nickjillings@1324
|
2163 var commentQuestions = xml.getElementsByTagName('commentquestion');
|
nickjillings@1348
|
2164 var commentQuestionSchema = parent.schema.getAllElementsByName('commentquestion')[0];
|
nickjillings@1324
|
2165 for (var i=0; i<commentQuestions.length; i++)
|
nickjillings@1324
|
2166 {
|
nickjillings@1318
|
2167 var node = new this.commentQuestionNode();
|
nickjillings@1324
|
2168 node.decode(parent,commentQuestions[i],commentQuestionSchema);
|
nickjillings@1318
|
2169 this.commentQuestions.push(node);
|
nickjillings@1318
|
2170 }
|
nickjillings@1318
|
2171 };
|
nickjillings@1318
|
2172
|
nickjillings@1318
|
2173 this.encode = function(root)
|
nickjillings@1318
|
2174 {
|
nickjillings@1318
|
2175 var AHNode = root.createElement("audioHolder");
|
nickjillings@1318
|
2176 AHNode.id = this.id;
|
nickjillings@1318
|
2177 AHNode.setAttribute("hostURL",this.hostURL);
|
nickjillings@1318
|
2178 AHNode.setAttribute("sampleRate",this.sampleRate);
|
nickjillings@1318
|
2179 AHNode.setAttribute("randomiseOrder",this.randomiseOrder);
|
nickjillings@1318
|
2180 AHNode.setAttribute("repeatCount",this.repeatCount);
|
nickjillings@1318
|
2181 AHNode.setAttribute("loop",this.loop);
|
nickjillings@1318
|
2182 AHNode.setAttribute("elementComments",this.elementComments);
|
nickjillings@1318
|
2183 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
|
nickjillings@1318
|
2184 if(this.initialPosition != null) {
|
nickjillings@1318
|
2185 AHNode.setAttribute("loudness",this.initialPosition*100);
|
nickjillings@1318
|
2186 }
|
nickjillings@1318
|
2187 for (var i=0; i<this.interfaces.length; i++)
|
nickjillings@1318
|
2188 {
|
nickjillings@1318
|
2189 AHNode.appendChild(this.interfaces[i].encode(root));
|
nickjillings@1318
|
2190 }
|
nickjillings@1318
|
2191
|
nickjillings@1318
|
2192 for (var i=0; i<this.audioElements.length; i++) {
|
nickjillings@1318
|
2193 AHNode.appendChild(this.audioElements[i].encode(root));
|
nickjillings@1318
|
2194 }
|
nickjillings@1318
|
2195 // Create <CommentQuestion>
|
nickjillings@1318
|
2196 for (var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1318
|
2197 {
|
nickjillings@1318
|
2198 AHNode.appendChild(this.commentQuestions[i].exportXML(root));
|
nickjillings@1318
|
2199 }
|
nickjillings@1318
|
2200
|
nickjillings@1318
|
2201 // Create <PreTest>
|
nickjillings@1318
|
2202 var AHPreTest = root.createElement("PreTest");
|
nickjillings@1318
|
2203 for (var i=0; i<this.preTest.options.length; i++)
|
nickjillings@1318
|
2204 {
|
nickjillings@1318
|
2205 AHPreTest.appendChild(this.preTest.options[i].exportXML(root));
|
nickjillings@1318
|
2206 }
|
nickjillings@1318
|
2207
|
nickjillings@1318
|
2208 var AHPostTest = root.createElement("PostTest");
|
nickjillings@1318
|
2209 for (var i=0; i<this.postTest.options.length; i++)
|
nickjillings@1318
|
2210 {
|
nickjillings@1318
|
2211 AHPostTest.appendChild(this.postTest.options[i].exportXML(root));
|
nickjillings@1318
|
2212 }
|
nickjillings@1318
|
2213 AHNode.appendChild(AHPreTest);
|
nickjillings@1318
|
2214 AHNode.appendChild(AHPostTest);
|
nickjillings@1318
|
2215 return AHNode;
|
nickjillings@1318
|
2216 };
|
nickjillings@1318
|
2217
|
nickjillings@1324
|
2218 this.commentQuestionNode = function() {
|
nickjillings@1324
|
2219 this.id = null;
|
nickjillings@1324
|
2220 this.type = undefined;
|
nickjillings@1318
|
2221 this.options = [];
|
nickjillings@1324
|
2222 this.statement = undefined;
|
nickjillings@1324
|
2223 this.schema = null;
|
nickjillings@1324
|
2224 this.decode = function(parent,xml,schema)
|
nickjillings@1318
|
2225 {
|
nickjillings@1324
|
2226 this.id = xml.id;
|
nickjillings@1324
|
2227 this.type = xml.getAttribute('type');
|
nickjillings@1324
|
2228 this.statement = xml.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1324
|
2229 var optNodes = xml.getElementsByTagName('option');
|
nickjillings@1324
|
2230 for (var i=0; i<optNodes.length; i++)
|
nickjillings@1324
|
2231 {
|
nickjillings@1324
|
2232 var optNode = optNodes[i];
|
nickjillings@1324
|
2233 this.options.push({
|
nickjillings@1324
|
2234 name: optNode.getAttribute('name'),
|
nickjillings@1324
|
2235 text: optNode.textContent
|
nickjillings@1324
|
2236 });
|
nickjillings@1318
|
2237 }
|
nickjillings@1318
|
2238 };
|
nickjillings@1324
|
2239
|
nickjillings@1318
|
2240 this.encode = function(root)
|
nickjillings@1318
|
2241 {
|
nickjillings@1324
|
2242
|
nickjillings@1318
|
2243 };
|
nickjillings@1318
|
2244 };
|
nickjillings@1318
|
2245
|
nickjillings@1318
|
2246 this.audioElementNode = function() {
|
nickjillings@1318
|
2247 this.url = null;
|
nickjillings@1318
|
2248 this.id = null;
|
nickjillings@1318
|
2249 this.parent = null;
|
nickjillings@1324
|
2250 this.type = null;
|
nickjillings@1318
|
2251 this.marker = false;
|
nickjillings@1318
|
2252 this.enforce = false;
|
nickjillings@1318
|
2253 this.gain = 1.0;
|
nickjillings@1324
|
2254 this.schema = null;
|
nickjillings@1324
|
2255 this.parent = null;
|
nickjillings@1324
|
2256 this.decode = function(parent,xml,schema)
|
nickjillings@1318
|
2257 {
|
nickjillings@1324
|
2258 this.schema = schema;
|
nickjillings@1318
|
2259 this.parent = parent;
|
nickjillings@1348
|
2260 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
2261 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1318
|
2262 {
|
nickjillings@1324
|
2263 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
2264 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1324
|
2265 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
2266 switch(typeof projectAttr)
|
nickjillings@1318
|
2267 {
|
nickjillings@1324
|
2268 case "number":
|
nickjillings@1324
|
2269 case "boolean":
|
nickjillings@1324
|
2270 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
2271 break;
|
nickjillings@1324
|
2272 case "string":
|
nickjillings@1324
|
2273 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
2274 break;
|
nickjillings@1318
|
2275 }
|
nickjillings@1318
|
2276 }
|
nickjillings@1324
|
2277
|
nickjillings@1318
|
2278 };
|
nickjillings@1318
|
2279 this.encode = function(root)
|
nickjillings@1318
|
2280 {
|
nickjillings@1318
|
2281 var AENode = root.createElement("audioElements");
|
nickjillings@1318
|
2282 AENode.id = this.id;
|
nickjillings@1318
|
2283 AENode.setAttribute("url",this.url);
|
nickjillings@1318
|
2284 AENode.setAttribute("type",this.type);
|
nickjillings@1318
|
2285 AENode.setAttribute("gain",linearToDecibel(this.gain));
|
nickjillings@1318
|
2286 if (this.marker != false)
|
nickjillings@1318
|
2287 {
|
nickjillings@1318
|
2288 AENode.setAttribute("marker",this.marker*100);
|
nickjillings@1318
|
2289 }
|
nickjillings@1318
|
2290 return AENode;
|
nickjillings@1318
|
2291 };
|
nickjillings@1318
|
2292 };
|
nickjillings@1318
|
2293 };
|
nickjillings@1318
|
2294 }
|
nickjillings@1318
|
2295
|
nickjillings@1318
|
2296 function Interface(specificationObject) {
|
nickjillings@1318
|
2297 // This handles the bindings between the interface and the audioEngineContext;
|
nickjillings@1318
|
2298 this.specification = specificationObject;
|
nickjillings@1318
|
2299 this.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1318
|
2300
|
nickjillings@1324
|
2301 this.newPage = function(audioHolderObject,store)
|
nickjillings@1318
|
2302 {
|
nickjillings@1324
|
2303 audioEngineContext.newTestPage(store);
|
nickjillings@1318
|
2304 audioEngineContext.loopPlayback = audioHolderObject.loop;
|
nickjillings@1318
|
2305 // Delete any previous audioObjects associated with the audioEngine
|
nickjillings@1318
|
2306 audioEngineContext.audioObjects = [];
|
nickjillings@1318
|
2307 interfaceContext.deleteCommentBoxes();
|
nickjillings@1318
|
2308 interfaceContext.deleteCommentQuestions();
|
nickjillings@1324
|
2309 loadTest(audioHolderObject,store);
|
nickjillings@1318
|
2310 };
|
nickjillings@1318
|
2311
|
nickjillings@1318
|
2312 // Bounded by interface!!
|
nickjillings@1318
|
2313 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
|
nickjillings@1318
|
2314 // For example, APE returns the slider position normalised in a <value> tag.
|
nickjillings@1318
|
2315 this.interfaceObjects = [];
|
nickjillings@1318
|
2316 this.interfaceObject = function(){};
|
nickjillings@1318
|
2317
|
nickjillings@1318
|
2318 this.resizeWindow = function(event)
|
nickjillings@1318
|
2319 {
|
nickjillings@1318
|
2320 popup.resize(event);
|
nickjillings@1318
|
2321 for(var i=0; i<this.commentBoxes.length; i++)
|
nickjillings@1318
|
2322 {this.commentBoxes[i].resize();}
|
nickjillings@1318
|
2323 for(var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1318
|
2324 {this.commentQuestions[i].resize();}
|
nickjillings@1318
|
2325 try
|
nickjillings@1318
|
2326 {
|
nickjillings@1318
|
2327 resizeWindow(event);
|
nickjillings@1318
|
2328 }
|
nickjillings@1318
|
2329 catch(err)
|
nickjillings@1318
|
2330 {
|
nickjillings@1318
|
2331 console.log("Warning - Interface does not have Resize option");
|
nickjillings@1318
|
2332 console.log(err);
|
nickjillings@1318
|
2333 }
|
nickjillings@1318
|
2334 };
|
nickjillings@1318
|
2335
|
nickjillings@1318
|
2336 this.returnNavigator = function()
|
nickjillings@1318
|
2337 {
|
nickjillings@1318
|
2338 var node = document.createElement("navigator");
|
nickjillings@1318
|
2339 var platform = document.createElement("platform");
|
nickjillings@1318
|
2340 platform.textContent = navigator.platform;
|
nickjillings@1318
|
2341 var vendor = document.createElement("vendor");
|
nickjillings@1318
|
2342 vendor.textContent = navigator.vendor;
|
nickjillings@1318
|
2343 var userAgent = document.createElement("uagent");
|
nickjillings@1318
|
2344 userAgent.textContent = navigator.userAgent;
|
nickjillings@1318
|
2345 node.appendChild(platform);
|
nickjillings@1318
|
2346 node.appendChild(vendor);
|
nickjillings@1318
|
2347 node.appendChild(userAgent);
|
nickjillings@1318
|
2348 return node;
|
nickjillings@1318
|
2349 };
|
nickjillings@1318
|
2350
|
nickjillings@1318
|
2351 this.commentBoxes = [];
|
nickjillings@1318
|
2352 this.elementCommentBox = function(audioObject) {
|
nickjillings@1318
|
2353 var element = audioObject.specification;
|
nickjillings@1318
|
2354 this.audioObject = audioObject;
|
nickjillings@1318
|
2355 this.id = audioObject.id;
|
nickjillings@1318
|
2356 var audioHolderObject = audioObject.specification.parent;
|
nickjillings@1318
|
2357 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2358 this.trackComment = document.createElement('div');
|
nickjillings@1318
|
2359 this.trackComment.className = 'comment-div';
|
nickjillings@1318
|
2360 this.trackComment.id = 'comment-div-'+audioObject.id;
|
nickjillings@1318
|
2361 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2362 this.trackString = document.createElement('span');
|
nickjillings@1318
|
2363 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id;
|
nickjillings@1318
|
2364 // Create the HTML5 comment box 'textarea'
|
nickjillings@1318
|
2365 this.trackCommentBox = document.createElement('textarea');
|
nickjillings@1318
|
2366 this.trackCommentBox.rows = '4';
|
nickjillings@1318
|
2367 this.trackCommentBox.cols = '100';
|
nickjillings@1318
|
2368 this.trackCommentBox.name = 'trackComment'+audioObject.id;
|
nickjillings@1318
|
2369 this.trackCommentBox.className = 'trackComment';
|
nickjillings@1318
|
2370 var br = document.createElement('br');
|
nickjillings@1318
|
2371 // Add to the holder.
|
nickjillings@1318
|
2372 this.trackComment.appendChild(this.trackString);
|
nickjillings@1318
|
2373 this.trackComment.appendChild(br);
|
nickjillings@1318
|
2374 this.trackComment.appendChild(this.trackCommentBox);
|
nickjillings@1318
|
2375
|
nickjillings@1318
|
2376 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2377 var root = document.createElement('comment');
|
nickjillings@1318
|
2378 if (this.audioObject.specification.parent.elementComments) {
|
nickjillings@1318
|
2379 var question = document.createElement('question');
|
nickjillings@1318
|
2380 question.textContent = this.trackString.textContent;
|
nickjillings@1318
|
2381 var response = document.createElement('response');
|
nickjillings@1318
|
2382 response.textContent = this.trackCommentBox.value;
|
nickjillings@1318
|
2383 console.log("Comment frag-"+this.id+": "+response.textContent);
|
nickjillings@1318
|
2384 root.appendChild(question);
|
nickjillings@1318
|
2385 root.appendChild(response);
|
nickjillings@1318
|
2386 }
|
nickjillings@1318
|
2387 return root;
|
nickjillings@1318
|
2388 };
|
nickjillings@1318
|
2389 this.resize = function()
|
nickjillings@1318
|
2390 {
|
nickjillings@1318
|
2391 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2392 if (boxwidth >= 600)
|
nickjillings@1318
|
2393 {
|
nickjillings@1318
|
2394 boxwidth = 600;
|
nickjillings@1318
|
2395 }
|
nickjillings@1318
|
2396 else if (boxwidth < 400)
|
nickjillings@1318
|
2397 {
|
nickjillings@1318
|
2398 boxwidth = 400;
|
nickjillings@1318
|
2399 }
|
nickjillings@1318
|
2400 this.trackComment.style.width = boxwidth+"px";
|
nickjillings@1318
|
2401 this.trackCommentBox.style.width = boxwidth-6+"px";
|
nickjillings@1318
|
2402 };
|
nickjillings@1318
|
2403 this.resize();
|
nickjillings@1318
|
2404 };
|
nickjillings@1318
|
2405
|
nickjillings@1318
|
2406 this.commentQuestions = [];
|
nickjillings@1318
|
2407
|
nickjillings@1318
|
2408 this.commentBox = function(commentQuestion) {
|
nickjillings@1318
|
2409 this.specification = commentQuestion;
|
nickjillings@1318
|
2410 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2411 this.holder = document.createElement('div');
|
nickjillings@1318
|
2412 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2413 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2414 this.string = document.createElement('span');
|
nickjillings@1324
|
2415 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2416 // Create the HTML5 comment box 'textarea'
|
nickjillings@1318
|
2417 this.textArea = document.createElement('textarea');
|
nickjillings@1318
|
2418 this.textArea.rows = '4';
|
nickjillings@1318
|
2419 this.textArea.cols = '100';
|
nickjillings@1318
|
2420 this.textArea.className = 'trackComment';
|
nickjillings@1318
|
2421 var br = document.createElement('br');
|
nickjillings@1318
|
2422 // Add to the holder.
|
nickjillings@1318
|
2423 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2424 this.holder.appendChild(br);
|
nickjillings@1318
|
2425 this.holder.appendChild(this.textArea);
|
nickjillings@1318
|
2426
|
nickjillings@1318
|
2427 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2428 var root = document.createElement('comment');
|
nickjillings@1318
|
2429 root.id = this.specification.id;
|
nickjillings@1318
|
2430 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2431 root.textContent = this.textArea.value;
|
nickjillings@1318
|
2432 console.log("Question: "+this.string.textContent);
|
nickjillings@1318
|
2433 console.log("Response: "+root.textContent);
|
nickjillings@1318
|
2434 return root;
|
nickjillings@1318
|
2435 };
|
nickjillings@1318
|
2436 this.resize = function()
|
nickjillings@1318
|
2437 {
|
nickjillings@1318
|
2438 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2439 if (boxwidth >= 600)
|
nickjillings@1318
|
2440 {
|
nickjillings@1318
|
2441 boxwidth = 600;
|
nickjillings@1318
|
2442 }
|
nickjillings@1318
|
2443 else if (boxwidth < 400)
|
nickjillings@1318
|
2444 {
|
nickjillings@1318
|
2445 boxwidth = 400;
|
nickjillings@1318
|
2446 }
|
nickjillings@1318
|
2447 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2448 this.textArea.style.width = boxwidth-6+"px";
|
nickjillings@1318
|
2449 };
|
nickjillings@1318
|
2450 this.resize();
|
nickjillings@1318
|
2451 };
|
nickjillings@1318
|
2452
|
nickjillings@1318
|
2453 this.radioBox = function(commentQuestion) {
|
nickjillings@1318
|
2454 this.specification = commentQuestion;
|
nickjillings@1318
|
2455 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2456 this.holder = document.createElement('div');
|
nickjillings@1318
|
2457 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2458 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2459 this.string = document.createElement('span');
|
nickjillings@1318
|
2460 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2461 var br = document.createElement('br');
|
nickjillings@1318
|
2462 // Add to the holder.
|
nickjillings@1318
|
2463 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2464 this.holder.appendChild(br);
|
nickjillings@1318
|
2465 this.options = [];
|
nickjillings@1318
|
2466 this.inputs = document.createElement('div');
|
nickjillings@1318
|
2467 this.span = document.createElement('div');
|
nickjillings@1318
|
2468 this.inputs.align = 'center';
|
nickjillings@1318
|
2469 this.inputs.style.marginLeft = '12px';
|
nickjillings@1318
|
2470 this.span.style.marginLeft = '12px';
|
nickjillings@1318
|
2471 this.span.align = 'center';
|
nickjillings@1318
|
2472 this.span.style.marginTop = '15px';
|
nickjillings@1318
|
2473
|
nickjillings@1318
|
2474 var optCount = commentQuestion.options.length;
|
nickjillings@1324
|
2475 for (var optNode of commentQuestion.options)
|
nickjillings@1318
|
2476 {
|
nickjillings@1318
|
2477 var div = document.createElement('div');
|
nickjillings@1318
|
2478 div.style.width = '80px';
|
nickjillings@1318
|
2479 div.style.float = 'left';
|
nickjillings@1318
|
2480 var input = document.createElement('input');
|
nickjillings@1318
|
2481 input.type = 'radio';
|
nickjillings@1318
|
2482 input.name = commentQuestion.id;
|
nickjillings@1324
|
2483 input.setAttribute('setvalue',optNode.name);
|
nickjillings@1318
|
2484 input.className = 'comment-radio';
|
nickjillings@1318
|
2485 div.appendChild(input);
|
nickjillings@1318
|
2486 this.inputs.appendChild(div);
|
nickjillings@1318
|
2487
|
nickjillings@1318
|
2488
|
nickjillings@1318
|
2489 div = document.createElement('div');
|
nickjillings@1318
|
2490 div.style.width = '80px';
|
nickjillings@1318
|
2491 div.style.float = 'left';
|
nickjillings@1318
|
2492 div.align = 'center';
|
nickjillings@1318
|
2493 var span = document.createElement('span');
|
nickjillings@1324
|
2494 span.textContent = optNode.text;
|
nickjillings@1318
|
2495 span.className = 'comment-radio-span';
|
nickjillings@1318
|
2496 div.appendChild(span);
|
nickjillings@1318
|
2497 this.span.appendChild(div);
|
nickjillings@1318
|
2498 this.options.push(input);
|
nickjillings@1318
|
2499 }
|
nickjillings@1318
|
2500 this.holder.appendChild(this.span);
|
nickjillings@1318
|
2501 this.holder.appendChild(this.inputs);
|
nickjillings@1318
|
2502
|
nickjillings@1318
|
2503 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2504 var root = document.createElement('comment');
|
nickjillings@1318
|
2505 root.id = this.specification.id;
|
nickjillings@1318
|
2506 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2507 var question = document.createElement('question');
|
nickjillings@1318
|
2508 question.textContent = this.string.textContent;
|
nickjillings@1318
|
2509 var response = document.createElement('response');
|
nickjillings@1318
|
2510 var i=0;
|
nickjillings@1318
|
2511 while(this.options[i].checked == false) {
|
nickjillings@1318
|
2512 i++;
|
nickjillings@1318
|
2513 if (i >= this.options.length) {
|
nickjillings@1318
|
2514 break;
|
nickjillings@1318
|
2515 }
|
nickjillings@1318
|
2516 }
|
nickjillings@1318
|
2517 if (i >= this.options.length) {
|
nickjillings@1318
|
2518 response.textContent = 'null';
|
nickjillings@1318
|
2519 } else {
|
nickjillings@1318
|
2520 response.textContent = this.options[i].getAttribute('setvalue');
|
nickjillings@1318
|
2521 response.setAttribute('number',i);
|
nickjillings@1318
|
2522 }
|
nickjillings@1318
|
2523 console.log('Comment: '+question.textContent);
|
nickjillings@1318
|
2524 console.log('Response: '+response.textContent);
|
nickjillings@1318
|
2525 root.appendChild(question);
|
nickjillings@1318
|
2526 root.appendChild(response);
|
nickjillings@1318
|
2527 return root;
|
nickjillings@1318
|
2528 };
|
nickjillings@1318
|
2529 this.resize = function()
|
nickjillings@1318
|
2530 {
|
nickjillings@1318
|
2531 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2532 if (boxwidth >= 600)
|
nickjillings@1318
|
2533 {
|
nickjillings@1318
|
2534 boxwidth = 600;
|
nickjillings@1318
|
2535 }
|
nickjillings@1318
|
2536 else if (boxwidth < 400)
|
nickjillings@1318
|
2537 {
|
nickjillings@1318
|
2538 boxwidth = 400;
|
nickjillings@1318
|
2539 }
|
nickjillings@1318
|
2540 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2541 var text = this.holder.children[2];
|
nickjillings@1318
|
2542 var options = this.holder.children[3];
|
nickjillings@1318
|
2543 var optCount = options.children.length;
|
nickjillings@1318
|
2544 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
|
nickjillings@1318
|
2545 var options = options.firstChild;
|
nickjillings@1318
|
2546 var text = text.firstChild;
|
nickjillings@1318
|
2547 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2548 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2549 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2550 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2551 while(options.nextSibling != undefined)
|
nickjillings@1318
|
2552 {
|
nickjillings@1318
|
2553 options = options.nextSibling;
|
nickjillings@1318
|
2554 text = text.nextSibling;
|
nickjillings@1318
|
2555 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2556 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2557 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2558 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2559 }
|
nickjillings@1318
|
2560 };
|
nickjillings@1318
|
2561 this.resize();
|
nickjillings@1318
|
2562 };
|
nickjillings@1318
|
2563
|
nickjillings@1318
|
2564 this.checkboxBox = function(commentQuestion) {
|
nickjillings@1318
|
2565 this.specification = commentQuestion;
|
nickjillings@1318
|
2566 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2567 this.holder = document.createElement('div');
|
nickjillings@1318
|
2568 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2569 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2570 this.string = document.createElement('span');
|
nickjillings@1318
|
2571 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2572 var br = document.createElement('br');
|
nickjillings@1318
|
2573 // Add to the holder.
|
nickjillings@1318
|
2574 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2575 this.holder.appendChild(br);
|
nickjillings@1318
|
2576 this.options = [];
|
nickjillings@1318
|
2577 this.inputs = document.createElement('div');
|
nickjillings@1318
|
2578 this.span = document.createElement('div');
|
nickjillings@1318
|
2579 this.inputs.align = 'center';
|
nickjillings@1318
|
2580 this.inputs.style.marginLeft = '12px';
|
nickjillings@1318
|
2581 this.span.style.marginLeft = '12px';
|
nickjillings@1318
|
2582 this.span.align = 'center';
|
nickjillings@1318
|
2583 this.span.style.marginTop = '15px';
|
nickjillings@1318
|
2584
|
nickjillings@1318
|
2585 var optCount = commentQuestion.options.length;
|
nickjillings@1318
|
2586 for (var i=0; i<optCount; i++)
|
nickjillings@1318
|
2587 {
|
nickjillings@1318
|
2588 var div = document.createElement('div');
|
nickjillings@1318
|
2589 div.style.width = '80px';
|
nickjillings@1318
|
2590 div.style.float = 'left';
|
nickjillings@1318
|
2591 var input = document.createElement('input');
|
nickjillings@1318
|
2592 input.type = 'checkbox';
|
nickjillings@1318
|
2593 input.name = commentQuestion.id;
|
nickjillings@1318
|
2594 input.setAttribute('setvalue',commentQuestion.options[i].name);
|
nickjillings@1318
|
2595 input.className = 'comment-radio';
|
nickjillings@1318
|
2596 div.appendChild(input);
|
nickjillings@1318
|
2597 this.inputs.appendChild(div);
|
nickjillings@1318
|
2598
|
nickjillings@1318
|
2599
|
nickjillings@1318
|
2600 div = document.createElement('div');
|
nickjillings@1318
|
2601 div.style.width = '80px';
|
nickjillings@1318
|
2602 div.style.float = 'left';
|
nickjillings@1318
|
2603 div.align = 'center';
|
nickjillings@1318
|
2604 var span = document.createElement('span');
|
nickjillings@1318
|
2605 span.textContent = commentQuestion.options[i].text;
|
nickjillings@1318
|
2606 span.className = 'comment-radio-span';
|
nickjillings@1318
|
2607 div.appendChild(span);
|
nickjillings@1318
|
2608 this.span.appendChild(div);
|
nickjillings@1318
|
2609 this.options.push(input);
|
nickjillings@1318
|
2610 }
|
nickjillings@1318
|
2611 this.holder.appendChild(this.span);
|
nickjillings@1318
|
2612 this.holder.appendChild(this.inputs);
|
nickjillings@1318
|
2613
|
nickjillings@1318
|
2614 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2615 var root = document.createElement('comment');
|
nickjillings@1318
|
2616 root.id = this.specification.id;
|
nickjillings@1318
|
2617 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2618 var question = document.createElement('question');
|
nickjillings@1318
|
2619 question.textContent = this.string.textContent;
|
nickjillings@1318
|
2620 root.appendChild(question);
|
nickjillings@1318
|
2621 console.log('Comment: '+question.textContent);
|
nickjillings@1318
|
2622 for (var i=0; i<this.options.length; i++) {
|
nickjillings@1318
|
2623 var response = document.createElement('response');
|
nickjillings@1318
|
2624 response.textContent = this.options[i].checked;
|
nickjillings@1318
|
2625 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
|
nickjillings@1318
|
2626 root.appendChild(response);
|
nickjillings@1318
|
2627 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
|
nickjillings@1318
|
2628 }
|
nickjillings@1318
|
2629 return root;
|
nickjillings@1318
|
2630 };
|
nickjillings@1318
|
2631 this.resize = function()
|
nickjillings@1318
|
2632 {
|
nickjillings@1318
|
2633 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2634 if (boxwidth >= 600)
|
nickjillings@1318
|
2635 {
|
nickjillings@1318
|
2636 boxwidth = 600;
|
nickjillings@1318
|
2637 }
|
nickjillings@1318
|
2638 else if (boxwidth < 400)
|
nickjillings@1318
|
2639 {
|
nickjillings@1318
|
2640 boxwidth = 400;
|
nickjillings@1318
|
2641 }
|
nickjillings@1318
|
2642 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2643 var text = this.holder.children[2];
|
nickjillings@1318
|
2644 var options = this.holder.children[3];
|
nickjillings@1318
|
2645 var optCount = options.children.length;
|
nickjillings@1318
|
2646 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
|
nickjillings@1318
|
2647 var options = options.firstChild;
|
nickjillings@1318
|
2648 var text = text.firstChild;
|
nickjillings@1318
|
2649 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2650 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2651 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2652 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2653 while(options.nextSibling != undefined)
|
nickjillings@1318
|
2654 {
|
nickjillings@1318
|
2655 options = options.nextSibling;
|
nickjillings@1318
|
2656 text = text.nextSibling;
|
nickjillings@1318
|
2657 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2658 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2659 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2660 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2661 }
|
nickjillings@1318
|
2662 };
|
nickjillings@1318
|
2663 this.resize();
|
nickjillings@1318
|
2664 };
|
nickjillings@1318
|
2665
|
nickjillings@1318
|
2666 this.createCommentBox = function(audioObject) {
|
nickjillings@1318
|
2667 var node = new this.elementCommentBox(audioObject);
|
nickjillings@1318
|
2668 this.commentBoxes.push(node);
|
nickjillings@1318
|
2669 audioObject.commentDOM = node;
|
nickjillings@1318
|
2670 return node;
|
nickjillings@1318
|
2671 };
|
nickjillings@1318
|
2672
|
nickjillings@1318
|
2673 this.sortCommentBoxes = function() {
|
nickjillings@1338
|
2674 this.commentBoxes.sort(function(a,b){return a.id - b.id;});
|
nickjillings@1318
|
2675 };
|
nickjillings@1318
|
2676
|
nickjillings@1318
|
2677 this.showCommentBoxes = function(inject, sort) {
|
nickjillings@1318
|
2678 if (sort) {interfaceContext.sortCommentBoxes();}
|
nickjillings@1338
|
2679 for (var box of interfaceContext.commentBoxes) {
|
nickjillings@1338
|
2680 inject.appendChild(box.trackComment);
|
nickjillings@1318
|
2681 }
|
nickjillings@1318
|
2682 };
|
nickjillings@1318
|
2683
|
nickjillings@1318
|
2684 this.deleteCommentBoxes = function() {
|
nickjillings@1318
|
2685 this.commentBoxes = [];
|
nickjillings@1318
|
2686 };
|
nickjillings@1318
|
2687
|
nickjillings@1318
|
2688 this.createCommentQuestion = function(element) {
|
nickjillings@1318
|
2689 var node;
|
nickjillings@1324
|
2690 if (element.type == 'question') {
|
nickjillings@1318
|
2691 node = new this.commentBox(element);
|
nickjillings@1318
|
2692 } else if (element.type == 'radio') {
|
nickjillings@1318
|
2693 node = new this.radioBox(element);
|
nickjillings@1318
|
2694 } else if (element.type == 'checkbox') {
|
nickjillings@1318
|
2695 node = new this.checkboxBox(element);
|
nickjillings@1318
|
2696 }
|
nickjillings@1318
|
2697 this.commentQuestions.push(node);
|
nickjillings@1318
|
2698 return node;
|
nickjillings@1318
|
2699 };
|
nickjillings@1318
|
2700
|
nickjillings@1318
|
2701 this.deleteCommentQuestions = function()
|
nickjillings@1318
|
2702 {
|
nickjillings@1318
|
2703 this.commentQuestions = [];
|
nickjillings@1318
|
2704 };
|
nickjillings@1318
|
2705
|
nickjillings@1318
|
2706 this.playhead = new function()
|
nickjillings@1318
|
2707 {
|
nickjillings@1318
|
2708 this.object = document.createElement('div');
|
nickjillings@1318
|
2709 this.object.className = 'playhead';
|
nickjillings@1318
|
2710 this.object.align = 'left';
|
nickjillings@1318
|
2711 var curTime = document.createElement('div');
|
nickjillings@1318
|
2712 curTime.style.width = '50px';
|
nickjillings@1318
|
2713 this.curTimeSpan = document.createElement('span');
|
nickjillings@1318
|
2714 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2715 curTime.appendChild(this.curTimeSpan);
|
nickjillings@1318
|
2716 this.object.appendChild(curTime);
|
nickjillings@1318
|
2717 this.scrubberTrack = document.createElement('div');
|
nickjillings@1318
|
2718 this.scrubberTrack.className = 'playhead-scrub-track';
|
nickjillings@1318
|
2719
|
nickjillings@1318
|
2720 this.scrubberHead = document.createElement('div');
|
nickjillings@1318
|
2721 this.scrubberHead.id = 'playhead-scrubber';
|
nickjillings@1318
|
2722 this.scrubberTrack.appendChild(this.scrubberHead);
|
nickjillings@1318
|
2723 this.object.appendChild(this.scrubberTrack);
|
nickjillings@1318
|
2724
|
nickjillings@1318
|
2725 this.timePerPixel = 0;
|
nickjillings@1318
|
2726 this.maxTime = 0;
|
nickjillings@1318
|
2727
|
nickjillings@1318
|
2728 this.playbackObject;
|
nickjillings@1318
|
2729
|
nickjillings@1318
|
2730 this.setTimePerPixel = function(audioObject) {
|
nickjillings@1318
|
2731 //maxTime must be in seconds
|
nickjillings@1318
|
2732 this.playbackObject = audioObject;
|
nickjillings@1318
|
2733 this.maxTime = audioObject.buffer.buffer.duration;
|
nickjillings@1318
|
2734 var width = 490; //500 - 10, 5 each side of the tracker head
|
nickjillings@1318
|
2735 this.timePerPixel = this.maxTime/490;
|
nickjillings@1318
|
2736 if (this.maxTime < 60) {
|
nickjillings@1318
|
2737 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2738 } else {
|
nickjillings@1318
|
2739 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2740 }
|
nickjillings@1318
|
2741 };
|
nickjillings@1318
|
2742
|
nickjillings@1318
|
2743 this.update = function() {
|
nickjillings@1318
|
2744 // Update the playhead position, startPlay must be called
|
nickjillings@1318
|
2745 if (this.timePerPixel > 0) {
|
nickjillings@1318
|
2746 var time = this.playbackObject.getCurrentPosition();
|
nickjillings@1318
|
2747 if (time > 0) {
|
nickjillings@1318
|
2748 var width = 490;
|
nickjillings@1318
|
2749 var pix = Math.floor(time/this.timePerPixel);
|
nickjillings@1318
|
2750 this.scrubberHead.style.left = pix+'px';
|
nickjillings@1318
|
2751 if (this.maxTime > 60.0) {
|
nickjillings@1318
|
2752 var secs = time%60;
|
nickjillings@1318
|
2753 var mins = Math.floor((time-secs)/60);
|
nickjillings@1318
|
2754 secs = secs.toString();
|
nickjillings@1318
|
2755 secs = secs.substr(0,2);
|
nickjillings@1318
|
2756 mins = mins.toString();
|
nickjillings@1318
|
2757 this.curTimeSpan.textContent = mins+':'+secs;
|
nickjillings@1318
|
2758 } else {
|
nickjillings@1318
|
2759 time = time.toString();
|
nickjillings@1318
|
2760 this.curTimeSpan.textContent = time.substr(0,4);
|
nickjillings@1318
|
2761 }
|
nickjillings@1318
|
2762 } else {
|
nickjillings@1318
|
2763 this.scrubberHead.style.left = '0px';
|
nickjillings@1318
|
2764 if (this.maxTime < 60) {
|
nickjillings@1318
|
2765 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2766 } else {
|
nickjillings@1318
|
2767 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2768 }
|
nickjillings@1318
|
2769 }
|
nickjillings@1318
|
2770 }
|
nickjillings@1318
|
2771 };
|
nickjillings@1318
|
2772
|
nickjillings@1318
|
2773 this.interval = undefined;
|
nickjillings@1318
|
2774
|
nickjillings@1318
|
2775 this.start = function() {
|
nickjillings@1318
|
2776 if (this.playbackObject != undefined && this.interval == undefined) {
|
nickjillings@1318
|
2777 if (this.maxTime < 60) {
|
nickjillings@1318
|
2778 this.interval = setInterval(function(){interfaceContext.playhead.update();},10);
|
nickjillings@1318
|
2779 } else {
|
nickjillings@1318
|
2780 this.interval = setInterval(function(){interfaceContext.playhead.update();},100);
|
nickjillings@1318
|
2781 }
|
nickjillings@1318
|
2782 }
|
nickjillings@1318
|
2783 };
|
nickjillings@1318
|
2784 this.stop = function() {
|
nickjillings@1318
|
2785 clearInterval(this.interval);
|
nickjillings@1318
|
2786 this.interval = undefined;
|
nickjillings@1318
|
2787 if (this.maxTime < 60) {
|
nickjillings@1318
|
2788 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2789 } else {
|
nickjillings@1318
|
2790 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2791 }
|
nickjillings@1318
|
2792 };
|
nickjillings@1318
|
2793 };
|
nickjillings@1318
|
2794
|
nickjillings@1318
|
2795 // Global Checkers
|
nickjillings@1318
|
2796 // These functions will help enforce the checkers
|
nickjillings@1318
|
2797 this.checkHiddenAnchor = function()
|
nickjillings@1318
|
2798 {
|
nickjillings@1324
|
2799 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2800 {
|
nickjillings@1324
|
2801 if (ao.specification.type == "anchor")
|
nickjillings@1318
|
2802 {
|
nickjillings@1325
|
2803 if (ao.interfaceDOM.getValue() > (ao.specification.marker/100) && ao.specification.marker > 0) {
|
nickjillings@1324
|
2804 // Anchor is not set below
|
nickjillings@1324
|
2805 console.log('Anchor node not below marker value');
|
nickjillings@1324
|
2806 alert('Please keep listening');
|
nickjillings@1324
|
2807 return false;
|
nickjillings@1324
|
2808 }
|
nickjillings@1318
|
2809 }
|
nickjillings@1318
|
2810 }
|
nickjillings@1318
|
2811 return true;
|
nickjillings@1318
|
2812 };
|
nickjillings@1318
|
2813
|
nickjillings@1318
|
2814 this.checkHiddenReference = function()
|
nickjillings@1318
|
2815 {
|
nickjillings@1324
|
2816 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2817 {
|
nickjillings@1324
|
2818 if (ao.specification.type == "reference")
|
nickjillings@1318
|
2819 {
|
nickjillings@1325
|
2820 if (ao.interfaceDOM.getValue() < (ao.specification.marker/100) && ao.specification.marker > 0) {
|
nickjillings@1324
|
2821 // Anchor is not set below
|
nickjillings@1324
|
2822 console.log('Reference node not below marker value');
|
nickjillings@1324
|
2823 alert('Please keep listening');
|
nickjillings@1324
|
2824 return false;
|
nickjillings@1324
|
2825 }
|
nickjillings@1318
|
2826 }
|
nickjillings@1318
|
2827 }
|
nickjillings@1318
|
2828 return true;
|
nickjillings@1318
|
2829 };
|
nickjillings@1318
|
2830
|
nickjillings@1318
|
2831 this.checkFragmentsFullyPlayed = function ()
|
nickjillings@1318
|
2832 {
|
nickjillings@1318
|
2833 // Checks the entire file has been played back
|
nickjillings@1318
|
2834 // NOTE ! This will return true IF playback is Looped!!!
|
nickjillings@1318
|
2835 if (audioEngineContext.loopPlayback)
|
nickjillings@1318
|
2836 {
|
nickjillings@1318
|
2837 console.log("WARNING - Looped source: Cannot check fragments are fully played");
|
nickjillings@1318
|
2838 return true;
|
nickjillings@1318
|
2839 }
|
nickjillings@1318
|
2840 var check_pass = true;
|
nickjillings@1318
|
2841 var error_obj = [];
|
nickjillings@1318
|
2842 for (var i = 0; i<audioEngineContext.audioObjects.length; i++)
|
nickjillings@1318
|
2843 {
|
nickjillings@1318
|
2844 var object = audioEngineContext.audioObjects[i];
|
nickjillings@1318
|
2845 var time = object.buffer.buffer.duration;
|
nickjillings@1318
|
2846 var metric = object.metric;
|
nickjillings@1318
|
2847 var passed = false;
|
nickjillings@1318
|
2848 for (var j=0; j<metric.listenTracker.length; j++)
|
nickjillings@1318
|
2849 {
|
nickjillings@1318
|
2850 var bt = metric.listenTracker[j].getElementsByTagName('buffertime');
|
nickjillings@1318
|
2851 var start_time = Number(bt[0].getAttribute('start'));
|
nickjillings@1318
|
2852 var stop_time = Number(bt[0].getAttribute('stop'));
|
nickjillings@1318
|
2853 var delta = stop_time - start_time;
|
nickjillings@1318
|
2854 if (delta >= time)
|
nickjillings@1318
|
2855 {
|
nickjillings@1318
|
2856 passed = true;
|
nickjillings@1318
|
2857 break;
|
nickjillings@1318
|
2858 }
|
nickjillings@1318
|
2859 }
|
nickjillings@1318
|
2860 if (passed == false)
|
nickjillings@1318
|
2861 {
|
nickjillings@1318
|
2862 check_pass = false;
|
nickjillings@1340
|
2863 console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
|
nickjillings@1340
|
2864 error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2865 }
|
nickjillings@1318
|
2866 }
|
nickjillings@1318
|
2867 if (check_pass == false)
|
nickjillings@1318
|
2868 {
|
nickjillings@1318
|
2869 var str_start = "You have not completely listened to fragments ";
|
nickjillings@1318
|
2870 for (var i=0; i<error_obj.length; i++)
|
nickjillings@1318
|
2871 {
|
nickjillings@1318
|
2872 str_start += error_obj[i];
|
nickjillings@1318
|
2873 if (i != error_obj.length-1)
|
nickjillings@1318
|
2874 {
|
nickjillings@1318
|
2875 str_start += ', ';
|
nickjillings@1318
|
2876 }
|
nickjillings@1318
|
2877 }
|
nickjillings@1318
|
2878 str_start += ". Please keep listening";
|
nickjillings@1318
|
2879 console.log("[ALERT]: "+str_start);
|
nickjillings@1318
|
2880 alert(str_start);
|
nickjillings@1318
|
2881 }
|
nickjillings@1318
|
2882 };
|
nickjillings@1318
|
2883 this.checkAllMoved = function()
|
nickjillings@1318
|
2884 {
|
nickjillings@1318
|
2885 var str = "You have not moved ";
|
nickjillings@1318
|
2886 var failed = [];
|
nickjillings@1340
|
2887 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2888 {
|
nickjillings@1340
|
2889 if(ao.metric.wasMoved == false && ao.interfaceDOM.canMove() == true)
|
nickjillings@1318
|
2890 {
|
nickjillings@1340
|
2891 failed.push(ao.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2892 }
|
nickjillings@1318
|
2893 }
|
nickjillings@1318
|
2894 if (failed.length == 0)
|
nickjillings@1318
|
2895 {
|
nickjillings@1318
|
2896 return true;
|
nickjillings@1318
|
2897 } else if (failed.length == 1)
|
nickjillings@1318
|
2898 {
|
nickjillings@1318
|
2899 str += 'track '+failed[0];
|
nickjillings@1318
|
2900 } else {
|
nickjillings@1318
|
2901 str += 'tracks ';
|
nickjillings@1318
|
2902 for (var i=0; i<failed.length-1; i++)
|
nickjillings@1318
|
2903 {
|
nickjillings@1318
|
2904 str += failed[i]+', ';
|
nickjillings@1318
|
2905 }
|
nickjillings@1318
|
2906 str += 'and '+failed[i];
|
nickjillings@1318
|
2907 }
|
nickjillings@1318
|
2908 str +='.';
|
nickjillings@1318
|
2909 alert(str);
|
nickjillings@1318
|
2910 console.log(str);
|
nickjillings@1318
|
2911 return false;
|
nickjillings@1318
|
2912 };
|
nickjillings@1318
|
2913 this.checkAllPlayed = function()
|
nickjillings@1318
|
2914 {
|
nickjillings@1318
|
2915 var str = "You have not played ";
|
nickjillings@1318
|
2916 var failed = [];
|
nickjillings@1340
|
2917 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2918 {
|
nickjillings@1340
|
2919 if(ao.metric.wasListenedTo == false)
|
nickjillings@1318
|
2920 {
|
nickjillings@1340
|
2921 failed.push(ao.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2922 }
|
nickjillings@1318
|
2923 }
|
nickjillings@1318
|
2924 if (failed.length == 0)
|
nickjillings@1318
|
2925 {
|
nickjillings@1318
|
2926 return true;
|
nickjillings@1318
|
2927 } else if (failed.length == 1)
|
nickjillings@1318
|
2928 {
|
nickjillings@1318
|
2929 str += 'track '+failed[0];
|
nickjillings@1318
|
2930 } else {
|
nickjillings@1318
|
2931 str += 'tracks ';
|
nickjillings@1318
|
2932 for (var i=0; i<failed.length-1; i++)
|
nickjillings@1318
|
2933 {
|
nickjillings@1318
|
2934 str += failed[i]+', ';
|
nickjillings@1318
|
2935 }
|
nickjillings@1318
|
2936 str += 'and '+failed[i];
|
nickjillings@1318
|
2937 }
|
nickjillings@1318
|
2938 str +='.';
|
nickjillings@1318
|
2939 alert(str);
|
nickjillings@1318
|
2940 console.log(str);
|
nickjillings@1318
|
2941 return false;
|
nickjillings@1318
|
2942 };
|
nickjillings@1324
|
2943 }
|
nickjillings@1324
|
2944
|
nickjillings@1324
|
2945 function Storage()
|
nickjillings@1324
|
2946 {
|
nickjillings@1324
|
2947 // Holds results in XML format until ready for collection
|
nickjillings@1324
|
2948 this.globalPreTest = null;
|
nickjillings@1324
|
2949 this.globalPostTest = null;
|
nickjillings@1324
|
2950 this.testPages = [];
|
nickjillings@1324
|
2951 this.document = document.implementation.createDocument(null,"waetresult");
|
nickjillings@1324
|
2952 this.root = this.document.children[0];
|
nickjillings@1324
|
2953 this.state = 0;
|
nickjillings@1324
|
2954
|
nickjillings@1324
|
2955 this.initialise = function()
|
nickjillings@1324
|
2956 {
|
nickjillings@1342
|
2957 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);}
|
nickjillings@1342
|
2958 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);}
|
nickjillings@1324
|
2959 };
|
nickjillings@1324
|
2960
|
nickjillings@1324
|
2961 this.createTestPageStore = function(specification)
|
nickjillings@1324
|
2962 {
|
nickjillings@1324
|
2963 var store = new this.pageNode(this,specification);
|
nickjillings@1324
|
2964 this.testPages.push(store);
|
nickjillings@1324
|
2965 return this.testPages[this.testPages.length-1];
|
nickjillings@1324
|
2966 };
|
nickjillings@1324
|
2967
|
nickjillings@1324
|
2968 this.surveyNode = function(parent,root,specification)
|
nickjillings@1324
|
2969 {
|
nickjillings@1324
|
2970 this.specification = specification;
|
nickjillings@1324
|
2971 this.parent = parent;
|
nickjillings@1324
|
2972 this.XMLDOM = this.parent.document.createElement('survey');
|
nickjillings@1324
|
2973 this.XMLDOM.setAttribute('location',this.specification.location);
|
nickjillings@1324
|
2974 for (var optNode of this.specification.options)
|
nickjillings@1324
|
2975 {
|
nickjillings@1324
|
2976 if (optNode.type != 'statement')
|
nickjillings@1324
|
2977 {
|
nickjillings@1324
|
2978 var node = this.parent.document.createElement('surveyresult');
|
nickjillings@1324
|
2979 node.id = optNode.id;
|
nickjillings@1324
|
2980 node.setAttribute('type',optNode.type);
|
nickjillings@1324
|
2981 this.XMLDOM.appendChild(node);
|
nickjillings@1324
|
2982 }
|
nickjillings@1324
|
2983 }
|
nickjillings@1324
|
2984 root.appendChild(this.XMLDOM);
|
nickjillings@1324
|
2985
|
nickjillings@1324
|
2986 this.postResult = function(node)
|
nickjillings@1324
|
2987 {
|
nickjillings@1324
|
2988 // From popup: node is the popupOption node containing both spec. and results
|
nickjillings@1324
|
2989 // ID is the position
|
nickjillings@1324
|
2990 if (node.specification.type == 'statement'){return;}
|
nickjillings@1324
|
2991 var surveyresult = this.parent.document.getElementById(node.specification.id);
|
nickjillings@1324
|
2992 switch(node.specification.type)
|
nickjillings@1324
|
2993 {
|
nickjillings@1324
|
2994 case "number":
|
nickjillings@1324
|
2995 case "question":
|
nickjillings@1324
|
2996 var child = this.parent.document.createElement('response');
|
nickjillings@1324
|
2997 child.textContent = node.response;
|
nickjillings@1324
|
2998 surveyresult.appendChild(child);
|
nickjillings@1324
|
2999 break;
|
nickjillings@1324
|
3000 case "radio":
|
nickjillings@1324
|
3001 var child = this.parent.document.createElement('response');
|
nickjillings@1324
|
3002 child.setAttribute('name',node.response.name);
|
nickjillings@1324
|
3003 child.textContent = node.response.text;
|
nickjillings@1324
|
3004 surveyresult.appendChild(child);
|
nickjillings@1324
|
3005 break;
|
nickjillings@1324
|
3006 case "checkbox":
|
nickjillings@1324
|
3007 for (var i=0; i<node.response.length; i++)
|
nickjillings@1324
|
3008 {
|
nickjillings@1324
|
3009 var checkNode = this.parent.document.createElement('response');
|
nickjillings@1347
|
3010 checkNode.setAttribute('name',node.response[i].name);
|
nickjillings@1347
|
3011 checkNode.setAttribute('checked',node.response[i].checked);
|
nickjillings@1326
|
3012 surveyresult.appendChild(checkNode);
|
nickjillings@1324
|
3013 }
|
nickjillings@1324
|
3014 break;
|
nickjillings@1324
|
3015 }
|
nickjillings@1324
|
3016 };
|
nickjillings@1324
|
3017 };
|
nickjillings@1324
|
3018
|
nickjillings@1324
|
3019 this.pageNode = function(parent,specification)
|
nickjillings@1324
|
3020 {
|
nickjillings@1324
|
3021 // Create one store per test page
|
nickjillings@1324
|
3022 this.specification = specification;
|
nickjillings@1324
|
3023 this.parent = parent;
|
nickjillings@1324
|
3024 this.XMLDOM = this.parent.document.createElement('page');
|
nickjillings@1324
|
3025 this.XMLDOM.setAttribute('id',specification.id);
|
nickjillings@1324
|
3026 this.XMLDOM.setAttribute('presentedId',specification.presentedId);
|
nickjillings@1345
|
3027 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);}
|
nickjillings@1345
|
3028 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);}
|
nickjillings@1324
|
3029
|
nickjillings@1324
|
3030 // Add any page metrics
|
nickjillings@1324
|
3031 var page_metric = this.parent.document.createElement('metric');
|
nickjillings@1324
|
3032 this.XMLDOM.appendChild(page_metric);
|
nickjillings@1324
|
3033
|
nickjillings@1324
|
3034 // Add the audioelement
|
nickjillings@1324
|
3035 for (var element of this.specification.audioElements)
|
nickjillings@1324
|
3036 {
|
nickjillings@1324
|
3037 var aeNode = this.parent.document.createElement('audioelement');
|
nickjillings@1324
|
3038 aeNode.id = element.id;
|
nickjillings@1324
|
3039 aeNode.setAttribute('type',element.type);
|
nickjillings@1324
|
3040 aeNode.setAttribute('url', element.url);
|
nickjillings@1324
|
3041 aeNode.setAttribute('gain', element.gain);
|
nickjillings@1324
|
3042 if (element.type == 'anchor' || element.type == 'reference')
|
nickjillings@1324
|
3043 {
|
nickjillings@1324
|
3044 if (element.marker > 0)
|
nickjillings@1324
|
3045 {
|
nickjillings@1324
|
3046 aeNode.setAttribute('marker',element.marker);
|
nickjillings@1324
|
3047 }
|
nickjillings@1324
|
3048 }
|
nickjillings@1324
|
3049 var ae_metric = this.parent.document.createElement('metric');
|
nickjillings@1324
|
3050 aeNode.appendChild(ae_metric);
|
nickjillings@1324
|
3051 this.XMLDOM.appendChild(aeNode);
|
nickjillings@1324
|
3052 }
|
nickjillings@1324
|
3053
|
nickjillings@1324
|
3054 // Add any commentQuestions
|
nickjillings@1324
|
3055 for (var element of this.specification.commentQuestions)
|
nickjillings@1324
|
3056 {
|
nickjillings@1324
|
3057 var cqNode = this.parent.document.createElement('commentquestion');
|
nickjillings@1324
|
3058 cqNode.id = element.id;
|
nickjillings@1324
|
3059 cqNode.setAttribute('type',element.type);
|
nickjillings@1324
|
3060 var statement = this.parent.document.createElement('statement');
|
nickjillings@1324
|
3061 statement.textContent = cqNode.statement;
|
nickjillings@1324
|
3062 cqNode.appendChild(statement);
|
nickjillings@1324
|
3063 var response = this.parent.document.createElement('response');
|
nickjillings@1324
|
3064 cqNode.appendChild(response);
|
nickjillings@1324
|
3065 this.XMLDOM.appendChild(cqNode);
|
nickjillings@1324
|
3066 }
|
nickjillings@1324
|
3067
|
nickjillings@1324
|
3068 this.parent.root.appendChild(this.XMLDOM);
|
nickjillings@1324
|
3069 };
|
nickjillings@1324
|
3070 this.finish = function()
|
nickjillings@1324
|
3071 {
|
nickjillings@1324
|
3072 if (this.state == 0)
|
nickjillings@1324
|
3073 {
|
nickjillings@1324
|
3074 var projectDocument = specification.projectXML;
|
nickjillings@1324
|
3075 projectDocument.setAttribute('file-name',url);
|
nickjillings@1324
|
3076 this.root.appendChild(projectDocument);
|
nickjillings@1324
|
3077 this.root.appendChild(returnDateNode());
|
nickjillings@1324
|
3078 this.root.appendChild(interfaceContext.returnNavigator());
|
nickjillings@1324
|
3079 }
|
nickjillings@1324
|
3080 this.state = 1;
|
nickjillings@1324
|
3081 return this.root;
|
nickjillings@1324
|
3082 };
|
nickjillings@1324
|
3083 }
|