nickjillings@1341
|
1 /**
|
nickjillings@1341
|
2 * mushra.js
|
nickjillings@1341
|
3 * Create the MUSHRA interface
|
nickjillings@1341
|
4 */
|
nickjillings@1341
|
5
|
nickjillings@1341
|
6 // Once this is loaded and parsed, begin execution
|
nickjillings@1341
|
7 loadInterface();
|
nickjillings@1341
|
8
|
nickjillings@1341
|
9 function loadInterface() {
|
nicholas@2538
|
10 // Get the dimensions of the screen available to the page
|
nicholas@2538
|
11 var width = window.innerWidth;
|
nicholas@2538
|
12 var height = window.innerHeight;
|
nicholas@2538
|
13
|
nicholas@2538
|
14 // The injection point into the HTML page
|
nicholas@2538
|
15 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
nicholas@2538
|
16 var testContent = document.createElement('div');
|
nicholas@2538
|
17 testContent.id = 'testContent';
|
nicholas@2538
|
18
|
nicholas@2538
|
19 // Create the top div for the Title element
|
nicholas@2538
|
20 var titleAttr = specification.title;
|
nicholas@2538
|
21 var title = document.createElement('div');
|
nicholas@2538
|
22 title.className = "title";
|
nicholas@2538
|
23 title.align = "center";
|
nicholas@2538
|
24 var titleSpan = document.createElement('span');
|
nicholas@2470
|
25 titleSpan.id = "test-title";
|
nicholas@2538
|
26
|
nicholas@2538
|
27 // Set title to that defined in XML, else set to default
|
nicholas@2538
|
28 if (titleAttr != undefined) {
|
nicholas@2538
|
29 titleSpan.textContent = titleAttr;
|
nicholas@2538
|
30 } else {
|
nicholas@2538
|
31 titleSpan.textContent = 'Listening test';
|
nicholas@2538
|
32 }
|
nicholas@2538
|
33 // Insert the titleSpan element into the title div element.
|
nicholas@2538
|
34 title.appendChild(titleSpan);
|
nicholas@2538
|
35
|
nicholas@2538
|
36 var pagetitle = document.createElement('div');
|
nicholas@2538
|
37 pagetitle.className = "pageTitle";
|
nicholas@2538
|
38 pagetitle.align = "center";
|
nicholas@2538
|
39 var titleSpan = document.createElement('span');
|
nicholas@2538
|
40 titleSpan.id = "pageTitle";
|
nicholas@2538
|
41 pagetitle.appendChild(titleSpan);
|
nicholas@2538
|
42
|
nicholas@2538
|
43 // Create Interface buttons!
|
nicholas@2538
|
44 var interfaceButtons = document.createElement('div');
|
nicholas@2538
|
45 interfaceButtons.id = 'interface-buttons';
|
nicholas@2538
|
46 interfaceButtons.style.height = '25px';
|
nicholas@2538
|
47
|
nicholas@2538
|
48 // Create playback start/stop points
|
nicholas@2538
|
49 var playback = document.createElement("button");
|
nicholas@2538
|
50 playback.innerHTML = 'Stop';
|
nicholas@2538
|
51 playback.id = 'playback-button';
|
nicholas@2538
|
52 playback.style.float = 'left';
|
nicholas@2538
|
53 // onclick function. Check if it is playing or not, call the correct function in the
|
nicholas@2538
|
54 // audioEngine, change the button text to reflect the next state.
|
nicholas@2538
|
55 playback.onclick = function () {
|
nicholas@2538
|
56 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
57 audioEngineContext.stop();
|
nicholas@2538
|
58 this.innerHTML = 'Stop';
|
nickjillings@1341
|
59 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1341
|
60 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@2538
|
61 }
|
nicholas@2538
|
62 };
|
nicholas@2538
|
63 // Create Submit (save) button
|
nicholas@2538
|
64 var submit = document.createElement("button");
|
nicholas@2538
|
65 submit.innerHTML = 'Next';
|
nicholas@2538
|
66 submit.onclick = buttonSubmitClick;
|
nicholas@2538
|
67 submit.id = 'submit-button';
|
nicholas@2538
|
68 submit.style.float = 'left';
|
nicholas@2538
|
69 // Append the interface buttons into the interfaceButtons object.
|
nicholas@2538
|
70 interfaceButtons.appendChild(playback);
|
nicholas@2538
|
71 interfaceButtons.appendChild(submit);
|
nicholas@2538
|
72
|
nicholas@2395
|
73 // Create outside reference holder
|
nicholas@2395
|
74 var outsideRef = document.createElement("div");
|
nicholas@2395
|
75 outsideRef.id = "outside-reference-holder";
|
nicholas@2538
|
76
|
nicholas@2538
|
77
|
nicholas@2538
|
78 // Create a slider box
|
nicholas@2538
|
79 var sliderBox = document.createElement('div');
|
nicholas@2538
|
80 sliderBox.style.width = "100%";
|
nicholas@2538
|
81 sliderBox.style.height = window.innerHeight - 200 + 12 + 'px';
|
nicholas@2538
|
82 sliderBox.style.marginBottom = '10px';
|
nicholas@2538
|
83 sliderBox.id = 'slider';
|
nicholas@2538
|
84 var scaleHolder = document.createElement('div');
|
nicholas@2538
|
85 scaleHolder.id = "scale-holder";
|
nicholas@2538
|
86 sliderBox.appendChild(scaleHolder);
|
nicholas@2538
|
87 var scaleText = document.createElement('div');
|
nicholas@2538
|
88 scaleText.id = "scale-text-holder";
|
nicholas@2538
|
89 scaleHolder.appendChild(scaleText);
|
nicholas@2538
|
90 var scaleCanvas = document.createElement('canvas');
|
nicholas@2538
|
91 scaleCanvas.id = "scale-canvas";
|
nicholas@2538
|
92 scaleHolder.appendChild(scaleCanvas);
|
nicholas@2538
|
93 var sliderObjectHolder = document.createElement('div');
|
nicholas@2538
|
94 sliderObjectHolder.id = 'slider-holder';
|
nicholas@2538
|
95 sliderObjectHolder.align = "center";
|
nicholas@2538
|
96 sliderBox.appendChild(sliderObjectHolder);
|
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 testContent.style.zIndex = 1;
|
nicholas@2538
|
103 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
|
nicholas@2538
|
104
|
nicholas@2538
|
105 // Inject into HTML
|
nicholas@2538
|
106 testContent.appendChild(title); // Insert the title
|
nicholas@2538
|
107 testContent.appendChild(pagetitle);
|
nicholas@2538
|
108 testContent.appendChild(interfaceButtons);
|
nicholas@2395
|
109 testContent.appendChild(outsideRef);
|
nicholas@2538
|
110 testContent.appendChild(sliderBox);
|
nicholas@2538
|
111 testContent.appendChild(feedbackHolder);
|
nicholas@2538
|
112 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@1341
|
113
|
nicholas@2538
|
114 // Load the full interface
|
nicholas@2538
|
115 testState.initialise();
|
nicholas@2538
|
116 testState.advanceState();
|
nickjillings@1341
|
117 }
|
nickjillings@1341
|
118
|
nicholas@2538
|
119 function loadTest(audioHolderObject) {
|
nicholas@2538
|
120 var id = audioHolderObject.id;
|
nicholas@2538
|
121
|
nicholas@2538
|
122 var feedbackHolder = document.getElementById('feedbackHolder');
|
nicholas@2380
|
123 feedbackHolder.innerHTML = "";
|
nicholas@2538
|
124 var interfaceObj = audioHolderObject.interfaces;
|
nicholas@2538
|
125 if (interfaceObj.length > 1) {
|
nicholas@2538
|
126 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
|
nicholas@2538
|
127 }
|
nicholas@2538
|
128 interfaceObj = interfaceObj[0];
|
nicholas@2538
|
129
|
nicholas@2470
|
130 // Set the page title
|
nicholas@2470
|
131 if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) {
|
nicholas@2470
|
132 document.getElementById("test-title").textContent = audioHolderObject.title
|
nicholas@2470
|
133 }
|
nicholas@2538
|
134
|
nicholas@2538
|
135 if (interfaceObj.title != null) {
|
nicholas@2538
|
136 document.getElementById("pageTitle").textContent = interfaceObj.title;
|
nicholas@2538
|
137 }
|
nicholas@2538
|
138
|
nicholas@2538
|
139 // Delete outside reference
|
nicholas@2538
|
140 var outsideReferenceHolder = document.getElementById("outside-reference-holder");
|
nicholas@2395
|
141 outsideReferenceHolder.innerHTML = "";
|
nicholas@2538
|
142
|
nicholas@2538
|
143 var sliderBox = document.getElementById('slider-holder');
|
nicholas@2538
|
144 sliderBox.innerHTML = "";
|
nicholas@2538
|
145
|
nicholas@2538
|
146 var commentBoxPrefix = "Comment on track";
|
nicholas@2538
|
147 if (interfaceObj.commentBoxPrefix != undefined) {
|
nicholas@2538
|
148 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
nicholas@2538
|
149 }
|
nicholas@2538
|
150 var loopPlayback = audioHolderObject.loop;
|
nicholas@2538
|
151
|
nicholas@2538
|
152 currentTestHolder = document.createElement('audioHolder');
|
nicholas@2538
|
153 currentTestHolder.id = audioHolderObject.id;
|
nicholas@2538
|
154 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
nicholas@2538
|
155
|
nicholas@2538
|
156 // Find all the audioElements from the audioHolder
|
nicholas@2538
|
157 var index = 0;
|
nicholas@2538
|
158 $(audioHolderObject.audioElements).each(function (index, element) {
|
nicholas@2538
|
159 // Find URL of track
|
nicholas@2538
|
160 // In this jQuery loop, variable 'this' holds the current audioElement.
|
nicholas@2538
|
161
|
nicholas@2538
|
162 var audioObject = audioEngineContext.newTrack(element);
|
nicholas@2538
|
163 if (element.type == 'outside-reference') {
|
nicholas@2538
|
164 // Construct outside reference;
|
nicholas@2538
|
165 var orNode = new interfaceContext.outsideReferenceDOM(audioObject, index, outsideReferenceHolder);
|
nicholas@2538
|
166 audioObject.bindInterface(orNode);
|
nicholas@2538
|
167 } else {
|
nicholas@2538
|
168 // Create a slider per track
|
nicholas@2538
|
169 switch (audioObject.specification.parent.label) {
|
nickjillings@1295
|
170 case "none":
|
nickjillings@1295
|
171 label = "";
|
nickjillings@1295
|
172 break;
|
nickjillings@1295
|
173 case "letter":
|
nickjillings@1295
|
174 label = String.fromCharCode(97 + index);
|
nickjillings@1295
|
175 break;
|
nickjillings@1295
|
176 case "capital":
|
nickjillings@1295
|
177 label = String.fromCharCode(65 + index);
|
nickjillings@1295
|
178 break;
|
nickjillings@1295
|
179 default:
|
nicholas@2538
|
180 label = "" + index;
|
nickjillings@1295
|
181 break;
|
nickjillings@1295
|
182 }
|
nicholas@2538
|
183 var sliderObj = new sliderObject(audioObject, label);
|
nicholas@2538
|
184
|
nicholas@2538
|
185 if (typeof audioHolderObject.initialPosition === "number") {
|
nicholas@2538
|
186 // Set the values
|
nicholas@2538
|
187 sliderObj.slider.value = audioHolderObject.initalPosition;
|
nicholas@2538
|
188 } else {
|
nicholas@2538
|
189 // Distribute it randomnly
|
nicholas@2538
|
190 sliderObj.slider.value = Math.random();
|
nicholas@2538
|
191 }
|
nicholas@2538
|
192 sliderBox.appendChild(sliderObj.holder);
|
nicholas@2538
|
193 audioObject.bindInterface(sliderObj);
|
nickjillings@2117
|
194 interfaceContext.commentBoxes.createCommentBox(audioObject);
|
nicholas@2538
|
195 index += 1;
|
nicholas@2538
|
196 }
|
nicholas@2538
|
197
|
nicholas@2538
|
198 });
|
nicholas@2538
|
199
|
nicholas@2538
|
200
|
n@2407
|
201 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
|
nicholas@2538
|
202 for (var option of interfaceOptions) {
|
nicholas@2538
|
203 if (option.type == "show") {
|
nicholas@2538
|
204 switch (option.name) {
|
n@2407
|
205 case "playhead":
|
n@2407
|
206 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@2538
|
207 if (playbackHolder == null) {
|
n@2407
|
208 playbackHolder = document.createElement('div');
|
n@2407
|
209 playbackHolder.style.width = "100%";
|
n@2407
|
210 playbackHolder.align = 'center';
|
n@2407
|
211 playbackHolder.appendChild(interfaceContext.playhead.object);
|
n@2407
|
212 feedbackHolder.appendChild(playbackHolder);
|
n@2407
|
213 }
|
n@2407
|
214 break;
|
n@2407
|
215 case "page-count":
|
n@2407
|
216 var pagecountHolder = document.getElementById('page-count');
|
nicholas@2538
|
217 if (pagecountHolder == null) {
|
n@2407
|
218 pagecountHolder = document.createElement('div');
|
n@2407
|
219 pagecountHolder.id = 'page-count';
|
n@2407
|
220 }
|
nicholas@2538
|
221 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
|
n@2407
|
222 var inject = document.getElementById('interface-buttons');
|
n@2407
|
223 inject.appendChild(pagecountHolder);
|
n@2407
|
224 break;
|
n@2407
|
225 case "volume":
|
nicholas@2538
|
226 if (document.getElementById('master-volume-holder') == null) {
|
n@2407
|
227 feedbackHolder.appendChild(interfaceContext.volume.object);
|
n@2407
|
228 }
|
n@2407
|
229 break;
|
n@2407
|
230 case "comments":
|
nicholas@2538
|
231 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
|
n@2407
|
232 break;
|
n@2407
|
233 }
|
n@2407
|
234 }
|
n@2407
|
235 }
|
nicholas@2538
|
236
|
nicholas@2538
|
237 $(audioHolderObject.commentQuestions).each(function (index, element) {
|
nicholas@2538
|
238 var node = interfaceContext.createCommentQuestion(element);
|
nicholas@2538
|
239 feedbackHolder.appendChild(node.holder);
|
nicholas@2538
|
240 });
|
nicholas@2538
|
241
|
nicholas@2538
|
242 // Auto-align
|
nicholas@2538
|
243 resizeWindow(null);
|
nickjillings@1341
|
244 }
|
nickjillings@1341
|
245
|
nicholas@2538
|
246 function sliderObject(audioObject, label) {
|
nicholas@2538
|
247 // Constructs the slider object. We use the HTML5 slider object
|
nicholas@2538
|
248 this.parent = audioObject;
|
nicholas@2538
|
249 this.holder = document.createElement('div');
|
nicholas@2538
|
250 this.title = document.createElement('span');
|
nicholas@2538
|
251 this.slider = document.createElement('input');
|
nicholas@2538
|
252 this.play = document.createElement('button');
|
nicholas@2538
|
253
|
nicholas@2538
|
254 this.holder.className = 'track-slider';
|
nicholas@2538
|
255 this.holder.style.height = window.innerHeight - 200 + 'px';
|
nicholas@2538
|
256 this.holder.appendChild(this.title);
|
nicholas@2538
|
257 this.holder.appendChild(this.slider);
|
nicholas@2538
|
258 this.holder.appendChild(this.play);
|
nicholas@2538
|
259 this.holder.align = "center";
|
nicholas@2538
|
260 if (label == 0) {
|
nicholas@2538
|
261 this.holder.style.marginLeft = '0px';
|
nicholas@2538
|
262 }
|
nicholas@2538
|
263 this.holder.setAttribute('trackIndex', audioObject.id);
|
nicholas@2538
|
264
|
nicholas@2538
|
265 this.title.textContent = label;
|
nicholas@2538
|
266 this.title.style.width = "100%";
|
nicholas@2538
|
267 this.title.style.float = "left";
|
nicholas@2538
|
268
|
nicholas@2538
|
269 this.slider.type = "range";
|
nicholas@2538
|
270 this.slider.className = "track-slider-range track-slider-not-moved";
|
nicholas@2538
|
271 this.slider.min = "0";
|
nicholas@2538
|
272 this.slider.max = "1";
|
nicholas@2538
|
273 this.slider.step = "0.01";
|
nicholas@2538
|
274 this.slider.setAttribute('orient', 'vertical');
|
nicholas@2538
|
275 this.slider.style.height = window.innerHeight - 250 + 'px';
|
nicholas@2538
|
276 this.slider.onchange = function () {
|
nicholas@2538
|
277 var time = audioEngineContext.timer.getTestTime();
|
nicholas@2538
|
278 var id = Number(this.parentNode.getAttribute('trackIndex'));
|
nicholas@2538
|
279 audioEngineContext.audioObjects[id].metric.moved(time, this.value);
|
nicholas@2538
|
280 console.log('slider ' + id + ' moved to ' + this.value + ' (' + time + ')');
|
nicholas@2538
|
281 $(this).removeClass('track-slider-not-moved');
|
nicholas@2538
|
282 };
|
nicholas@2538
|
283
|
nicholas@2538
|
284 this.play.textContent = "Loading...";
|
nicholas@2538
|
285 this.play.value = audioObject.id;
|
nicholas@2538
|
286 this.play.style.float = "left";
|
nicholas@2538
|
287 this.play.style.width = "100%";
|
nicholas@2538
|
288 this.play.disabled = true;
|
nicholas@2538
|
289 this.play.setAttribute("playstate", "ready");
|
nicholas@2538
|
290 this.play.onclick = function (event) {
|
nicholas@2538
|
291 var id = Number(event.currentTarget.value);
|
nicholas@2538
|
292 //audioEngineContext.metric.sliderPlayed(id);
|
nicholas@2538
|
293 if (event.currentTarget.getAttribute("playstate") == "ready") {
|
nicholas@2538
|
294 audioEngineContext.play(id);
|
nicholas@2538
|
295 } else if (event.currentTarget.getAttribute("playstate") == "playing") {
|
nicholas@2538
|
296 audioEngineContext.stop();
|
nicholas@2538
|
297 }
|
nicholas@2538
|
298 };
|
nicholas@2538
|
299
|
nicholas@2538
|
300 this.enable = function () {
|
nicholas@2538
|
301 this.play.disabled = false;
|
nicholas@2538
|
302 this.play.textContent = "Play";
|
nicholas@2538
|
303 $(this.slider).removeClass('track-slider-disabled');
|
nicholas@2538
|
304 };
|
nicholas@2538
|
305
|
nicholas@2538
|
306 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
307 // Called by the audioObject holding this element. Must be present
|
nicholas@2538
|
308 var node = storage.document.createElement('value');
|
nicholas@2538
|
309 node.textContent = this.slider.value;
|
nicholas@2538
|
310 return node;
|
nicholas@2538
|
311 };
|
nicholas@2538
|
312 this.startPlayback = function () {
|
nickjillings@1360
|
313 // Called when playback has begun
|
nicholas@2538
|
314 this.play.setAttribute("playstate", "playing");
|
nickjillings@1360
|
315 $(".track-slider").removeClass('track-slider-playing');
|
nicholas@2538
|
316 $(this.holder).addClass('track-slider-playing');
|
nicholas@2538
|
317 var outsideReference = document.getElementById('outside-reference');
|
nicholas@2538
|
318 if (outsideReference != null) {
|
nicholas@2538
|
319 $(outsideReference).removeClass('track-slider-playing');
|
nicholas@2538
|
320 }
|
nickjillings@1383
|
321 this.play.textContent = "Stop";
|
nickjillings@1360
|
322 };
|
nicholas@2538
|
323 this.stopPlayback = function () {
|
nickjillings@1360
|
324 // Called when playback has stopped. This gets called even if playback never started!
|
nicholas@2538
|
325 this.play.setAttribute("playstate", "ready");
|
nickjillings@1360
|
326 $(this.holder).removeClass('track-slider-playing');
|
nickjillings@1383
|
327 this.play.textContent = "Play";
|
nickjillings@1360
|
328 };
|
nicholas@2538
|
329 this.getValue = function () {
|
nicholas@2538
|
330 return this.slider.value;
|
nicholas@2538
|
331 };
|
nicholas@2538
|
332
|
nicholas@2538
|
333 this.resize = function (event) {
|
nicholas@2538
|
334 this.holder.style.height = window.innerHeight - 200 + 'px';
|
nicholas@2538
|
335 this.slider.style.height = window.innerHeight - 250 + 'px';
|
nicholas@2538
|
336 };
|
nicholas@2538
|
337 this.updateLoading = function (progress) {
|
nicholas@2538
|
338 progress = String(progress);
|
nicholas@2538
|
339 progress = progress.substr(0, 5);
|
nicholas@2538
|
340 this.play.textContent = "Loading: " + progress + "%";
|
nicholas@2538
|
341 };
|
nicholas@2538
|
342
|
nicholas@2538
|
343 if (this.parent.state == 1) {
|
nicholas@2538
|
344 this.enable();
|
nicholas@2538
|
345 }
|
nicholas@2538
|
346 this.getPresentedId = function () {
|
nicholas@2538
|
347 return this.title.textContent;
|
nicholas@2538
|
348 };
|
nicholas@2538
|
349 this.canMove = function () {
|
nicholas@2538
|
350 return true;
|
nicholas@2538
|
351 };
|
nicholas@2538
|
352 this.error = function () {
|
nicholas@2538
|
353 // audioObject has an error!!
|
nickjillings@2113
|
354 this.playback.textContent = "Error";
|
nickjillings@2113
|
355 $(this.playback).addClass("error-colour");
|
nickjillings@2113
|
356 }
|
nickjillings@1341
|
357 }
|
nickjillings@1341
|
358
|
nicholas@2538
|
359 function resizeWindow(event) {
|
nicholas@2538
|
360 // Function called when the window has been resized.
|
nicholas@2538
|
361 // MANDATORY FUNCTION
|
nicholas@2538
|
362
|
nicholas@2538
|
363 var outsideRef = document.getElementById('outside-reference');
|
nicholas@2538
|
364 if (outsideRef != null) {
|
nicholas@2538
|
365 outsideRef.style.left = (window.innerWidth - 120) / 2 + 'px';
|
nicholas@2538
|
366 }
|
nicholas@2538
|
367
|
nicholas@2538
|
368 // Auto-align
|
nicholas@2538
|
369 var numObj = document.getElementsByClassName('track-slider').length;
|
nicholas@2538
|
370 var totalWidth = (numObj - 1) * 150 + 100;
|
nicholas@2538
|
371 var diff = (window.innerWidth - totalWidth) / 2;
|
nicholas@2538
|
372 document.getElementById('slider').style.height = window.innerHeight - 180 + 'px';
|
nicholas@2538
|
373 if (diff <= 0) {
|
nicholas@2538
|
374 diff = 0;
|
nicholas@2538
|
375 }
|
nicholas@2538
|
376 document.getElementById('slider-holder').style.marginLeft = diff + 'px';
|
nicholas@2538
|
377 for (var i in audioEngineContext.audioObjects) {
|
nicholas@2538
|
378 if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference') {
|
nicholas@2538
|
379 audioEngineContext.audioObjects[i].interfaceDOM.resize(event);
|
nicholas@2538
|
380 }
|
nicholas@2538
|
381 }
|
nicholas@2538
|
382 document.getElementById('scale-holder').style.marginLeft = (diff - 100) + 'px';
|
nicholas@2538
|
383 document.getElementById('scale-text-holder').style.height = window.innerHeight - 194 + 'px';
|
nicholas@2380
|
384 // Cheers edge for making me delete a canvas every resize.
|
nicholas@2538
|
385 var canvas = document.getElementById('scale-canvas');
|
nicholas@2380
|
386 var new_canvas = document.createElement("canvas");
|
nicholas@2380
|
387 new_canvas.id = 'scale-canvas';
|
nicholas@2380
|
388 canvas.parentElement.appendChild(new_canvas);
|
nicholas@2380
|
389 canvas.parentElement.removeChild(canvas);
|
nicholas@2538
|
390 new_canvas.width = totalWidth;
|
nicholas@2538
|
391 new_canvas.height = window.innerHeight - 194;
|
nicholas@2538
|
392 drawScale();
|
nickjillings@1341
|
393 }
|
nickjillings@1341
|
394
|
nicholas@2538
|
395 function drawScale() {
|
nicholas@2538
|
396 var interfaceObj = testState.currentStateMap.interfaces[0];
|
nicholas@2538
|
397 var scales = testState.currentStateMap.interfaces[0].scales;
|
nicholas@2538
|
398 scales = scales.sort(function (a, b) {
|
nicholas@2538
|
399 return a.position - b.position;
|
nicholas@2538
|
400 });
|
nicholas@2538
|
401 var canvas = document.getElementById('scale-canvas');
|
nicholas@2538
|
402 var ctx = canvas.getContext("2d");
|
nicholas@2538
|
403 var height = canvas.height;
|
nicholas@2538
|
404 var width = canvas.width;
|
nicholas@2538
|
405 ctx.clearRect(0, 0, canvas.width, canvas.height);
|
nicholas@2538
|
406 var draw_heights = [24, height - 34];
|
nicholas@2538
|
407 var textHolder = document.getElementById('scale-text-holder');
|
nicholas@2538
|
408 textHolder.innerHTML = "";
|
nicholas@2538
|
409 var lastHeight = 0;
|
nicholas@2538
|
410 for (var scale of scales) {
|
nicholas@2538
|
411 var posPercent = scale.position / 100.0;
|
nicholas@2538
|
412 var posPix = (1 - posPercent) * (draw_heights[1] - draw_heights[0]) + draw_heights[0];
|
nicholas@2538
|
413 ctx.fillStyle = "#000000";
|
nicholas@2538
|
414 ctx.setLineDash([1, 2]);
|
nicholas@2538
|
415 ctx.moveTo(0, posPix);
|
nicholas@2538
|
416 ctx.lineTo(width, posPix);
|
nicholas@2538
|
417 ctx.stroke();
|
nicholas@2538
|
418 var text = document.createElement('div');
|
nicholas@2538
|
419 text.align = "right";
|
nicholas@2538
|
420 var textC = document.createElement('span');
|
nicholas@2538
|
421 textC.textContent = scale.text;
|
nicholas@2538
|
422 text.appendChild(textC);
|
nicholas@2538
|
423 text.className = "scale-text";
|
nicholas@2538
|
424 textHolder.appendChild(text);
|
nicholas@2538
|
425 text.style.top = (posPix - 9) + 'px';
|
nicholas@2538
|
426 text.style.left = 100 - ($(text).width() + 3) + 'px';
|
nicholas@2538
|
427 lastHeight = posPix;
|
nicholas@2538
|
428 }
|
nickjillings@1341
|
429 }
|
nickjillings@1341
|
430
|
nickjillings@1341
|
431 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
nickjillings@1341
|
432 {
|
nicholas@2538
|
433 var checks = [];
|
nicholas@2538
|
434 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
|
nicholas@2538
|
435 checks = checks.concat(specification.interfaces.options);
|
nicholas@2538
|
436 var canContinue = true;
|
nickjillings@1341
|
437
|
nicholas@2538
|
438 // Check that the anchor and reference objects are correctly placed
|
nicholas@2538
|
439 if (interfaceContext.checkHiddenAnchor() == false) {
|
nicholas@2538
|
440 return;
|
nicholas@2538
|
441 }
|
nicholas@2538
|
442 if (interfaceContext.checkHiddenReference() == false) {
|
nicholas@2538
|
443 return;
|
nicholas@2538
|
444 }
|
nicholas@2538
|
445
|
nicholas@2538
|
446 for (var i = 0; i < checks.length; i++) {
|
nicholas@2538
|
447 if (checks[i].type == 'check') {
|
nicholas@2538
|
448 switch (checks[i].name) {
|
nicholas@2538
|
449 case 'fragmentPlayed':
|
nicholas@2538
|
450 // Check if all fragments have been played
|
nicholas@2538
|
451 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@2538
|
452 if (checkState == false) {
|
nicholas@2538
|
453 canContinue = false;
|
nicholas@2538
|
454 }
|
nicholas@2538
|
455 break;
|
nicholas@2538
|
456 case 'fragmentFullPlayback':
|
nicholas@2538
|
457 // Check all fragments have been played to their full length
|
nicholas@2538
|
458 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@2538
|
459 if (checkState == false) {
|
nicholas@2538
|
460 canContinue = false;
|
nicholas@2538
|
461 }
|
nicholas@2538
|
462 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
|
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
|
nickjillings@1341
|
496 if (canContinue) {
|
nicholas@2538
|
497 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
498 var playback = document.getElementById('playback-button');
|
nicholas@2538
|
499 playback.click();
|
nicholas@2538
|
500 // 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
|
501 } else {
|
nicholas@2538
|
502 if (audioEngineContext.timer.testStarted == false) {
|
nicholas@2538
|
503 interfaceContext.lightbox.post("Message", 'You have not started the test! Please press start to begin the test!');
|
nicholas@2538
|
504 return;
|
nicholas@2538
|
505 }
|
nicholas@2538
|
506 }
|
nicholas@2538
|
507 testState.advanceState();
|
nicholas@2538
|
508 }
|
nickjillings@1341
|
509 }
|
nickjillings@1341
|
510
|
nicholas@2538
|
511 function pageXMLSave(store, pageSpecification) {
|
nicholas@2538
|
512 // MANDATORY
|
nicholas@2538
|
513 // Saves a specific test page
|
nicholas@2538
|
514 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nicholas@2538
|
515 // Get the current <page> information in store (remember to appendChild your data to it)
|
nicholas@2538
|
516 // pageSpecification is the current page node configuration
|
nicholas@2538
|
517 // To create new XML nodes, use storage.document.createElement();
|
nickjillings@1341
|
518 }
|