nickjillings@2161
|
1 /**
|
nickjillings@2161
|
2 * WAET Blank Template
|
nickjillings@2161
|
3 * Use this to start building your custom interface
|
nickjillings@2161
|
4 */
|
nickjillings@2161
|
5
|
nickjillings@2161
|
6 // Once this is loaded and parsed, begin execution
|
nickjillings@2161
|
7 loadInterface();
|
nickjillings@2161
|
8
|
nickjillings@2161
|
9 function loadInterface() {
|
nickjillings@2161
|
10 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects,
|
nickjillings@2161
|
11 // holding div's, or setting up any nodes which are present for the entire test sequence
|
nickjillings@2161
|
12
|
nicholas@2381
|
13 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
|
nickjillings@2163
|
14
|
nicholas@2359
|
15 Interface.prototype.checkScaleRange = function(min, max) {
|
nicholas@2359
|
16 var page = testState.getCurrentTestPage();
|
nicholas@2359
|
17 var audioObjects = audioEngineContext.audioObjects;
|
nicholas@2359
|
18 var state = true;
|
nicholas@2359
|
19 var str = "Please keep listening. ";
|
nicholas@2359
|
20 var minRanking = Infinity;
|
nicholas@2359
|
21 var maxRanking = -Infinity;
|
nicholas@2359
|
22 for (var ao of audioObjects) {
|
nicholas@2359
|
23 var rank = ao.interfaceDOM.getValue();
|
nicholas@2359
|
24 if (rank < minRanking) {minRanking = rank;}
|
nicholas@2359
|
25 if (rank > maxRanking) {maxRanking = rank;}
|
nicholas@2359
|
26 }
|
nicholas@2359
|
27 if (maxRanking*100 < max) {
|
nicholas@2359
|
28 str += "At least one fragment must be selected."
|
nicholas@2359
|
29 state = false;
|
nicholas@2359
|
30 }
|
nicholas@2359
|
31 if (!state) {
|
nicholas@2359
|
32 console.log(str);
|
nicholas@2359
|
33 this.storeErrorNode(str);
|
nicholas@2362
|
34 interfaceContext.lightbox.post("Message",str);
|
nicholas@2359
|
35 }
|
nicholas@2359
|
36 return state;
|
nicholas@2359
|
37 }
|
nicholas@2359
|
38
|
nickjillings@2161
|
39 // Custom comparator Object
|
nickjillings@2161
|
40 Interface.prototype.comparator = null;
|
nickjillings@2161
|
41
|
nickjillings@2161
|
42 // The injection point into the HTML page
|
nickjillings@2161
|
43 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@2161
|
44 var testContent = document.createElement('div');
|
nickjillings@2161
|
45 testContent.id = 'testContent';
|
nickjillings@2161
|
46
|
nickjillings@2161
|
47 // Create the top div for the Title element
|
nickjillings@2161
|
48 var titleAttr = specification.title;
|
nickjillings@2161
|
49 var title = document.createElement('div');
|
nickjillings@2161
|
50 title.className = "title";
|
nickjillings@2161
|
51 title.align = "center";
|
nickjillings@2161
|
52 var titleSpan = document.createElement('span');
|
nicholas@2470
|
53 titleSpan.id = "test-title";
|
nickjillings@2161
|
54
|
nickjillings@2161
|
55 // Set title to that defined in XML, else set to default
|
nickjillings@2161
|
56 if (titleAttr != undefined) {
|
nickjillings@2161
|
57 titleSpan.textContent = titleAttr;
|
nickjillings@2161
|
58 } else {
|
nickjillings@2161
|
59 titleSpan.textContent = 'Listening test';
|
nickjillings@2161
|
60 }
|
nickjillings@2161
|
61 // Insert the titleSpan element into the title div element.
|
nickjillings@2161
|
62 title.appendChild(titleSpan);
|
nickjillings@2161
|
63
|
nickjillings@2161
|
64 var pagetitle = document.createElement('div');
|
nickjillings@2161
|
65 pagetitle.className = "pageTitle";
|
nickjillings@2161
|
66 pagetitle.align = "center";
|
nickjillings@2161
|
67 var titleSpan = document.createElement('span');
|
nickjillings@2161
|
68 titleSpan.id = "pageTitle";
|
nickjillings@2161
|
69 pagetitle.appendChild(titleSpan);
|
nickjillings@2161
|
70
|
nickjillings@2161
|
71 // Create Interface buttons!
|
nickjillings@2161
|
72 var interfaceButtons = document.createElement('div');
|
nickjillings@2161
|
73 interfaceButtons.id = 'interface-buttons';
|
nickjillings@2161
|
74 interfaceButtons.style.height = '25px';
|
nickjillings@2161
|
75
|
nickjillings@2161
|
76 // Create playback start/stop points
|
nickjillings@2161
|
77 var playback = document.createElement("button");
|
nickjillings@2161
|
78 playback.innerHTML = 'Stop';
|
nickjillings@2161
|
79 playback.id = 'playback-button';
|
nickjillings@2161
|
80 playback.style.float = 'left';
|
nickjillings@2161
|
81 // onclick function. Check if it is playing or not, call the correct function in the
|
nickjillings@2161
|
82 // audioEngine, change the button text to reflect the next state.
|
nickjillings@2161
|
83 playback.onclick = function() {
|
nickjillings@2161
|
84 if (audioEngineContext.status == 1) {
|
nickjillings@2161
|
85 audioEngineContext.stop();
|
nickjillings@2161
|
86 this.innerHTML = 'Stop';
|
nickjillings@2161
|
87 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@2161
|
88 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nickjillings@2161
|
89 }
|
nickjillings@2161
|
90 };
|
nickjillings@2161
|
91 // Append the interface buttons into the interfaceButtons object.
|
nickjillings@2161
|
92 interfaceButtons.appendChild(playback);
|
nickjillings@2161
|
93
|
nickjillings@2161
|
94 // Global parent for the comment boxes on the page
|
nickjillings@2161
|
95 var feedbackHolder = document.createElement('div');
|
nickjillings@2161
|
96 feedbackHolder.id = 'feedbackHolder';
|
nickjillings@2161
|
97
|
nickjillings@2161
|
98 // Construct the AB Boxes
|
nickjillings@2161
|
99 var boxes = document.createElement('div');
|
nickjillings@2161
|
100 boxes.align = "center";
|
nickjillings@2161
|
101 boxes.id = "box-holders";
|
nickjillings@2161
|
102 boxes.style.float = "left";
|
nickjillings@2161
|
103
|
nickjillings@2161
|
104 var submit = document.createElement('button');
|
nickjillings@2161
|
105 submit.id = "submit";
|
nickjillings@2161
|
106 submit.onclick = buttonSubmitClick;
|
nickjillings@2161
|
107 submit.className = "big-button";
|
nickjillings@2161
|
108 submit.textContent = "submit";
|
nickjillings@2161
|
109 submit.style.position = "relative";
|
nickjillings@2161
|
110 submit.style.left = (window.innerWidth-250)/2 + 'px';
|
nickjillings@2161
|
111
|
nickjillings@2161
|
112 feedbackHolder.appendChild(boxes);
|
nickjillings@2161
|
113
|
nickjillings@2161
|
114 // Inject into HTML
|
nickjillings@2161
|
115 testContent.appendChild(title); // Insert the title
|
nickjillings@2161
|
116 testContent.appendChild(pagetitle);
|
nickjillings@2161
|
117 testContent.appendChild(interfaceButtons);
|
nickjillings@2161
|
118 testContent.appendChild(feedbackHolder);
|
nickjillings@2161
|
119 testContent.appendChild(submit);
|
nickjillings@2161
|
120 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@2161
|
121
|
nickjillings@2161
|
122 // Load the full interface
|
nickjillings@2161
|
123 testState.initialise();
|
nickjillings@2161
|
124 testState.advanceState();
|
nickjillings@2161
|
125 };
|
nickjillings@2161
|
126
|
nickjillings@2161
|
127 function loadTest(page)
|
nickjillings@2161
|
128 {
|
nickjillings@2161
|
129 // Called each time a new test page is to be build. The page specification node is the only item passed in
|
nicholas@2381
|
130 document.getElementById('box-holders').innerHTML = "";
|
nickjillings@2163
|
131
|
nickjillings@2163
|
132 var interfaceObj = page.interfaces;
|
nickjillings@2163
|
133 if (interfaceObj.length > 1)
|
nickjillings@2163
|
134 {
|
nickjillings@2163
|
135 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
|
nickjillings@2163
|
136 }
|
nickjillings@2163
|
137 interfaceObj = interfaceObj[0];
|
nicholas@2470
|
138
|
nicholas@2470
|
139 // Set the page title
|
nicholas@2470
|
140 if (typeof page.title == "string" && page.title.length > 0) {
|
nicholas@2470
|
141 document.getElementById("test-title").textContent = page.title
|
nicholas@2470
|
142 }
|
nickjillings@2163
|
143
|
nickjillings@2163
|
144 if(interfaceObj.title != null)
|
nickjillings@2163
|
145 {
|
nickjillings@2163
|
146 document.getElementById("pageTitle").textContent = interfaceObj.title;
|
nickjillings@2163
|
147 }
|
nickjillings@2163
|
148
|
nicholas@2469
|
149 interfaceContext.comparator = new comparator(page);
|
nicholas@2469
|
150
|
nickjillings@2163
|
151 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
|
nickjillings@2163
|
152 for (var option of interfaceOptions)
|
nickjillings@2163
|
153 {
|
nickjillings@2163
|
154 if (option.type == "show")
|
nickjillings@2163
|
155 {
|
nickjillings@2163
|
156 switch(option.name) {
|
nickjillings@2163
|
157 case "playhead":
|
nickjillings@2163
|
158 var playbackHolder = document.getElementById('playback-holder');
|
nickjillings@2163
|
159 if (playbackHolder == null)
|
nickjillings@2163
|
160 {
|
nickjillings@2163
|
161 playbackHolder = document.createElement('div');
|
nickjillings@2163
|
162 playbackHolder.style.width = "100%";
|
nickjillings@2163
|
163 playbackHolder.style.float = "left";
|
nickjillings@2163
|
164 playbackHolder.align = 'center';
|
nickjillings@2163
|
165 playbackHolder.appendChild(interfaceContext.playhead.object);
|
nickjillings@2163
|
166 feedbackHolder.appendChild(playbackHolder);
|
nickjillings@2163
|
167 }
|
nickjillings@2163
|
168 break;
|
nickjillings@2163
|
169 case "page-count":
|
nickjillings@2163
|
170 var pagecountHolder = document.getElementById('page-count');
|
nickjillings@2163
|
171 if (pagecountHolder == null)
|
nickjillings@2163
|
172 {
|
nickjillings@2163
|
173 pagecountHolder = document.createElement('div');
|
nickjillings@2163
|
174 pagecountHolder.id = 'page-count';
|
nickjillings@2163
|
175 }
|
nickjillings@2163
|
176 pagecountHolder.innerHTML = '<span>Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+'</span>';
|
nickjillings@2163
|
177 var inject = document.getElementById('interface-buttons');
|
nickjillings@2163
|
178 inject.appendChild(pagecountHolder);
|
nickjillings@2163
|
179 break;
|
nickjillings@2163
|
180 case "volume":
|
nickjillings@2163
|
181 if (document.getElementById('master-volume-holder') == null)
|
nickjillings@2163
|
182 {
|
nickjillings@2163
|
183 feedbackHolder.appendChild(interfaceContext.volume.object);
|
nickjillings@2163
|
184 }
|
nickjillings@2163
|
185 break;
|
nicholas@2469
|
186 case "comments":
|
nicholas@2469
|
187 var commentHolder = document.createElement('div');
|
nicholas@2469
|
188 commentHolder.id = 'commentHolder';
|
nicholas@2469
|
189 document.getElementById('testContent').appendChild(commentHolder);
|
nicholas@2469
|
190 // Generate one comment box per presented page
|
nicholas@2469
|
191 for (var element of audioEngineContext.audioObjects)
|
nicholas@2469
|
192 {
|
nicholas@2469
|
193 interfaceContext.commentBoxes.createCommentBox(element);
|
nicholas@2469
|
194 }
|
nicholas@2469
|
195 interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true);
|
nicholas@2469
|
196 break;
|
nickjillings@2163
|
197 }
|
nickjillings@2163
|
198 }
|
nickjillings@2163
|
199 }
|
nickjillings@2163
|
200
|
nicholas@2469
|
201 $(page.commentQuestions).each(function(index,element) {
|
nicholas@2469
|
202 var node = interfaceContext.createCommentQuestion(element);
|
nicholas@2469
|
203 document.getElementById('testContent').appendChild(node.holder);
|
nicholas@2469
|
204 });
|
nicholas@2469
|
205
|
nickjillings@2163
|
206 resizeWindow(null);
|
nickjillings@2161
|
207 }
|
nickjillings@2161
|
208
|
nickjillings@2161
|
209 function comparator(page)
|
nickjillings@2161
|
210 {
|
nickjillings@2161
|
211 // Build prototype constructor
|
nickjillings@2161
|
212 this.interfaceObject = function(element,label)
|
nickjillings@2161
|
213 {
|
nickjillings@2161
|
214 // An example node, you can make this however you want for each audioElement.
|
nickjillings@2161
|
215 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following
|
nickjillings@2161
|
216 // You attach them by calling audioObject.bindInterface( )
|
nickjillings@2161
|
217 this.parent = element;
|
nickjillings@2161
|
218 this.id = element.id;
|
nickjillings@2161
|
219 this.value = 0;
|
nickjillings@2161
|
220 this.disabled = true;
|
nickjillings@2161
|
221 this.box = document.createElement('div');
|
nickjillings@2161
|
222 this.box.className = 'comparator-holder';
|
nickjillings@2161
|
223 this.box.setAttribute('track-id',element.id);
|
nickjillings@2161
|
224 this.box.id = 'comparator-'+label;
|
nickjillings@2161
|
225 this.selector = document.createElement('div');
|
nickjillings@2161
|
226 this.selector.className = 'comparator-selector disabled';
|
nickjillings@2161
|
227 var selectorText = document.createElement('span');
|
nickjillings@2161
|
228 selectorText.textContent = label;
|
nickjillings@2161
|
229 this.selector.appendChild(selectorText);
|
nickjillings@2161
|
230 this.playback = document.createElement('button');
|
nickjillings@2161
|
231 this.playback.className = 'comparator-button';
|
nickjillings@2161
|
232 this.playback.disabled = true;
|
nickjillings@2161
|
233 this.playback.textContent = "Listen";
|
nickjillings@2161
|
234 this.box.appendChild(this.selector);
|
nickjillings@2161
|
235 this.box.appendChild(this.playback);
|
nickjillings@2161
|
236 this.selector.onclick = function(event)
|
nickjillings@2161
|
237 {
|
nickjillings@2161
|
238 var label = event.currentTarget.children[0].textContent;
|
nickjillings@2161
|
239 if (label == "X" || label == "x") {return;}
|
nickjillings@2161
|
240 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@2161
|
241 if ($(event.currentTarget).hasClass('disabled'))
|
nickjillings@2161
|
242 {
|
nickjillings@2161
|
243 console.log("Please wait until sample has loaded");
|
nickjillings@2161
|
244 return;
|
nickjillings@2161
|
245 }
|
nickjillings@2161
|
246 if (audioEngineContext.status == 0)
|
nickjillings@2161
|
247 {
|
nicholas@2362
|
248 interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection");
|
nickjillings@2161
|
249 console.log("Please listen to the samples before making a selection");
|
nickjillings@2161
|
250 return;
|
nickjillings@2161
|
251 }
|
nickjillings@2161
|
252 var id = event.currentTarget.parentElement.getAttribute('track-id');
|
nickjillings@2161
|
253 interfaceContext.comparator.selected = id;
|
nickjillings@2161
|
254 if ($(event.currentTarget).hasClass("selected")) {
|
nickjillings@2161
|
255 $(".comparator-selector").removeClass('selected');
|
giuliomoro@2291
|
256 for (var i=0; i<interfaceContext.comparator.pair.length; i++)
|
nickjillings@2161
|
257 {
|
nicholas@2308
|
258 var obj = interfaceContext.comparator.pair[i];
|
nickjillings@2161
|
259 obj.parent.metric.moved(time,0);
|
nicholas@2308
|
260 obj.value = 0;
|
nickjillings@2161
|
261 }
|
nickjillings@2161
|
262 } else {
|
nickjillings@2161
|
263 $(".comparator-selector").removeClass('selected');
|
nickjillings@2161
|
264 $(event.currentTarget).addClass('selected');
|
giuliomoro@2291
|
265 for (var i=0; i<interfaceContext.comparator.pair.length; i++)
|
nickjillings@2161
|
266 {
|
giuliomoro@2291
|
267 var obj = interfaceContext.comparator.pair[i];
|
nickjillings@2161
|
268 if (i == id) {
|
nickjillings@2161
|
269 obj.value = 1;
|
nickjillings@2161
|
270 } else {
|
nickjillings@2161
|
271 obj.value = 0;
|
nickjillings@2161
|
272 }
|
nickjillings@2161
|
273 obj.parent.metric.moved(time,obj.value);
|
nickjillings@2161
|
274 }
|
nickjillings@2161
|
275 console.log("Selected "+id+' ('+time+')');
|
nickjillings@2161
|
276 }
|
nickjillings@2161
|
277 };
|
nickjillings@2161
|
278 this.playback.setAttribute("playstate","ready");
|
nickjillings@2161
|
279 this.playback.onclick = function(event)
|
nickjillings@2161
|
280 {
|
nickjillings@2161
|
281 var id = event.currentTarget.parentElement.getAttribute('track-id');
|
nickjillings@2161
|
282 if (event.currentTarget.getAttribute("playstate") == "ready")
|
nickjillings@2161
|
283 {
|
nickjillings@2161
|
284 audioEngineContext.play(id);
|
nickjillings@2161
|
285 } else if (event.currentTarget.getAttribute("playstate") == "playing") {
|
nickjillings@2161
|
286 audioEngineContext.stop();
|
nickjillings@2161
|
287 }
|
nickjillings@2161
|
288
|
nickjillings@2161
|
289 };
|
nickjillings@2161
|
290 this.enable = function()
|
nickjillings@2161
|
291 {
|
nickjillings@2161
|
292 // This is used to tell the interface object that playback of this node is ready
|
nickjillings@2161
|
293 if (this.parent.state == 1)
|
nickjillings@2161
|
294 {
|
nickjillings@2161
|
295 $(this.selector).removeClass('disabled');
|
nickjillings@2161
|
296 this.playback.disabled = false;
|
nickjillings@2161
|
297 }
|
nickjillings@2161
|
298 };
|
nickjillings@2161
|
299 this.updateLoading = function(progress)
|
nickjillings@2161
|
300 {
|
nickjillings@2161
|
301 // progress is a value from 0 to 100 indicating the current download state of media files
|
nickjillings@2161
|
302 if (progress != 100)
|
nickjillings@2161
|
303 {
|
nickjillings@2161
|
304 progress = String(progress);
|
nickjillings@2161
|
305 progress = progress.split('.')[0];
|
nickjillings@2161
|
306 this.playback.textContent = progress+'%';
|
nickjillings@2161
|
307 } else {
|
nickjillings@2161
|
308 this.playback.textContent = "Play";
|
nickjillings@2161
|
309 }
|
nickjillings@2161
|
310 };
|
nickjillings@2161
|
311 this.error = function() {
|
nickjillings@2161
|
312 // audioObject has an error!!
|
nickjillings@2161
|
313 this.playback.textContent = "Error";
|
nickjillings@2161
|
314 $(this.playback).addClass("error-colour");
|
nickjillings@2161
|
315 };
|
nickjillings@2161
|
316 this.startPlayback = function()
|
nickjillings@2161
|
317 {
|
n@2428
|
318 if (this.parent.specification.parent.playOne || specification.playOne) {
|
n@2428
|
319 $('.comparator-button').text('Wait');
|
n@2428
|
320 $('.comparator-button').attr("disabled","true");
|
n@2428
|
321 $(this.playback).css("disabled","false");
|
n@2428
|
322 } else {
|
n@2428
|
323 $('.comparator-button').text('Listen');
|
n@2428
|
324 }
|
nickjillings@2161
|
325 $(this.playback).text('Stop');
|
nickjillings@2161
|
326 this.playback.setAttribute("playstate","playing");
|
nickjillings@2161
|
327 };
|
nickjillings@2161
|
328 this.stopPlayback = function()
|
nickjillings@2161
|
329 {
|
n@2428
|
330 if (this.playback.getAttribute("playstate") == "playing") {
|
n@2428
|
331 $('.comparator-button').text('Listen');
|
n@2428
|
332 $('.comparator-button').removeAttr("disabled");
|
n@2428
|
333 this.playback.setAttribute("playstate","ready");
|
n@2428
|
334 }
|
nickjillings@2161
|
335 };
|
nickjillings@2161
|
336 this.getValue = function()
|
nickjillings@2161
|
337 {
|
nickjillings@2161
|
338 // Return the current value of the object. If there is no value, return 0
|
nickjillings@2161
|
339 return this.value;
|
nickjillings@2161
|
340 };
|
nickjillings@2161
|
341 this.getPresentedId = function()
|
nickjillings@2161
|
342 {
|
nickjillings@2161
|
343 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale
|
nickjillings@2161
|
344 return this.selector.children[0].textContent;
|
nickjillings@2161
|
345 };
|
nickjillings@2161
|
346 this.canMove = function()
|
nickjillings@2161
|
347 {
|
nickjillings@2161
|
348 // Return either true or false if the interface object can be moved. AB / Reference cannot, whilst sliders can and therefore have a continuous scale.
|
nickjillings@2161
|
349 // These are checked primarily if the interface check option 'fragmentMoved' is enabled.
|
nickjillings@2161
|
350 return false;
|
nickjillings@2161
|
351 };
|
nickjillings@2161
|
352 this.exportXMLDOM = function(audioObject) {
|
nickjillings@2161
|
353 // Called by the audioObject holding this element to export the interface <value> node.
|
nickjillings@2161
|
354 // If there is no value node (such as outside reference), return null
|
nickjillings@2161
|
355 // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute
|
nickjillings@2161
|
356 // Use storage.document.createElement('value'); to generate the XML node.
|
nickjillings@2161
|
357 var node = storage.document.createElement('value');
|
nickjillings@2161
|
358 node.textContent = this.value;
|
nickjillings@2161
|
359 return node;
|
nickjillings@2161
|
360
|
nickjillings@2161
|
361 };
|
nickjillings@2161
|
362 this.error = function() {
|
nickjillings@2161
|
363 // If there is an error with the audioObject, this will be called to indicate a failure
|
nickjillings@2161
|
364 }
|
nickjillings@2161
|
365 };
|
nickjillings@2161
|
366 // Ensure there are only two comparisons per page
|
nickjillings@2161
|
367 if (page.audioElements.length != 2) {
|
nickjillings@2161
|
368 console.error('FATAL - There must be 2 <audioelement> nodes on each <page>: '+page.id);
|
nickjillings@2161
|
369 return;
|
nickjillings@2161
|
370 }
|
nickjillings@2161
|
371 // Build the three audio elements
|
nickjillings@2161
|
372 this.pair = [];
|
nickjillings@2161
|
373 this.X = null;
|
nickjillings@2161
|
374 this.boxHolders = document.getElementById('box-holders');
|
nickjillings@2161
|
375 for (var index=0; index<page.audioElements.length; index++) {
|
nickjillings@2161
|
376 var element = page.audioElements[index];
|
nickjillings@2161
|
377 if (element.type != 'normal')
|
nickjillings@2161
|
378 {
|
nickjillings@2161
|
379 console.log("WARNING - ABX can only have normal elements. Page "+page.id+", Element "+element.id);
|
nickjillings@2161
|
380 element.type = "normal";
|
nickjillings@2161
|
381 }
|
nickjillings@2161
|
382 var audioObject = audioEngineContext.newTrack(element);
|
nickjillings@2161
|
383 var label;
|
nickjillings@2161
|
384 switch(audioObject.specification.parent.label) {
|
nickjillings@2161
|
385 case "none":
|
nickjillings@2161
|
386 label = "";
|
nickjillings@2161
|
387 break;
|
nickjillings@2161
|
388 case "number":
|
nickjillings@2161
|
389 label = ""+index;
|
nickjillings@2161
|
390 break;
|
nickjillings@2161
|
391 case "letter":
|
nickjillings@2161
|
392 label = String.fromCharCode(97 + index);
|
nickjillings@2161
|
393 break;
|
nickjillings@2161
|
394 default:
|
nickjillings@2161
|
395 label = String.fromCharCode(65 + index);
|
nickjillings@2161
|
396 break;
|
nickjillings@2161
|
397 }
|
nickjillings@2161
|
398 var node = new this.interfaceObject(audioObject,label);
|
nickjillings@2161
|
399 audioObject.bindInterface(node);
|
nickjillings@2161
|
400 this.pair.push(node);
|
nickjillings@2161
|
401 this.boxHolders.appendChild(node.box);
|
nickjillings@2161
|
402 }
|
nickjillings@2161
|
403 var elementId = Math.floor(Math.random() * 2); //Randomly pick A or B to be X
|
giuliomoro@2291
|
404 var element = new page.audioElementNode(specification);
|
nickjillings@2161
|
405 for (var atr in page.audioElements[elementId]) {
|
nickjillings@2161
|
406 eval("element."+atr+" = page.audioElements[elementId]."+atr);
|
nickjillings@2161
|
407 }
|
nickjillings@2161
|
408 element.id += "-X";
|
nickjillings@2161
|
409 if (typeof element.name == "string") {element.name+="-X";}
|
nickjillings@2161
|
410 page.audioElements.push(element);
|
nickjillings@2161
|
411 // Create the save place-holder for the 'X' element
|
nickjillings@2161
|
412 var root = testState.currentStore.XMLDOM;
|
nickjillings@2161
|
413 var aeNode = storage.document.createElement('audioelement');
|
nickjillings@2161
|
414 aeNode.setAttribute('ref',element.id);
|
nickjillings@2161
|
415 if (typeof element.name == "string"){aeNode.setAttribute('name',element.name);}
|
nickjillings@2161
|
416 aeNode.setAttribute('type','normal');
|
nickjillings@2161
|
417 aeNode.setAttribute('url',element.url);
|
nickjillings@2161
|
418 aeNode.setAttribute('gain',element.gain);
|
nickjillings@2161
|
419 aeNode.appendChild(storage.document.createElement('metric'));
|
nickjillings@2161
|
420 root.appendChild(aeNode);
|
nickjillings@2161
|
421 // Build the 'X' element
|
nickjillings@2161
|
422 var audioObject = audioEngineContext.newTrack(element);
|
nickjillings@2161
|
423 var label;
|
nickjillings@2161
|
424 switch(audioObject.specification.parent.label) {
|
nickjillings@2161
|
425 case "letter":
|
nickjillings@2161
|
426 label = "x";
|
nickjillings@2161
|
427 break;
|
nickjillings@2161
|
428 default:
|
nickjillings@2161
|
429 label = "X";
|
nickjillings@2161
|
430 break;
|
nickjillings@2161
|
431 }
|
nickjillings@2161
|
432 var node = new this.interfaceObject(audioObject,label);
|
giuliomoro@2305
|
433 node.box.children[0].classList.add('inactive');
|
nickjillings@2161
|
434 audioObject.bindInterface(node);
|
nickjillings@2161
|
435 this.X = node;
|
nickjillings@2161
|
436 this.boxHolders.appendChild(node.box);
|
nickjillings@2161
|
437 }
|
nickjillings@2161
|
438
|
nickjillings@2161
|
439 function resizeWindow(event)
|
nickjillings@2161
|
440 {
|
nickjillings@2163
|
441 document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px';
|
nickjillings@2163
|
442 var numObj = 3;
|
nickjillings@2163
|
443 var boxW = numObj*312;
|
nickjillings@2163
|
444 var diff = window.innerWidth - boxW;
|
nickjillings@2163
|
445 while (diff < 0)
|
nickjillings@2163
|
446 {
|
nickjillings@2163
|
447 numObj = Math.ceil(numObj/2);
|
nickjillings@2163
|
448 boxW = numObj*312;
|
nickjillings@2163
|
449 diff = window.innerWidth - boxW;
|
nickjillings@2163
|
450 }
|
nickjillings@2163
|
451 document.getElementById('box-holders').style.marginLeft = diff/2 + 'px';
|
nickjillings@2163
|
452 document.getElementById('box-holders').style.marginRight = diff/2 + 'px';
|
nickjillings@2163
|
453 document.getElementById('box-holders').style.width = boxW + 'px';
|
nickjillings@2161
|
454 }
|
nickjillings@2161
|
455
|
nickjillings@2161
|
456 function buttonSubmitClick()
|
nickjillings@2161
|
457 {
|
nickjillings@2163
|
458 var checks = [];
|
nickjillings@2163
|
459 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
|
nickjillings@2163
|
460 checks = checks.concat(specification.interfaces.options);
|
nickjillings@2163
|
461 var canContinue = true;
|
nickjillings@2163
|
462
|
nickjillings@2163
|
463 for (var i=0; i<checks.length; i++) {
|
nickjillings@2163
|
464 if (checks[i].type == 'check')
|
nickjillings@2163
|
465 {
|
nickjillings@2163
|
466 switch(checks[i].name) {
|
nickjillings@2163
|
467 case 'fragmentPlayed':
|
nickjillings@2163
|
468 // Check if all fragments have been played
|
nickjillings@2163
|
469 var checkState = interfaceContext.checkAllPlayed();
|
nickjillings@2163
|
470 if (checkState == false) {canContinue = false;}
|
nickjillings@2163
|
471 break;
|
nickjillings@2163
|
472 case 'fragmentFullPlayback':
|
nickjillings@2163
|
473 // Check all fragments have been played to their full length
|
nickjillings@2163
|
474 var checkState = interfaceContext.checkFragmentsFullyPlayed();
|
nickjillings@2163
|
475 if (checkState == false) {canContinue = false;}
|
nickjillings@2163
|
476 break;
|
nickjillings@2163
|
477 case 'fragmentMoved':
|
nickjillings@2163
|
478 // Check all fragment sliders have been moved.
|
nickjillings@2163
|
479 var checkState = interfaceContext.checkAllMoved();
|
nickjillings@2163
|
480 if (checkState == false) {canContinue = false;}
|
nickjillings@2163
|
481 break;
|
nickjillings@2163
|
482 case 'fragmentComments':
|
nickjillings@2163
|
483 // Check all fragment sliders have been moved.
|
nickjillings@2163
|
484 var checkState = interfaceContext.checkAllCommented();
|
nickjillings@2163
|
485 if (checkState == false) {canContinue = false;}
|
nickjillings@2163
|
486 break;
|
nicholas@2310
|
487 case 'scalerange':
|
nicholas@2310
|
488 // Check the scale has been used effectively
|
nicholas@2310
|
489 var checkState = interfaceContext.checkScaleRange(checks[i].min,checks[i].max);
|
nicholas@2310
|
490 if (checkState == false) {canContinue = false;}
|
nicholas@2310
|
491 break;
|
nickjillings@2163
|
492 default:
|
nickjillings@2163
|
493 console.log("WARNING - Check option "+checks[i].check+" is not supported on this interface");
|
nickjillings@2163
|
494 break;
|
nickjillings@2163
|
495 }
|
nickjillings@2163
|
496
|
nickjillings@2163
|
497 }
|
nickjillings@2163
|
498 if (!canContinue) {break;}
|
nickjillings@2163
|
499 }
|
nickjillings@2163
|
500 if (canContinue)
|
nickjillings@2163
|
501 {
|
nickjillings@2163
|
502 if (audioEngineContext.status == 1) {
|
nickjillings@2163
|
503 var playback = document.getElementById('playback-button');
|
nickjillings@2163
|
504 playback.click();
|
nickjillings@2163
|
505 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nickjillings@2163
|
506 } else
|
nickjillings@2163
|
507 {
|
nickjillings@2163
|
508 if (audioEngineContext.timer.testStarted == false)
|
nickjillings@2163
|
509 {
|
nicholas@2362
|
510 interfaceContext.lightbox.post("Warning",'You have not started the test! Please listen to a sample to begin the test!');
|
nickjillings@2163
|
511 return;
|
nickjillings@2163
|
512 }
|
nickjillings@2163
|
513 }
|
nickjillings@2163
|
514 testState.advanceState();
|
nickjillings@2163
|
515 }
|
nickjillings@2161
|
516 }
|
nickjillings@2161
|
517
|
nickjillings@2161
|
518 function pageXMLSave(store, pageSpecification)
|
nickjillings@2161
|
519 {
|
nickjillings@2161
|
520 // MANDATORY
|
nickjillings@2161
|
521 // Saves a specific test page
|
nickjillings@2161
|
522 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nickjillings@2161
|
523 // Get the current <page> information in store (remember to appendChild your data to it)
|
nickjillings@2161
|
524 // pageSpecification is the current page node configuration
|
nickjillings@2161
|
525 // To create new XML nodes, use storage.document.createElement();
|
nickjillings@2161
|
526 } |