nickjillings@1341
|
1 /**
|
nickjillings@1341
|
2 * ape.js
|
nickjillings@1341
|
3 * Create the APE interface
|
nickjillings@1341
|
4 */
|
nickjillings@1341
|
5
|
nicholas@2696
|
6 /*globals window,interfaceContext, document, audioEngineContext, console, $, Interface, testState, storage, specification */
|
n@3094
|
7 /*globals metricTracker, module, randomiseOrder */
|
nickjillings@1341
|
8 // Once this is loaded and parsed, begin execution
|
nickjillings@1341
|
9 loadInterface();
|
nickjillings@1341
|
10
|
nickjillings@1341
|
11 function loadInterface() {
|
nicholas@2538
|
12
|
nicholas@2538
|
13 // Get the dimensions of the screen available to the page
|
nicholas@2538
|
14 var width = window.innerWidth;
|
nicholas@2538
|
15 var height = window.innerHeight;
|
nicholas@2538
|
16
|
nicholas@2538
|
17 // The injection point into the HTML page
|
nicholas@2538
|
18 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
nicholas@2538
|
19 var testContent = document.createElement('div');
|
nicholas@2538
|
20
|
nicholas@2538
|
21 testContent.id = 'testContent';
|
nicholas@2538
|
22
|
nicholas@2538
|
23 // Bindings for interfaceContext
|
nicholas@2538
|
24
|
nicholas@2538
|
25 interfaceContext.checkAllMoved = function () {
|
n@3011
|
26 return module.checkAllMoved();
|
nicholas@2538
|
27 };
|
nicholas@2703
|
28
|
nicholas@2698
|
29 interfaceContext.checkScaleRange = function () {
|
n@3011
|
30 return module.checkScaleRange();
|
nicholas@2538
|
31 };
|
nicholas@2538
|
32
|
nicholas@2538
|
33 // Bindings for audioObjects
|
nicholas@2538
|
34
|
nicholas@2538
|
35 // Create the top div for the Title element
|
nicholas@2538
|
36 var titleAttr = specification.title;
|
nicholas@2538
|
37 var title = document.createElement('div');
|
nicholas@2538
|
38 title.className = "title";
|
nicholas@2538
|
39 title.align = "center";
|
nicholas@2538
|
40 var titleSpan = document.createElement('span');
|
nicholas@2470
|
41 titleSpan.id = "test-title";
|
nicholas@2538
|
42
|
nicholas@2538
|
43 // Set title to that defined in XML, else set to default
|
nicholas@2696
|
44 if (titleAttr !== undefined) {
|
nicholas@2538
|
45 titleSpan.textContent = titleAttr;
|
nicholas@2538
|
46 } else {
|
nicholas@2538
|
47 titleSpan.textContent = 'Listening test';
|
nicholas@2538
|
48 }
|
nicholas@2538
|
49 // Insert the titleSpan element into the title div element.
|
nicholas@2538
|
50 title.appendChild(titleSpan);
|
nicholas@2538
|
51
|
nicholas@2538
|
52 // Create Interface buttons!
|
nicholas@2538
|
53 var interfaceButtons = document.createElement('div');
|
nicholas@2538
|
54 interfaceButtons.id = 'interface-buttons';
|
nicholas@2538
|
55
|
nicholas@2538
|
56 // Create playback start/stop points
|
nicholas@2538
|
57 var playback = document.createElement("button");
|
nicholas@2538
|
58 playback.innerHTML = 'Stop';
|
nicholas@2538
|
59 playback.id = 'playback-button';
|
nicholas@2538
|
60 // onclick function. Check if it is playing or not, call the correct function in the
|
nicholas@2538
|
61 // audioEngine, change the button text to reflect the next state.
|
nicholas@2538
|
62 playback.onclick = function () {
|
nicholas@2538
|
63 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
64 audioEngineContext.stop();
|
nicholas@2538
|
65 this.innerHTML = 'Stop';
|
nickjillings@1341
|
66 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1341
|
67 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@2538
|
68 }
|
nicholas@2538
|
69 };
|
nicholas@2538
|
70 // Create Submit (save) button
|
nicholas@2538
|
71 var submit = document.createElement("button");
|
nicholas@2538
|
72 submit.innerHTML = 'Next';
|
nicholas@2538
|
73 submit.onclick = buttonSubmitClick;
|
nicholas@2538
|
74 submit.id = 'submit-button';
|
nicholas@2538
|
75 // Append the interface buttons into the interfaceButtons object.
|
nicholas@2538
|
76 interfaceButtons.appendChild(playback);
|
nicholas@2538
|
77 interfaceButtons.appendChild(submit);
|
nicholas@2538
|
78
|
nicholas@2538
|
79 var sliderHolder = document.createElement("div");
|
nicholas@2538
|
80 sliderHolder.id = "slider-holder";
|
nicholas@2538
|
81
|
nicholas@2396
|
82 // Create outside reference holder
|
nicholas@2396
|
83 var outsideRef = document.createElement("div");
|
nicholas@2396
|
84 outsideRef.id = "outside-reference-holder";
|
nicholas@2538
|
85
|
nicholas@2538
|
86 // Global parent for the comment boxes on the page
|
nicholas@2538
|
87 var feedbackHolder = document.createElement('div');
|
nicholas@2538
|
88 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2538
|
89
|
nicholas@2538
|
90 testContent.style.zIndex = 1;
|
nicholas@2538
|
91 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
|
nicholas@2538
|
92
|
nicholas@2538
|
93 // Inject into HTML
|
nicholas@2538
|
94 testContent.appendChild(title); // Insert the title
|
nicholas@2538
|
95 testContent.appendChild(interfaceButtons);
|
nicholas@2396
|
96 testContent.appendChild(outsideRef);
|
nicholas@2538
|
97 testContent.appendChild(sliderHolder);
|
nicholas@2538
|
98 testContent.appendChild(feedbackHolder);
|
nicholas@2538
|
99 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@1341
|
100
|
nicholas@2538
|
101 // Load the full interface
|
n@3010
|
102 window.module = new ape();
|
nicholas@2538
|
103 testState.initialise();
|
nicholas@2538
|
104 testState.advanceState();
|
nickjillings@1341
|
105 }
|
nickjillings@1341
|
106
|
nicholas@2538
|
107 function loadTest(audioHolderObject) {
|
n@3010
|
108 module.clear();
|
nicholas@2538
|
109 var width = window.innerWidth;
|
nicholas@2538
|
110 var height = window.innerHeight;
|
nicholas@2538
|
111 var id = audioHolderObject.id;
|
nicholas@2538
|
112
|
nicholas@2538
|
113 interfaceContext.interfaceSliders = [];
|
nicholas@2538
|
114
|
nicholas@2538
|
115 var feedbackHolder = document.getElementById('feedbackHolder');
|
nicholas@2538
|
116 var sliderHolder = document.getElementById('slider-holder');
|
nicholas@2538
|
117 feedbackHolder.innerHTML = "";
|
nicholas@2538
|
118 sliderHolder.innerHTML = "";
|
nicholas@2538
|
119
|
nicholas@2596
|
120 // Set labelType if default to number
|
nicholas@2696
|
121 if (audioHolderObject.label === "default" || audioHolderObject.label === "") {
|
nicholas@2596
|
122 audioHolderObject.label = "number";
|
nicholas@2596
|
123 }
|
nicholas@2470
|
124 // Set the page title
|
nicholas@2470
|
125 if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) {
|
nicholas@2696
|
126 document.getElementById("test-title").textContent = audioHolderObject.title;
|
nicholas@2470
|
127 }
|
nicholas@2538
|
128
|
nicholas@2538
|
129 // Delete outside reference
|
nicholas@2538
|
130 document.getElementById("outside-reference-holder").innerHTML = "";
|
nicholas@2538
|
131
|
nicholas@2651
|
132 var interfaceObj = interfaceContext.getCombinedInterfaces(audioHolderObject);
|
nicholas@2651
|
133 interfaceObj.forEach(function (interface) {
|
nicholas@2696
|
134 interface.options.forEach(function (option) {
|
nicholas@2651
|
135 if (option.type == "show") {
|
nicholas@2651
|
136 switch (option.name) {
|
nicholas@2651
|
137 case "playhead":
|
nicholas@2651
|
138 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@2696
|
139 if (playbackHolder === null) {
|
nicholas@2651
|
140 playbackHolder = document.createElement('div');
|
nicholas@2651
|
141 playbackHolder.style.width = "100%";
|
nicholas@2651
|
142 playbackHolder.align = 'center';
|
nicholas@2651
|
143 playbackHolder.appendChild(interfaceContext.playhead.object);
|
nicholas@2651
|
144 feedbackHolder.insertBefore(playbackHolder, feedbackHolder.firstElementChild);
|
nicholas@2651
|
145 }
|
nicholas@2651
|
146 break;
|
nicholas@2651
|
147 case "page-count":
|
nicholas@2651
|
148 var pagecountHolder = document.getElementById('page-count');
|
nicholas@2696
|
149 if (pagecountHolder === null) {
|
nicholas@2651
|
150 pagecountHolder = document.createElement('div');
|
nicholas@2651
|
151 pagecountHolder.id = 'page-count';
|
nicholas@2651
|
152 }
|
nicholas@2651
|
153 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
|
nicholas@2651
|
154 var inject = document.getElementById('interface-buttons');
|
nicholas@2651
|
155 inject.appendChild(pagecountHolder);
|
nicholas@2651
|
156 break;
|
nicholas@2651
|
157 case "volume":
|
nicholas@2696
|
158 if (document.getElementById('master-volume-holder') === null) {
|
nicholas@2651
|
159 feedbackHolder.appendChild(interfaceContext.volume.object);
|
nicholas@2651
|
160 }
|
nicholas@2651
|
161 break;
|
nicholas@2651
|
162 case "comments":
|
nicholas@2651
|
163 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
|
nicholas@2651
|
164 break;
|
nickjillings@1356
|
165 }
|
nickjillings@1356
|
166 }
|
nicholas@2696
|
167 });
|
nicholas@2651
|
168 });
|
nickjillings@1341
|
169
|
nicholas@2538
|
170 var commentBoxPrefix = "Comment on fragment";
|
nicholas@2538
|
171
|
nicholas@2538
|
172 var commentShow = audioHolderObject.elementComments;
|
nicholas@2538
|
173
|
nicholas@2538
|
174 var loopPlayback = audioHolderObject.loop;
|
nicholas@2538
|
175
|
n@3010
|
176 module.initialisePage(audioHolderObject);
|
nicholas@2538
|
177
|
n@2407
|
178 var interfaceList = audioHolderObject.interfaces.concat(specification.interfaces);
|
nicholas@2538
|
179 for (var k = 0; k < interfaceList.length; k++) {
|
nicholas@2538
|
180 for (var i = 0; i < interfaceList[k].options.length; i++) {
|
nicholas@2538
|
181 if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'playhead') {
|
n@2407
|
182 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@2696
|
183 if (playbackHolder === null) {
|
n@2407
|
184 playbackHolder = document.createElement('div');
|
n@2407
|
185 playbackHolder.id = "playback-holder";
|
n@2407
|
186 playbackHolder.style.width = "100%";
|
n@2407
|
187 playbackHolder.align = 'center';
|
n@2407
|
188 playbackHolder.appendChild(interfaceContext.playhead.object);
|
n@2407
|
189 feedbackHolder.appendChild(playbackHolder);
|
n@2407
|
190 }
|
nicholas@2538
|
191 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'page-count') {
|
n@2407
|
192 var pagecountHolder = document.getElementById('page-count');
|
nicholas@2696
|
193 if (pagecountHolder === null) {
|
n@2407
|
194 pagecountHolder = document.createElement('div');
|
n@2407
|
195 pagecountHolder.id = 'page-count';
|
n@2407
|
196 }
|
nicholas@2538
|
197 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
|
n@2407
|
198 var inject = document.getElementById('interface-buttons');
|
n@2407
|
199 inject.appendChild(pagecountHolder);
|
n@2407
|
200 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'volume') {
|
nicholas@2696
|
201 if (document.getElementById('master-volume-holder') === null) {
|
n@2407
|
202 feedbackHolder.appendChild(interfaceContext.volume.object);
|
n@2407
|
203 }
|
n@2407
|
204 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'comments') {
|
nicholas@2538
|
205 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
|
n@2407
|
206 break;
|
n@2407
|
207 }
|
n@2407
|
208 }
|
n@2407
|
209 }
|
nicholas@2538
|
210
|
nicholas@2538
|
211 $(audioHolderObject.commentQuestions).each(function (index, element) {
|
nicholas@2538
|
212 var node = interfaceContext.createCommentQuestion(element);
|
nicholas@2538
|
213 feedbackHolder.appendChild(node.holder);
|
nicholas@2538
|
214 });
|
nicholas@2538
|
215
|
nicholas@2538
|
216 //testWaitIndicator();
|
nicholas@3041
|
217 module.resize();
|
nickjillings@1341
|
218 }
|
nickjillings@1341
|
219
|
n@3009
|
220 function ape() {
|
n@3094
|
221 var axis = [];
|
n@3009
|
222 var DOMRoot = document.getElementById("slider-holder");
|
n@3009
|
223 var AOIs = [];
|
n@3094
|
224 var page;
|
n@3009
|
225
|
n@3009
|
226 function audioObjectInterface(audioObject, parent) {
|
n@3009
|
227 // The audioObject communicates with this object
|
n@3009
|
228 var playing = false;
|
n@3009
|
229 var sliders = [];
|
n@3009
|
230 this.enable = function () {
|
n@3009
|
231 sliders.forEach(function (s) {
|
n@3009
|
232 s.enable();
|
nicholas@3019
|
233 });
|
n@3094
|
234 };
|
n@3009
|
235
|
n@3009
|
236 this.updateLoading = function (p) {
|
n@3009
|
237 sliders.forEach(function (s) {
|
n@3009
|
238 s.updateLoading(p);
|
nicholas@3019
|
239 });
|
n@3094
|
240 };
|
n@3009
|
241
|
n@3009
|
242 this.startPlayback = function () {
|
n@3009
|
243 playing = true;
|
n@3009
|
244 sliders.forEach(function (s) {
|
n@3009
|
245 s.playing();
|
n@3009
|
246 });
|
n@3094
|
247 };
|
n@3009
|
248
|
n@3009
|
249 this.stopPlayback = function () {
|
n@3009
|
250 playing = false;
|
n@3009
|
251 sliders.forEach(function (s) {
|
n@3009
|
252 s.stopped();
|
n@3009
|
253 });
|
n@3094
|
254 };
|
n@3009
|
255
|
n@3009
|
256 this.getValue = function () {
|
nicholas@3041
|
257 return sliders[0].value;
|
n@3094
|
258 };
|
n@3009
|
259
|
n@3009
|
260 this.getPresentedId = function () {
|
n@3009
|
261 return sliders[0].label;
|
n@3094
|
262 };
|
n@3009
|
263
|
n@3009
|
264 this.canMove = function () {
|
n@3009
|
265 return true;
|
n@3094
|
266 };
|
n@3009
|
267
|
n@3009
|
268 this.exportXMLDOM = function (audioObject) {
|
n@3009
|
269 var elements = [];
|
n@3009
|
270 sliders.forEach(function (s) {
|
n@3009
|
271 elements.push(s.exportXMLDOM());
|
n@3009
|
272 });
|
n@3009
|
273 return elements;
|
n@3094
|
274 };
|
n@3009
|
275
|
n@3009
|
276 this.error = function () {
|
n@3009
|
277 sliders.forEach(function (s) {
|
n@3009
|
278 s.error();
|
n@3009
|
279 });
|
n@3094
|
280 };
|
n@3009
|
281
|
n@3009
|
282 this.addSlider = function (s) {
|
n@3009
|
283 sliders.push(s);
|
n@3094
|
284 };
|
n@3009
|
285
|
n@3009
|
286 this.clicked = function (event) {
|
n@3009
|
287 if (!playing) {
|
n@3009
|
288 audioEngineContext.play(audioObject.id);
|
n@3009
|
289 } else {
|
n@3009
|
290 audioEngineContext.stop();
|
n@3009
|
291 }
|
n@3009
|
292 playing = !playing;
|
n@3094
|
293 };
|
n@3009
|
294
|
n@3009
|
295 this.pageXMLSave = function (store) {
|
n@3009
|
296 var inject = audioObject.storeDOM.getElementsByTagName("metric")[0];
|
n@3009
|
297 sliders.forEach(function (s) {
|
n@3009
|
298 s.pageXMLSave(inject);
|
n@3009
|
299 });
|
n@3094
|
300 };
|
n@3009
|
301
|
n@3009
|
302 }
|
n@3009
|
303
|
n@3009
|
304 function axisObject(interfaceObject, parent) {
|
n@3009
|
305
|
n@3009
|
306 function sliderInterface(AOI, axisInterface) {
|
n@3009
|
307 var trackObj = document.createElement('div');
|
n@3009
|
308 var labelHolder = document.createElement("span");
|
n@3009
|
309 var label = "";
|
n@3009
|
310 var metric = new metricTracker(this);
|
nicholas@3041
|
311 var value = Math.random();
|
n@3009
|
312 trackObj.align = "center";
|
n@3009
|
313 trackObj.className = 'track-slider track-slider-disabled';
|
n@3009
|
314 trackObj.appendChild(labelHolder);
|
n@3009
|
315 axisInterface.sliderRail.appendChild(trackObj);
|
n@3009
|
316 metric.initialise(this.value);
|
n@3009
|
317 this.setLabel = function (s) {
|
n@3009
|
318 label = s;
|
n@3094
|
319 };
|
n@3009
|
320 this.resize = function (event) {
|
n@3009
|
321 var width = $(axisInterface.sliderRail).width();
|
nicholas@3041
|
322 var w = Number(value * width);
|
n@3009
|
323 trackObj.style.left = String(w) + "px";
|
n@3094
|
324 };
|
n@3009
|
325 this.playing = function () {
|
n@3009
|
326 trackObj.classList.add("track-slider-playing");
|
n@3094
|
327 };
|
n@3009
|
328 this.stopped = function () {
|
n@3009
|
329 trackObj.classList.remove("track-slider-playing");
|
n@3094
|
330 };
|
n@3009
|
331 this.enable = function () {
|
n@3009
|
332 trackObj.addEventListener("mousedown", this);
|
n@3009
|
333 trackObj.addEventListener("mouseup", this);
|
n@3009
|
334 trackObj.classList.remove("track-slider-disabled");
|
n@3009
|
335 labelHolder.textContent = label;
|
n@3094
|
336 };
|
n@3009
|
337 this.updateLoading = function (progress) {
|
n@3009
|
338 labelHolder.textContent = progress + "%";
|
n@3094
|
339 };
|
n@3009
|
340 this.exportXMLDOM = function () {
|
n@3009
|
341 var node = storage.document.createElement('value');
|
n@3094
|
342 node.setAttribute("interface-name", axisInterface.name);
|
nicholas@3063
|
343 node.textContent = this.value;
|
n@3009
|
344 return node;
|
n@3094
|
345 };
|
n@3009
|
346 this.error = function () {
|
n@3009
|
347 trackObj.classList.add("error-colour");
|
n@3009
|
348 trackObj.removeEventListener("mousedown");
|
n@3009
|
349 trackObj.removeEventListener("mouseup");
|
n@3094
|
350 };
|
n@3094
|
351 var timing;
|
n@3009
|
352 this.handleEvent = function (e) {
|
n@3009
|
353 // This is only for the mousedown / touchdown
|
n@3009
|
354 if (e.preventDefault) {
|
n@3009
|
355 e.preventDefault();
|
n@3009
|
356 }
|
n@3072
|
357 if (e.type == "mousedown") {
|
n@3009
|
358 axisInterface.mousedown(this);
|
n@3069
|
359 } else if (e.type == "mouseup" || e.type == "touchend" || e.type == "touchcancel") {
|
n@3009
|
360 axisInterface.mouseup(this);
|
nicholas@3064
|
361 metric.moved(audioEngineContext.timer.getTestTime(), this.value);
|
nicholas@3064
|
362 console.log("Slider " + label + " on axis " + axisInterface.name + " moved to " + this.value);
|
n@3009
|
363 }
|
n@3094
|
364 };
|
n@3009
|
365 this.clicked = function (e) {
|
n@3009
|
366 AOI.clicked();
|
n@3094
|
367 };
|
n@3009
|
368 this.pageXMLSave = function (inject) {
|
n@3009
|
369 var nodes = metric.exportXMLDOM(inject);
|
n@3009
|
370 nodes.forEach(function (elem) {
|
n@3009
|
371 var name = elem.getAttribute("name");
|
n@3009
|
372 if (name == "elementTracker" || name == "elementTrackerFull" || name == "elementInitialPosition" || name == "elementFlagMoved") {
|
n@3011
|
373 elem.setAttribute("interface-name", axisInterface.name);
|
n@3011
|
374 } else {
|
n@3011
|
375 inject.removeChild(elem);
|
n@3009
|
376 }
|
n@3009
|
377 });
|
n@3094
|
378 };
|
n@3010
|
379 this.hasMoved = function () {
|
n@3010
|
380 return metric.wasMoved;
|
n@3094
|
381 };
|
n@3009
|
382 Object.defineProperties(this, {
|
n@3009
|
383 "DOM": {
|
n@3009
|
384 "value": trackObj
|
n@3009
|
385 },
|
n@3009
|
386 "value": {
|
nicholas@3041
|
387 "get": function () {
|
nicholas@3041
|
388 return value;
|
nicholas@3041
|
389 },
|
nicholas@3041
|
390 "set": function (v) {
|
nicholas@3041
|
391 if (v >= 0 && v <= 1) {
|
nicholas@3041
|
392 value = v;
|
nicholas@3041
|
393 }
|
nicholas@3041
|
394 this.resize();
|
nicholas@3041
|
395 return value;
|
n@3009
|
396 }
|
n@3009
|
397 },
|
n@3009
|
398 "label": {
|
n@3009
|
399 "get": function () {
|
n@3009
|
400 return label;
|
n@3009
|
401 },
|
n@3009
|
402 "set": function () {}
|
nicholas@3063
|
403 },
|
nicholas@3063
|
404 "metric": {
|
nicholas@3063
|
405 "value": metric
|
n@3009
|
406 }
|
n@3009
|
407 });
|
n@3009
|
408 }
|
n@3009
|
409
|
nicholas@3041
|
410 function drawTick(position) {
|
nicholas@3041
|
411 var context = tickCanvas.getContext("2d"),
|
nicholas@3041
|
412 w = tickCanvas.width,
|
nicholas@3041
|
413 h = tickCanvas.height;
|
nicholas@3041
|
414 context.beginPath();
|
nicholas@3041
|
415 context.setLineDash([1, 2]);
|
nicholas@3041
|
416 context.moveTo(position * w, 0);
|
nicholas@3041
|
417 context.lineTo(position * w, h);
|
nicholas@3041
|
418 context.closePath();
|
nicholas@3041
|
419 context.stroke();
|
nicholas@3041
|
420 }
|
nicholas@3041
|
421
|
nicholas@3041
|
422 function clearTicks() {
|
nicholas@3041
|
423 var c = tickCanvas.getContext("2d"),
|
nicholas@3041
|
424 w = tickCanvas.width,
|
nicholas@3041
|
425 h = tickCanvas.height;
|
nicholas@3041
|
426 c.clearRect(0, 0, w, h);
|
nicholas@3041
|
427 }
|
nicholas@3041
|
428
|
n@3009
|
429 function createScaleMarkers(interfaceObject, root, w) {
|
nicholas@3041
|
430 var ticks = interfaceObject.options.findIndex(function (a) {
|
nicholas@3041
|
431 return (a.type == "show" && a.name == "ticks");
|
nicholas@3041
|
432 });
|
nicholas@3041
|
433 ticks = (ticks >= 0);
|
nicholas@3041
|
434 clearTicks();
|
n@3009
|
435 interfaceObject.scales.forEach(function (scaleObj) {
|
n@3009
|
436 var position = Number(scaleObj.position) * 0.01;
|
n@3009
|
437 var pixelPosition = (position * w) + 50;
|
n@3009
|
438 var scaleDOM = document.createElement('span');
|
n@3009
|
439 scaleDOM.className = "ape-marker-text";
|
n@3009
|
440 scaleDOM.textContent = scaleObj.text;
|
n@3009
|
441 scaleDOM.setAttribute('value', position);
|
n@3009
|
442 root.appendChild(scaleDOM);
|
n@3009
|
443 scaleDOM.style.left = Math.floor((pixelPosition - ($(scaleDOM).width() / 2))) + 'px';
|
nicholas@3041
|
444 if (ticks) {
|
nicholas@3041
|
445 drawTick(position);
|
nicholas@3041
|
446 }
|
n@3009
|
447 }, this);
|
n@3009
|
448 }
|
n@3009
|
449 var sliders = [];
|
n@3009
|
450 var UI = {
|
n@3009
|
451 selected: undefined,
|
n@3009
|
452 startTime: undefined
|
n@3094
|
453 };
|
n@3009
|
454 this.name = interfaceObject.name;
|
n@3009
|
455 var DOMRoot = document.createElement("div");
|
n@3010
|
456 parent.getDOMRoot().appendChild(DOMRoot);
|
n@3009
|
457 DOMRoot.className = "sliderCanvasDiv";
|
n@3009
|
458 DOMRoot.id = "sliderCanvasHolder-" + this.name;
|
n@3009
|
459
|
n@3009
|
460 var axisTitle = document.createElement("div");
|
n@3009
|
461 axisTitle.className = "pageTitle";
|
n@3009
|
462 axisTitle.align = "center";
|
n@3009
|
463 var titleSpan = document.createElement('span');
|
n@3009
|
464 titleSpan.id = "pageTitle-" + this.name;
|
n@3009
|
465 if (interfaceObject.title !== undefined && typeof interfaceObject.title == "string") {
|
n@3009
|
466 titleSpan.textContent = interfaceObject.title;
|
n@3009
|
467 } else {
|
n@3009
|
468 titleSpan.textContent = "Axis " + String(this.id + 1);
|
n@3009
|
469 }
|
n@3009
|
470 axisTitle.appendChild(titleSpan);
|
n@3009
|
471 DOMRoot.appendChild(axisTitle);
|
n@3009
|
472
|
n@3009
|
473 var imageHolder = (function () {
|
n@3009
|
474 var imageController = {};
|
n@3009
|
475 imageController.root = document.createElement("div");
|
n@3009
|
476 imageController.root.className = "imageController";
|
n@3009
|
477 imageController.img = document.createElement("img");
|
n@3009
|
478 imageController.root.appendChild(imageController.img);
|
n@3009
|
479 imageController.setImage = function (src) {
|
n@3009
|
480 imageController.img.src = "";
|
n@3009
|
481 if (typeof src !== "string" || src.length === undefined) {
|
n@3009
|
482 return;
|
n@3009
|
483 }
|
n@3009
|
484 imageController.img.src = src;
|
n@3009
|
485 };
|
n@3009
|
486 return imageController;
|
n@3009
|
487 })();
|
n@3009
|
488 if (interfaceObject.image !== undefined || page.audioElements.some(function (a) {
|
n@3009
|
489 return a.image !== undefined;
|
n@3009
|
490 })) {
|
n@3009
|
491 DOMRoot.appendChild(imageHolder.root);
|
n@3009
|
492 imageHolder.setImage(interfaceObject.image);
|
n@3009
|
493 }
|
n@3009
|
494
|
n@3009
|
495 // Now create the slider box to hold the fragment sliders
|
n@3009
|
496 var sliderRail = document.createElement("div");
|
n@3009
|
497 sliderRail.id = "sliderrail-" + this.name;
|
n@3009
|
498 sliderRail.className = "slider";
|
n@3009
|
499 sliderRail.align = "left";
|
n@3009
|
500 DOMRoot.appendChild(sliderRail);
|
n@3009
|
501
|
nicholas@3041
|
502 // Canvas for the markers
|
nicholas@3041
|
503 var tickCanvas = document.createElement("canvas");
|
nicholas@3041
|
504 tickCanvas.id = "ticks-" + this.name;
|
nicholas@3041
|
505 tickCanvas.className = "tick-canvas";
|
nicholas@3041
|
506 tickCanvas.height = 150;
|
nicholas@3041
|
507 tickCanvas.width = $(sliderRail).width() - 100;
|
nicholas@3041
|
508 tickCanvas.style.width = ($(sliderRail).width() - 100) + "px";
|
nicholas@3041
|
509 sliderRail.appendChild(tickCanvas);
|
nicholas@3041
|
510
|
n@3009
|
511 // Create the div to hold any scale objects
|
n@3009
|
512 var scale = document.createElement("div");
|
n@3009
|
513 scale.className = "sliderScale";
|
n@3009
|
514 scale.id = "slider-scale-holder-" + this.name;
|
n@3009
|
515 scale.slign = "left";
|
n@3009
|
516 DOMRoot.appendChild(scale);
|
n@3009
|
517 createScaleMarkers(interfaceObject, scale, $(sliderRail).width());
|
n@3009
|
518
|
n@3009
|
519 this.resize = function (event) {
|
n@3009
|
520 var w = $(sliderRail).width();
|
n@3009
|
521 var marginsize = 50;
|
n@3009
|
522 sliders.forEach(function (s) {
|
n@3009
|
523 s.resize();
|
n@3009
|
524 });
|
n@3009
|
525 scale.innerHTML = "";
|
nicholas@3041
|
526 tickCanvas.width = $(sliderRail).width();
|
nicholas@3041
|
527 tickCanvas.style.width = tickCanvas.width + "px";
|
n@3009
|
528 createScaleMarkers(interfaceObject, scale, $(sliderRail).width());
|
n@3094
|
529 };
|
n@3009
|
530 this.playing = function (id) {
|
n@3009
|
531 var node = audioEngineContext.audioObjects.find(function (a) {
|
n@3009
|
532 return a.id == id;
|
n@3009
|
533 });
|
n@3009
|
534 if (node === undefined) {
|
n@3009
|
535 this.imageHolder.setImage(interfaceObject.image || "");
|
nicholas@2782
|
536 return;
|
nicholas@2782
|
537 }
|
n@3009
|
538 var imgurl = node.specification.image || interfaceObject.image || "";
|
n@3009
|
539 this.imageHolder.setImage(imgurl);
|
n@2795
|
540 };
|
n@3009
|
541 this.stopped = function () {
|
n@3009
|
542 var imgurl = interfaceObject.image || "";
|
n@3009
|
543 this.imageHolder.setImage(imgurl);
|
n@3094
|
544 };
|
n@3009
|
545 this.addSlider = function (aoi) {
|
n@3009
|
546 var node = new sliderInterface(aoi, this);
|
n@3009
|
547 sliders.push(node);
|
n@3009
|
548 return node;
|
n@3094
|
549 };
|
n@3009
|
550 this.mousedown = function (sliderUI) {
|
n@3009
|
551 UI.selected = sliderUI;
|
n@3009
|
552 UI.startTime = new Date();
|
n@3094
|
553 };
|
n@3076
|
554 this.mouseup = function (event) {
|
n@3009
|
555 var delta = new Date() - UI.startTime;
|
n@3009
|
556 if (delta < 200) {
|
n@3009
|
557 UI.selected.clicked();
|
n@3077
|
558 } else if (event.type == "touchend" || event.type == "touchcancel") {
|
n@3077
|
559 UI.selected.handleEvent(event);
|
n@3009
|
560 }
|
n@3009
|
561 UI.selected = undefined;
|
n@3009
|
562 UI.startTime = undefined;
|
n@3094
|
563 };
|
n@3009
|
564 this.handleEvent = function (event) {
|
n@3095
|
565 // TODO: Functionalise and scope
|
n@3072
|
566 function getTargetSlider(target) {
|
n@3072
|
567 return sliders.find(function (a) {
|
n@3072
|
568 return a.DOM == target;
|
n@3072
|
569 });
|
n@3072
|
570 }
|
nicholas@3063
|
571 var time = audioEngineContext.timer.getTestTime();
|
n@3095
|
572 var move, w;
|
n@3009
|
573 if (event.preventDefault) {
|
n@3009
|
574 event.preventDefault();
|
n@3009
|
575 }
|
n@3072
|
576 if (event.type == "touchstart") {
|
n@3072
|
577 var selected = getTargetSlider(event.target);
|
n@3072
|
578 if (typeof selected != "object") {
|
n@3072
|
579 return;
|
n@3072
|
580 }
|
n@3075
|
581 UI.startTime = new Date();
|
n@3072
|
582 UI.selected = selected;
|
n@3072
|
583 }
|
n@3073
|
584 if (UI.selected === undefined) {
|
n@3073
|
585 return;
|
n@3073
|
586 }
|
n@3009
|
587 if (event.type == "mousemove") {
|
n@3095
|
588 move = event.clientX - 6;
|
n@3095
|
589 w = $(sliderRail).width();
|
n@3009
|
590 move = Math.max(50, move);
|
nicholas@3041
|
591 move = Math.min(w, move);
|
nicholas@3041
|
592 UI.selected.value = (move / w);
|
n@3009
|
593 } else if (event.type == "touchmove") {
|
n@3072
|
594 if (UI.selected == getTargetSlider(event.target)) {
|
n@3072
|
595 if (event.targetTouches) {
|
n@3072
|
596 move = event.targetTouches[0].clientX - 6;
|
n@3072
|
597 } else if (event.originalEvent.targetTouches) {
|
n@3072
|
598 move = event.originalEvent.targetTouches[0].clientX - 6;
|
n@3072
|
599 } else {
|
n@3072
|
600 return;
|
n@3072
|
601 }
|
n@3095
|
602 w = $(event.currentTarget).width();
|
n@3072
|
603 move = Math.max(50, move);
|
n@3072
|
604 move = Math.min(w, move);
|
n@3072
|
605 UI.selected.value = (move / w);
|
n@3067
|
606 }
|
n@3072
|
607 } else if (event.type == "touchend" || event.type == "touchcancel") {
|
n@3072
|
608 if (UI.selected == getTargetSlider(event.target)) {
|
n@3076
|
609 this.mouseup(event);
|
n@3072
|
610 }
|
nicholas@2825
|
611 }
|
n@3094
|
612 };
|
n@3010
|
613 this.checkAllMoved = function () {
|
n@3010
|
614 var notMoved = sliders.filter(function (s) {
|
n@3010
|
615 return !s.hasMoved();
|
n@3010
|
616 });
|
n@3010
|
617 if (notMoved.length !== 0) {
|
n@3010
|
618 var ls = [];
|
n@3010
|
619 notMoved.forEach(function (s) {
|
n@3010
|
620 ls.push(s.label);
|
n@3094
|
621 });
|
n@3010
|
622 var str = "On axis \"" + interfaceObject.title + "\", ";
|
n@3010
|
623 if (ls.length == 1) {
|
n@3010
|
624 str += "slider " + ls[0];
|
n@3010
|
625 } else {
|
n@3010
|
626 str += "sliders " + [ls.slice(0, ls.length - 1).join(", ")].concat(ls[ls.length - 1]).join(" and ");
|
n@3010
|
627 }
|
n@3010
|
628 str += ".";
|
n@3010
|
629 return str;
|
n@3010
|
630 } else {
|
n@3010
|
631 return "";
|
n@3010
|
632 }
|
n@3094
|
633 };
|
n@3010
|
634 this.checkScaleRange = function () {
|
n@3010
|
635 var scaleRange = interfaceObject.options.find(function (a) {
|
n@3010
|
636 return a.name == "scalerange";
|
n@3010
|
637 });
|
n@3010
|
638 if (scaleRange === undefined) {
|
n@3010
|
639 return "";
|
n@3010
|
640 }
|
n@3010
|
641 var scales = {
|
n@3010
|
642 min: scaleRange.min,
|
n@3010
|
643 max: scaleRange.max
|
n@3010
|
644 };
|
n@3010
|
645 var maxSlider = sliders.reduce(function (a, b) {
|
n@3010
|
646 return Math.max(a, b.value);
|
n@3010
|
647 }, 0);
|
n@3010
|
648 var minSlider = sliders.reduce(function (a, b) {
|
n@3010
|
649 return Math.min(a, b.value);
|
n@3010
|
650 }, 100);
|
n@3010
|
651 if (minSlider >= scales.min || maxSlider <= scales.max) {
|
n@3010
|
652 return "On axis \"" + interfaceObject.title + "\", you have not used the required width of the scales";
|
n@3010
|
653 }
|
n@3010
|
654 return "";
|
n@3094
|
655 };
|
n@3009
|
656 sliderRail.addEventListener("mousemove", this);
|
n@3072
|
657 sliderRail.addEventListener("touchstart", this);
|
n@3071
|
658 sliderRail.addEventListener("touchmove", this);
|
n@3072
|
659 sliderRail.addEventListener("touchend", this);
|
n@3072
|
660 sliderRail.addEventListener("touchcancel", this);
|
n@3009
|
661 Object.defineProperties(this, {
|
n@3009
|
662 "sliderRail": {
|
n@3009
|
663 "value": sliderRail
|
nicholas@2825
|
664 }
|
nicholas@2825
|
665 });
|
n@3009
|
666 }
|
n@3009
|
667 this.getDOMRoot = function () {
|
n@3009
|
668 return DOMRoot;
|
n@3094
|
669 };
|
n@3009
|
670 this.getPage = function () {
|
n@3009
|
671 return page;
|
n@3094
|
672 };
|
n@3009
|
673 this.clear = function () {
|
n@3009
|
674 page = undefined;
|
n@3009
|
675 axis = [];
|
n@3009
|
676 AOIs = [];
|
n@3009
|
677 DOMRoot.innerHTML = "";
|
n@3094
|
678 };
|
n@3009
|
679 this.initialisePage = function (page_init) {
|
n@3009
|
680 this.clear();
|
n@3009
|
681 page = page_init;
|
nicholas@3062
|
682 var randomiseAxisOrder;
|
nicholas@3062
|
683 if (page.randomiseAxisOrder !== undefined) {
|
nicholas@3062
|
684 randomiseAxisOrder = page.randomiseAxisOrder;
|
nicholas@3062
|
685 } else {
|
nicholas@3062
|
686 randomiseAxisOrder = page.parent.randomiseAxisOrder;
|
nicholas@3062
|
687 }
|
nicholas@3019
|
688 var commentBoxes = false;
|
n@3009
|
689 // Create each of the interface axis
|
nicholas@3062
|
690 if (randomiseAxisOrder) {
|
nicholas@3062
|
691 page.interfaces = randomiseOrder(page.interfaces);
|
nicholas@3062
|
692 }
|
nicholas@3062
|
693 var interfaceObj = interfaceContext.getCombinedInterfaces(page);
|
n@3009
|
694 interfaceObj.forEach(function (i) {
|
n@3009
|
695 var node = new axisObject(i, this);
|
n@3009
|
696 axis.push(node);
|
nicholas@3019
|
697 i.options.forEach(function (o) {
|
nicholas@3019
|
698 if (o.type == "show" && o.name == "comments") {
|
nicholas@3019
|
699 commentBoxes = true;
|
nicholas@3019
|
700 }
|
nicholas@3019
|
701 });
|
n@3009
|
702 }, this);
|
nicholas@2538
|
703
|
n@3009
|
704 // Create the audioObject interface objects for each aO.
|
n@3009
|
705 page.audioElements.forEach(function (element, index) {
|
n@3009
|
706 var audioObject = audioEngineContext.newTrack(element);
|
n@3009
|
707 if (element.type == 'outside-reference') {
|
n@3009
|
708 // Construct outside reference;
|
n@3009
|
709 var orNode = new outsideReferenceDOM(audioObject, index, document.getElementById("outside-reference-holder"));
|
n@3009
|
710 audioObject.bindInterface(orNode);
|
n@3009
|
711 } else {
|
n@3009
|
712 var aoi = new audioObjectInterface(audioObject, this);
|
n@3011
|
713 AOIs.push(aoi);
|
n@3009
|
714 var label = interfaceContext.getLabel(page.label, index, page.labelStart);
|
n@3009
|
715 axis.forEach(function (a) {
|
n@3009
|
716 var node = a.addSlider(aoi);
|
n@3009
|
717 node.setLabel(label);
|
n@3009
|
718 aoi.addSlider(node);
|
n@3009
|
719 });
|
nicholas@3060
|
720 audioObject.bindInterface(aoi);
|
nicholas@3060
|
721 if (commentBoxes) {
|
nicholas@3060
|
722 interfaceContext.commentBoxes.createCommentBox(audioObject);
|
nicholas@3060
|
723 }
|
n@3009
|
724 }
|
n@3009
|
725 });
|
n@3094
|
726 };
|
n@3010
|
727 this.checkAllMoved = function () {
|
n@3094
|
728 var str = "You have not moved the following sliders. ";
|
n@3010
|
729 var cont = true;
|
n@3010
|
730 axis.forEach(function (a) {
|
n@3010
|
731 var msg = a.checkAllMoved();
|
n@3010
|
732 if (msg.length > 0) {
|
n@3010
|
733 cont = false;
|
n@3010
|
734 str += msg;
|
n@3010
|
735 }
|
n@3010
|
736 });
|
n@3010
|
737 if (!cont) {
|
n@3010
|
738 interfaceContext.lightbox.post("Error", str);
|
n@3010
|
739 interfaceContext.storeErrorNode(str);
|
n@3010
|
740 console.log(str);
|
nicholas@2538
|
741 }
|
n@3010
|
742 return cont;
|
nicholas@2538
|
743 };
|
n@3010
|
744 this.checkScaleRange = function () {
|
n@3010
|
745 var str = "";
|
n@3010
|
746 var cont = true;
|
n@3010
|
747 axis.forEach(function (a) {
|
n@3010
|
748 var msg = a.checkScaleRange();
|
n@3010
|
749 if (msg.length > 0) {
|
n@3010
|
750 cont = false;
|
n@3010
|
751 str += msg;
|
n@3010
|
752 }
|
nicholas@2696
|
753 });
|
n@3010
|
754 if (!cont) {
|
n@3010
|
755 interfaceContext.lightbox.post("Error", str);
|
n@3010
|
756 interfaceContext.storeErrorNode(str);
|
n@3010
|
757 console.log(str);
|
nicholas@2538
|
758 }
|
n@3010
|
759 return cont;
|
nicholas@2538
|
760 };
|
n@3009
|
761 this.pageXMLSave = function (store, pageSpecification) {
|
n@3011
|
762 if (axis.length > 1) {
|
n@3011
|
763 AOIs.forEach(function (ao) {
|
n@3011
|
764 ao.pageXMLSave(store);
|
nicholas@2538
|
765 });
|
nicholas@2538
|
766 }
|
nicholas@2538
|
767 };
|
nicholas@3041
|
768 this.resize = function (event) {
|
nicholas@3041
|
769 axis.forEach(function (a) {
|
nicholas@3041
|
770 a.resize(event);
|
nicholas@2538
|
771 });
|
nicholas@2696
|
772 };
|
nickjillings@1341
|
773 }
|
nickjillings@1341
|
774
|
nicholas@2538
|
775 function outsideReferenceDOM(audioObject, index, inject) {
|
nicholas@2538
|
776 this.parent = audioObject;
|
nicholas@2538
|
777 this.outsideReferenceHolder = document.createElement('div');
|
nicholas@2538
|
778 this.outsideReferenceHolder.id = 'outside-reference';
|
nicholas@2538
|
779 this.outsideReferenceHolder.className = 'outside-reference track-slider-disabled';
|
nicholas@2538
|
780 var outsideReferenceHolderspan = document.createElement('span');
|
nicholas@2538
|
781 outsideReferenceHolderspan.textContent = 'Reference';
|
nicholas@2538
|
782 this.outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
|
nicholas@2538
|
783 this.outsideReferenceHolder.setAttribute('track-id', index);
|
nicholas@2538
|
784
|
nicholas@2696
|
785 this.handleEvent = function (event) {
|
nicholas@2696
|
786 audioEngineContext.play(audioObject.id);
|
nicholas@2538
|
787 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1341
|
788 $('.comment-div').removeClass('comment-box-playing');
|
nicholas@2696
|
789 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nicholas@2538
|
790 };
|
nicholas@2696
|
791 this.outsideReferenceHolder.addEventListener("click", this.handleEvent);
|
nicholas@2538
|
792 inject.appendChild(this.outsideReferenceHolder);
|
nicholas@2538
|
793 this.enable = function () {
|
nicholas@2538
|
794 if (this.parent.state == 1) {
|
nicholas@2538
|
795 $(this.outsideReferenceHolder).removeClass('track-slider-disabled');
|
nicholas@2538
|
796 }
|
nicholas@2538
|
797 };
|
nicholas@2538
|
798 this.updateLoading = function (progress) {
|
nicholas@2538
|
799 if (progress != 100) {
|
nicholas@2538
|
800 progress = String(progress);
|
nicholas@2538
|
801 progress = progress.split('.')[0];
|
nicholas@2538
|
802 this.outsideReferenceHolder.firstChild.textContent = progress + '%';
|
nicholas@2538
|
803 } else {
|
nicholas@2538
|
804 this.outsideReferenceHolder.firstChild.textContent = "Play Reference";
|
nicholas@2538
|
805 }
|
nicholas@2538
|
806 };
|
nicholas@2538
|
807 this.startPlayback = function () {
|
nickjillings@1360
|
808 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1360
|
809 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nickjillings@1360
|
810 $('.comment-div').removeClass('comment-box-playing');
|
nickjillings@1360
|
811 };
|
nicholas@2538
|
812 this.stopPlayback = function () {
|
nickjillings@1360
|
813 $(this.outsideReferenceHolder).removeClass('track-slider-playing');
|
nickjillings@1360
|
814 };
|
nicholas@2538
|
815 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
816 return null;
|
nicholas@2538
|
817 };
|
nicholas@2538
|
818 this.getValue = function () {
|
nicholas@2538
|
819 return 0;
|
nicholas@2538
|
820 };
|
nicholas@2538
|
821 this.getPresentedId = function () {
|
nicholas@2538
|
822 return 'reference';
|
nicholas@2538
|
823 };
|
nicholas@2538
|
824 this.canMove = function () {
|
nicholas@2538
|
825 return false;
|
nicholas@2538
|
826 };
|
nicholas@2538
|
827 this.error = function () {
|
nicholas@2538
|
828 // audioObject has an error!!
|
nickjillings@2113
|
829 this.outsideReferenceHolder.textContent = "Error";
|
nickjillings@2113
|
830 $(this.outsideReferenceHolder).addClass("error-colour");
|
nicholas@2696
|
831 };
|
nickjillings@1341
|
832 }
|
nickjillings@1341
|
833
|
nicholas@2538
|
834 function buttonSubmitClick() {
|
nicholas@2651
|
835 var checks = testState.currentStateMap.interfaces[0].options,
|
nicholas@2651
|
836 canContinue = true;
|
nickjillings@1341
|
837
|
nicholas@2538
|
838 // Check that the anchor and reference objects are correctly placed
|
nicholas@2696
|
839 if (interfaceContext.checkHiddenAnchor() === false) {
|
nicholas@2538
|
840 return;
|
nicholas@2538
|
841 }
|
nicholas@2696
|
842 if (interfaceContext.checkHiddenReference() === false) {
|
nicholas@2538
|
843 return;
|
nicholas@2538
|
844 }
|
nicholas@2825
|
845 if (interfaceContext.checkFragmentMinPlays() === false) {
|
nicholas@2825
|
846 return;
|
nicholas@2825
|
847 }
|
nicholas@3035
|
848 if (interfaceContext.checkCommentQuestions() === false) {
|
nicholas@3035
|
849 return;
|
nicholas@3035
|
850 }
|
nicholas@2538
|
851
|
nicholas@2538
|
852 for (var i = 0; i < checks.length; i++) {
|
n@2795
|
853 var checkState = true;
|
nicholas@2538
|
854 if (checks[i].type == 'check') {
|
nicholas@2538
|
855 switch (checks[i].name) {
|
nicholas@2538
|
856 case 'fragmentPlayed':
|
nicholas@2538
|
857 // Check if all fragments have been played
|
n@2790
|
858 checkState = interfaceContext.checkAllPlayed(checks[i].errorMessage);
|
nicholas@2538
|
859 break;
|
nicholas@2538
|
860 case 'fragmentFullPlayback':
|
nicholas@2538
|
861 // Check all fragments have been played to their full length
|
n@2790
|
862 checkState = interfaceContext.checkFragmentsFullyPlayed(checks[i].errorMessage);
|
nicholas@2538
|
863 break;
|
nicholas@2538
|
864 case 'fragmentMoved':
|
nicholas@2538
|
865 // Check all fragment sliders have been moved.
|
n@2790
|
866 checkState = interfaceContext.checkAllMoved(checks[i].errorMessage);
|
nicholas@2538
|
867 break;
|
nicholas@2538
|
868 case 'fragmentComments':
|
nicholas@2538
|
869 // Check all fragment sliders have been moved.
|
n@2790
|
870 checkState = interfaceContext.checkAllCommented(checks[i].errorMessage);
|
nicholas@2538
|
871 break;
|
nicholas@2538
|
872 case 'scalerange':
|
nicholas@2538
|
873 // Check the scale is used to its full width outlined by the node
|
n@2790
|
874 checkState = interfaceContext.checkScaleRange(checks[i].errorMessage);
|
nicholas@2538
|
875 break;
|
nicholas@2538
|
876 default:
|
nicholas@2538
|
877 console.log("WARNING - Check option " + checks[i].name + " is not supported on this interface");
|
nicholas@2538
|
878 break;
|
nicholas@2538
|
879 }
|
nicholas@2538
|
880
|
nicholas@2538
|
881 }
|
nicholas@2703
|
882 if (checkState === false) {
|
nicholas@2703
|
883 canContinue = false;
|
nicholas@2538
|
884 break;
|
nicholas@2538
|
885 }
|
nicholas@2538
|
886 }
|
nicholas@2538
|
887
|
nickjillings@1341
|
888 if (canContinue) {
|
nicholas@2538
|
889 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
890 var playback = document.getElementById('playback-button');
|
nicholas@2538
|
891 playback.click();
|
nicholas@2538
|
892 // 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
|
893 } else {
|
nicholas@2696
|
894 if (audioEngineContext.timer.testStarted === false) {
|
nicholas@2538
|
895 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click a fragment to begin the test!');
|
nicholas@2538
|
896 return;
|
nicholas@2538
|
897 }
|
nicholas@2538
|
898 }
|
nicholas@2538
|
899 testState.advanceState();
|
nicholas@2538
|
900 }
|
nickjillings@1341
|
901 }
|
nickjillings@1341
|
902
|
nicholas@2538
|
903 function convSliderPosToRate(trackSlider) {
|
nicholas@2538
|
904 var slider = trackSlider.parentElement;
|
nicholas@2538
|
905 var maxPix = $(slider).width();
|
nicholas@2538
|
906 var marginsize = 50;
|
nicholas@2538
|
907 var pix = trackSlider.style.left;
|
nicholas@2538
|
908 pix = pix.substr(0, pix.length - 2);
|
nicholas@2538
|
909 var rate = (pix - marginsize) / maxPix;
|
nicholas@2538
|
910 return rate;
|
nickjillings@1341
|
911 }
|
nickjillings@1341
|
912
|
nicholas@2538
|
913 function resizeWindow(event) {
|
nicholas@2538
|
914 // Function called when the window has been resized.
|
nicholas@2538
|
915 // MANDATORY FUNCTION
|
nicholas@2538
|
916
|
nicholas@2538
|
917 // Resize the slider objects
|
nicholas@3041
|
918 window.module.resize(event);
|
nickjillings@1341
|
919 }
|
nickjillings@1341
|
920
|
nicholas@2538
|
921 function pageXMLSave(store, pageSpecification) {
|
nicholas@2538
|
922 // MANDATORY
|
nicholas@2538
|
923 // Saves a specific test page
|
nicholas@2538
|
924 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nicholas@2538
|
925 // Get the current <page> information in store (remember to appendChild your data to it)
|
nicholas@2538
|
926 // pageSpecification is the current page node configuration
|
nicholas@2538
|
927 // To create new XML nodes, use storage.document.createElement();
|
nicholas@2538
|
928
|
n@3010
|
929 module.pageXMLSave(store, pageSpecification);
|
nicholas@2538
|
930 }
|