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