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