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