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