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 */
|
nicholas@2696
|
7 /*globals metricTracker */
|
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();
|
nickjillings@1341
|
217 }
|
nickjillings@1341
|
218
|
n@3009
|
219 function ape() {
|
n@3009
|
220 var axis = []
|
n@3009
|
221 var DOMRoot = document.getElementById("slider-holder");
|
n@3009
|
222 var AOIs = [];
|
n@3009
|
223 var page = undefined;
|
n@3009
|
224
|
n@3009
|
225 function audioObjectInterface(audioObject, parent) {
|
n@3009
|
226 // The audioObject communicates with this object
|
n@3009
|
227 var playing = false;
|
n@3009
|
228 var sliders = [];
|
n@3009
|
229 this.enable = function () {
|
n@3009
|
230 sliders.forEach(function (s) {
|
n@3009
|
231 s.enable();
|
nicholas@3019
|
232 });
|
n@3009
|
233 }
|
n@3009
|
234
|
n@3009
|
235 this.updateLoading = function (p) {
|
n@3009
|
236 sliders.forEach(function (s) {
|
n@3009
|
237 s.updateLoading(p);
|
nicholas@3019
|
238 });
|
n@3009
|
239 }
|
n@3009
|
240
|
n@3009
|
241 this.startPlayback = function () {
|
n@3009
|
242 playing = true;
|
n@3009
|
243 sliders.forEach(function (s) {
|
n@3009
|
244 s.playing();
|
n@3009
|
245 });
|
n@3009
|
246 }
|
n@3009
|
247
|
n@3009
|
248 this.stopPlayback = function () {
|
n@3009
|
249 playing = false;
|
n@3009
|
250 sliders.forEach(function (s) {
|
n@3009
|
251 s.stopped();
|
n@3009
|
252 });
|
n@3009
|
253 }
|
n@3009
|
254
|
n@3009
|
255 this.getValue = function () {
|
n@3009
|
256 return sliders[0].value();
|
n@3009
|
257 }
|
n@3009
|
258
|
n@3009
|
259 this.getPresentedId = function () {
|
n@3009
|
260 return sliders[0].label;
|
n@3009
|
261 }
|
n@3009
|
262
|
n@3009
|
263 this.canMove = function () {
|
n@3009
|
264 return true;
|
n@3009
|
265 }
|
n@3009
|
266
|
n@3009
|
267 this.exportXMLDOM = function (audioObject) {
|
n@3009
|
268 var elements = [];
|
n@3009
|
269 sliders.forEach(function (s) {
|
n@3009
|
270 elements.push(s.exportXMLDOM());
|
n@3009
|
271 });
|
n@3009
|
272 return elements;
|
n@3009
|
273 }
|
n@3009
|
274
|
n@3009
|
275 this.error = function () {
|
n@3009
|
276 sliders.forEach(function (s) {
|
n@3009
|
277 s.error();
|
n@3009
|
278 });
|
n@3009
|
279 }
|
n@3009
|
280
|
n@3009
|
281 this.addSlider = function (s) {
|
n@3009
|
282 sliders.push(s);
|
n@3009
|
283 }
|
n@3009
|
284
|
n@3009
|
285 this.clicked = function (event) {
|
n@3009
|
286 if (!playing) {
|
n@3009
|
287 audioEngineContext.play(audioObject.id);
|
n@3009
|
288 } else {
|
n@3009
|
289 audioEngineContext.stop();
|
n@3009
|
290 }
|
n@3009
|
291 playing = !playing;
|
n@3009
|
292 }
|
n@3009
|
293
|
n@3009
|
294 this.pageXMLSave = function (store) {
|
n@3009
|
295 var inject = audioObject.storeDOM.getElementsByTagName("metric")[0];
|
n@3009
|
296 sliders.forEach(function (s) {
|
n@3009
|
297 s.pageXMLSave(inject);
|
n@3009
|
298 });
|
n@3009
|
299 }
|
n@3009
|
300
|
n@3009
|
301 }
|
n@3009
|
302
|
n@3009
|
303 function axisObject(interfaceObject, parent) {
|
n@3009
|
304
|
n@3009
|
305 function sliderInterface(AOI, axisInterface) {
|
n@3009
|
306 var trackObj = document.createElement('div');
|
n@3009
|
307 var labelHolder = document.createElement("span");
|
n@3009
|
308 var label = "";
|
n@3009
|
309 var metric = new metricTracker(this);
|
n@3009
|
310 trackObj.align = "center";
|
n@3009
|
311 trackObj.className = 'track-slider track-slider-disabled';
|
n@3009
|
312 trackObj.appendChild(labelHolder);
|
n@3011
|
313 trackObj.style.left = (Math.random() * $(sliderRail).width()) + 50 + "px";
|
n@3009
|
314 axisInterface.sliderRail.appendChild(trackObj);
|
n@3009
|
315 metric.initialise(this.value);
|
n@3009
|
316 this.setLabel = function (s) {
|
n@3009
|
317 label = s;
|
n@3009
|
318 }
|
n@3009
|
319 this.resize = function (event) {
|
n@3009
|
320 var width = $(axisInterface.sliderRail).width();
|
n@3009
|
321 var w = Number(value * width + 50);
|
n@3009
|
322 trackObj.style.left = String(w) + "px";
|
n@3009
|
323 }
|
n@3009
|
324 this.playing = function () {
|
n@3009
|
325 trackObj.classList.add("track-slider-playing");
|
n@3009
|
326 }
|
n@3009
|
327 this.stopped = function () {
|
n@3009
|
328 trackObj.classList.remove("track-slider-playing");
|
n@3009
|
329 }
|
n@3009
|
330 this.enable = function () {
|
n@3009
|
331 trackObj.addEventListener("mousedown", this);
|
n@3009
|
332 trackObj.addEventListener("mouseup", this);
|
n@3009
|
333 trackObj.addEventListener("touchstart", this);
|
n@3009
|
334 trackObj.classList.remove("track-slider-disabled");
|
n@3009
|
335 labelHolder.textContent = label;
|
n@3009
|
336 }
|
n@3009
|
337 this.updateLoading = function (progress) {
|
n@3009
|
338 labelHolder.textContent = progress + "%";
|
n@3009
|
339 }
|
n@3009
|
340 this.exportXMLDOM = function () {
|
n@3009
|
341 var node = storage.document.createElement('value');
|
n@3009
|
342 node.setAttribute("interface-name", axisInterface.name)
|
n@3009
|
343 node.textContent = this.value();
|
n@3009
|
344 return node;
|
n@3009
|
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@3009
|
350 trackObj.removeEventListener("touchstart");
|
n@3009
|
351 }
|
n@3009
|
352 var timing = undefined;
|
n@3009
|
353 this.handleEvent = function (e) {
|
n@3009
|
354 // This is only for the mousedown / touchdown
|
n@3009
|
355 if (e.preventDefault) {
|
n@3009
|
356 e.preventDefault();
|
n@3009
|
357 }
|
n@3009
|
358 if (e.type == "mousedown" || e.type == "touchstart") {
|
n@3009
|
359 axisInterface.mousedown(this);
|
n@3009
|
360 } else if (e.type == "mouseup") {
|
n@3009
|
361 axisInterface.mouseup(this);
|
n@3009
|
362 }
|
n@3009
|
363 }
|
n@3009
|
364 this.clicked = function (e) {
|
n@3009
|
365 AOI.clicked();
|
n@3009
|
366 }
|
n@3009
|
367 this.pageXMLSave = function (inject) {
|
n@3009
|
368 var nodes = metric.exportXMLDOM(inject);
|
n@3009
|
369 nodes.forEach(function (elem) {
|
n@3009
|
370 var name = elem.getAttribute("name");
|
n@3009
|
371 if (name == "elementTracker" || name == "elementTrackerFull" || name == "elementInitialPosition" || name == "elementFlagMoved") {
|
n@3011
|
372 elem.setAttribute("interface-name", axisInterface.name);
|
n@3011
|
373 } else {
|
n@3011
|
374 inject.removeChild(elem);
|
n@3009
|
375 }
|
n@3009
|
376 });
|
n@3009
|
377 }
|
n@3010
|
378 this.hasMoved = function () {
|
n@3010
|
379 return metric.wasMoved;
|
n@3010
|
380 }
|
n@3009
|
381 Object.defineProperties(this, {
|
n@3009
|
382 "DOM": {
|
n@3009
|
383 "value": trackObj
|
n@3009
|
384 },
|
n@3009
|
385 "value": {
|
n@3009
|
386 "value": function () {
|
n@3009
|
387 var maxPix = $(axisInterface.sliderRail).width();
|
n@3009
|
388 var pix = trackObj.style.left.substr(0, trackObj.style.left.length - 2);
|
n@3009
|
389 return (pix - 50) / maxPix;
|
n@3009
|
390 }
|
n@3009
|
391 },
|
n@3009
|
392 "moveToPixel": {
|
n@3009
|
393 "value": function (pix) {
|
n@3009
|
394 var t = audioEngineContext.timer.getTestTime();
|
n@3009
|
395 trackObj.style.left = String(pix) + "px";
|
n@3009
|
396 metric.moved(t, this.value);
|
n@3009
|
397 }
|
n@3009
|
398 },
|
n@3009
|
399 "label": {
|
n@3009
|
400 "get": function () {
|
n@3009
|
401 return label;
|
n@3009
|
402 },
|
n@3009
|
403 "set": function () {}
|
n@3009
|
404 }
|
n@3009
|
405 });
|
n@3009
|
406 }
|
n@3009
|
407
|
n@3009
|
408 function createScaleMarkers(interfaceObject, root, w) {
|
n@3009
|
409 interfaceObject.scales.forEach(function (scaleObj) {
|
n@3009
|
410 var position = Number(scaleObj.position) * 0.01;
|
n@3009
|
411 var pixelPosition = (position * w) + 50;
|
n@3009
|
412 var scaleDOM = document.createElement('span');
|
n@3009
|
413 scaleDOM.className = "ape-marker-text";
|
n@3009
|
414 scaleDOM.textContent = scaleObj.text;
|
n@3009
|
415 scaleDOM.setAttribute('value', position);
|
n@3009
|
416 root.appendChild(scaleDOM);
|
n@3009
|
417 scaleDOM.style.left = Math.floor((pixelPosition - ($(scaleDOM).width() / 2))) + 'px';
|
n@3009
|
418 }, this);
|
n@3009
|
419 }
|
n@3009
|
420 var sliders = [];
|
n@3009
|
421 var UI = {
|
n@3009
|
422 selected: undefined,
|
n@3009
|
423 startTime: undefined
|
n@3009
|
424 }
|
n@3009
|
425 this.name = interfaceObject.name;
|
n@3009
|
426 var DOMRoot = document.createElement("div");
|
n@3010
|
427 parent.getDOMRoot().appendChild(DOMRoot);
|
n@3009
|
428 DOMRoot.className = "sliderCanvasDiv";
|
n@3009
|
429 DOMRoot.id = "sliderCanvasHolder-" + this.name;
|
n@3009
|
430 var sliders = [];
|
n@3009
|
431
|
n@3009
|
432 var axisTitle = document.createElement("div");
|
n@3009
|
433 axisTitle.className = "pageTitle";
|
n@3009
|
434 axisTitle.align = "center";
|
n@3009
|
435 var titleSpan = document.createElement('span');
|
n@3009
|
436 titleSpan.id = "pageTitle-" + this.name;
|
n@3009
|
437 if (interfaceObject.title !== undefined && typeof interfaceObject.title == "string") {
|
n@3009
|
438 titleSpan.textContent = interfaceObject.title;
|
n@3009
|
439 } else {
|
n@3009
|
440 titleSpan.textContent = "Axis " + String(this.id + 1);
|
n@3009
|
441 }
|
n@3009
|
442 axisTitle.appendChild(titleSpan);
|
n@3009
|
443 DOMRoot.appendChild(axisTitle);
|
n@3009
|
444
|
n@3009
|
445 var imageHolder = (function () {
|
n@3009
|
446 var imageController = {};
|
n@3009
|
447 imageController.root = document.createElement("div");
|
n@3009
|
448 imageController.root.className = "imageController";
|
n@3009
|
449 imageController.img = document.createElement("img");
|
n@3009
|
450 imageController.root.appendChild(imageController.img);
|
n@3009
|
451 imageController.setImage = function (src) {
|
n@3009
|
452 imageController.img.src = "";
|
n@3009
|
453 if (typeof src !== "string" || src.length === undefined) {
|
n@3009
|
454 return;
|
n@3009
|
455 }
|
n@3009
|
456 imageController.img.src = src;
|
n@3009
|
457 };
|
n@3009
|
458 return imageController;
|
n@3009
|
459 })();
|
n@3009
|
460 if (interfaceObject.image !== undefined || page.audioElements.some(function (a) {
|
n@3009
|
461 return a.image !== undefined;
|
n@3009
|
462 })) {
|
n@3009
|
463 DOMRoot.appendChild(imageHolder.root);
|
n@3009
|
464 imageHolder.setImage(interfaceObject.image);
|
n@3009
|
465 }
|
n@3009
|
466
|
n@3009
|
467 // Now create the slider box to hold the fragment sliders
|
n@3009
|
468 var sliderRail = document.createElement("div");
|
n@3009
|
469 sliderRail.id = "sliderrail-" + this.name;
|
n@3009
|
470 sliderRail.className = "slider";
|
n@3009
|
471 sliderRail.align = "left";
|
n@3009
|
472 DOMRoot.appendChild(sliderRail);
|
n@3009
|
473
|
n@3009
|
474 // Create the div to hold any scale objects
|
n@3009
|
475 var scale = document.createElement("div");
|
n@3009
|
476 scale.className = "sliderScale";
|
n@3009
|
477 scale.id = "slider-scale-holder-" + this.name;
|
n@3009
|
478 scale.slign = "left";
|
n@3009
|
479 DOMRoot.appendChild(scale);
|
n@3009
|
480 createScaleMarkers(interfaceObject, scale, $(sliderRail).width());
|
n@3009
|
481
|
n@3009
|
482 this.resize = function (event) {
|
n@3009
|
483 var w = $(sliderRail).width();
|
n@3009
|
484 var marginsize = 50;
|
n@3009
|
485 sliders.forEach(function (s) {
|
n@3009
|
486 s.resize();
|
n@3009
|
487 });
|
n@3009
|
488 scale.innerHTML = "";
|
n@3009
|
489 createScaleMarkers(interfaceObject, scale, $(sliderRail).width());
|
n@3009
|
490 }
|
n@3009
|
491 this.playing = function (id) {
|
n@3009
|
492 var node = audioEngineContext.audioObjects.find(function (a) {
|
n@3009
|
493 return a.id == id;
|
n@3009
|
494 });
|
n@3009
|
495 if (node === undefined) {
|
n@3009
|
496 this.imageHolder.setImage(interfaceObject.image || "");
|
nicholas@2782
|
497 return;
|
nicholas@2782
|
498 }
|
n@3009
|
499 var imgurl = node.specification.image || interfaceObject.image || "";
|
n@3009
|
500 this.imageHolder.setImage(imgurl);
|
nicholas@2538
|
501 }
|
n@3009
|
502 this.stopped = function () {
|
n@3009
|
503 var imgurl = interfaceObject.image || "";
|
n@3009
|
504 this.imageHolder.setImage(imgurl);
|
nicholas@2538
|
505 }
|
n@3009
|
506 this.addSlider = function (aoi) {
|
n@3009
|
507 var node = new sliderInterface(aoi, this);
|
n@3009
|
508 sliders.push(node);
|
n@3009
|
509 return node;
|
n@2796
|
510 }
|
n@3009
|
511 this.mousedown = function (sliderUI) {
|
n@3009
|
512 UI.selected = sliderUI;
|
n@3009
|
513 UI.startTime = new Date();
|
nicholas@2538
|
514 }
|
n@3009
|
515 this.mouseup = function (sliderUI) {
|
n@3009
|
516 var delta = new Date() - UI.startTime;
|
n@3009
|
517 if (delta < 200) {
|
n@3009
|
518 UI.selected.clicked();
|
n@3009
|
519 }
|
n@3009
|
520 UI.selected = undefined;
|
n@3009
|
521 UI.startTime = undefined;
|
nicholas@2538
|
522 }
|
n@3009
|
523 this.handleEvent = function (event) {
|
n@3009
|
524 if (event.preventDefault) {
|
n@3009
|
525 event.preventDefault();
|
n@3009
|
526 }
|
n@3009
|
527 if (UI.selected === undefined) {
|
n@3009
|
528 return;
|
n@3009
|
529 }
|
n@3009
|
530 if (event.type == "mousemove") {
|
n@3009
|
531 var move = event.clientX - 6;
|
n@3009
|
532 var w = $(sliderRail).width();
|
n@3009
|
533 move = Math.max(50, move);
|
n@3009
|
534 move = Math.min(w + 50, move);
|
n@3009
|
535 UI.selected.moveToPixel(move);
|
n@3009
|
536 } else if (event.type == "touchmove") {
|
n@3009
|
537 var move = event.originalEvent.targetTouches[0].clientX - 6;
|
n@3009
|
538 var w = $(event.currentTarget).width();
|
n@3009
|
539 move = Math.max(50, move);
|
n@3009
|
540 move = Math.min(w + 50, move);
|
n@3009
|
541 UI.selected.moveToPixel(move);
|
nicholas@2726
|
542 }
|
n@2428
|
543 }
|
n@3010
|
544 this.checkAllMoved = function () {
|
n@3010
|
545 var notMoved = sliders.filter(function (s) {
|
n@3010
|
546 return !s.hasMoved();
|
n@3010
|
547 });
|
n@3010
|
548 if (notMoved.length !== 0) {
|
n@3010
|
549 var ls = [];
|
n@3010
|
550 notMoved.forEach(function (s) {
|
n@3010
|
551 ls.push(s.label);
|
n@3010
|
552 })
|
n@3010
|
553 var str = "On axis \"" + interfaceObject.title + "\", ";
|
n@3010
|
554 if (ls.length == 1) {
|
n@3010
|
555 str += "slider " + ls[0];
|
n@3010
|
556 } else {
|
n@3010
|
557 str += "sliders " + [ls.slice(0, ls.length - 1).join(", ")].concat(ls[ls.length - 1]).join(" and ");
|
n@3010
|
558 }
|
n@3010
|
559 str += ".";
|
n@3010
|
560 return str;
|
n@3010
|
561 } else {
|
n@3010
|
562 return "";
|
n@3010
|
563 }
|
n@3010
|
564 }
|
n@3010
|
565 this.checkScaleRange = function () {
|
n@3010
|
566 var scaleRange = interfaceObject.options.find(function (a) {
|
n@3010
|
567 return a.name == "scalerange";
|
n@3010
|
568 });
|
n@3010
|
569 if (scaleRange === undefined) {
|
n@3010
|
570 return "";
|
n@3010
|
571 }
|
n@3010
|
572 var scales = {
|
n@3010
|
573 min: scaleRange.min,
|
n@3010
|
574 max: scaleRange.max
|
n@3010
|
575 };
|
n@3010
|
576 var maxSlider = sliders.reduce(function (a, b) {
|
n@3010
|
577 return Math.max(a, b.value);
|
n@3010
|
578 }, 0);
|
n@3010
|
579 var minSlider = sliders.reduce(function (a, b) {
|
n@3010
|
580 return Math.min(a, b.value);
|
n@3010
|
581 }, 100);
|
n@3010
|
582 if (minSlider >= scales.min || maxSlider <= scales.max) {
|
n@3010
|
583 return "On axis \"" + interfaceObject.title + "\", you have not used the required width of the scales";
|
n@3010
|
584 }
|
n@3010
|
585 return "";
|
n@3010
|
586 }
|
n@3009
|
587 sliderRail.addEventListener("mousemove", this);
|
n@3009
|
588 sliderRail.addEventListener("touchmove", this);
|
n@3009
|
589 Object.defineProperties(this, {
|
n@3009
|
590 "sliderRail": {
|
n@3009
|
591 "value": sliderRail
|
nicholas@2820
|
592 }
|
nicholas@2538
|
593 });
|
n@3009
|
594 }
|
n@3009
|
595 this.getDOMRoot = function () {
|
n@3009
|
596 return DOMRoot;
|
n@3009
|
597 }
|
n@3009
|
598 this.getPage = function () {
|
n@3009
|
599 return page;
|
n@3009
|
600 }
|
n@3009
|
601 this.clear = function () {
|
n@3009
|
602 page = undefined;
|
n@3009
|
603 axis = [];
|
n@3009
|
604 AOIs = [];
|
n@3009
|
605 DOMRoot.innerHTML = "";
|
n@3009
|
606 }
|
n@3009
|
607 this.initialisePage = function (page_init) {
|
n@3009
|
608 this.clear();
|
n@3009
|
609 page = page_init;
|
n@3009
|
610 var interfaceObj = interfaceContext.getCombinedInterfaces(page);
|
nicholas@3019
|
611 var commentBoxes = false;
|
n@3009
|
612 // Create each of the interface axis
|
n@3009
|
613 interfaceObj.forEach(function (i) {
|
n@3009
|
614 var node = new axisObject(i, this);
|
n@3009
|
615 axis.push(node);
|
nicholas@3019
|
616 i.options.forEach(function (o) {
|
nicholas@3019
|
617 if (o.type == "show" && o.name == "comments") {
|
nicholas@3019
|
618 commentBoxes = true;
|
nicholas@3019
|
619 }
|
nicholas@3019
|
620 });
|
n@3009
|
621 }, this);
|
nicholas@2538
|
622
|
n@3009
|
623 // Create the audioObject interface objects for each aO.
|
n@3009
|
624 page.audioElements.forEach(function (element, index) {
|
n@3009
|
625 var audioObject = audioEngineContext.newTrack(element);
|
n@3009
|
626 if (element.type == 'outside-reference') {
|
n@3009
|
627 // Construct outside reference;
|
n@3009
|
628 var orNode = new outsideReferenceDOM(audioObject, index, document.getElementById("outside-reference-holder"));
|
n@3009
|
629 audioObject.bindInterface(orNode);
|
n@3009
|
630 } else {
|
n@3009
|
631 var aoi = new audioObjectInterface(audioObject, this);
|
n@3011
|
632 AOIs.push(aoi);
|
n@3009
|
633 var label = interfaceContext.getLabel(page.label, index, page.labelStart);
|
n@3009
|
634 axis.forEach(function (a) {
|
n@3009
|
635 var node = a.addSlider(aoi);
|
n@3009
|
636 node.setLabel(label);
|
n@3009
|
637 aoi.addSlider(node);
|
n@3009
|
638 audioObject.bindInterface(aoi);
|
nicholas@3019
|
639 if (commentBoxes) {
|
nicholas@3019
|
640 interfaceContext.commentBoxes.createCommentBox(audioObject);
|
nicholas@3019
|
641 }
|
n@3009
|
642 });
|
n@3009
|
643 }
|
n@3009
|
644 });
|
n@3009
|
645 }
|
n@3010
|
646 this.checkAllMoved = function () {
|
n@3010
|
647 var str = "You have not moved the following sliders. "
|
n@3010
|
648 var cont = true;
|
n@3010
|
649 axis.forEach(function (a) {
|
n@3010
|
650 var msg = a.checkAllMoved();
|
n@3010
|
651 if (msg.length > 0) {
|
n@3010
|
652 cont = false;
|
n@3010
|
653 str += msg;
|
n@3010
|
654 }
|
n@3010
|
655 });
|
n@3010
|
656 if (!cont) {
|
n@3010
|
657 interfaceContext.lightbox.post("Error", str);
|
n@3010
|
658 interfaceContext.storeErrorNode(str);
|
n@3010
|
659 console.log(str);
|
n@3010
|
660 }
|
n@3010
|
661 return cont;
|
n@3010
|
662 }
|
n@3010
|
663 this.checkScaleRange = function () {
|
n@3010
|
664 var str = "";
|
n@3010
|
665 var cont = true;
|
n@3010
|
666 axis.forEach(function (a) {
|
n@3010
|
667 var msg = a.checkScaleRange();
|
n@3010
|
668 if (msg.length > 0) {
|
n@3010
|
669 cont = false;
|
n@3010
|
670 str += msg;
|
n@3010
|
671 }
|
n@3010
|
672 });
|
n@3010
|
673 if (!cont) {
|
n@3010
|
674 interfaceContext.lightbox.post("Error", str);
|
n@3010
|
675 interfaceContext.storeErrorNode(str);
|
n@3010
|
676 console.log(str);
|
n@3010
|
677 }
|
n@3010
|
678 return cont;
|
n@3010
|
679 }
|
n@3009
|
680 this.pageXMLSave = function (store, pageSpecification) {
|
n@3011
|
681 if (axis.length > 1) {
|
n@3011
|
682 AOIs.forEach(function (ao) {
|
n@3011
|
683 ao.pageXMLSave(store);
|
n@3011
|
684 });
|
n@3011
|
685 }
|
n@3009
|
686 }
|
nickjillings@1341
|
687 }
|
nickjillings@1341
|
688
|
nicholas@2538
|
689 function outsideReferenceDOM(audioObject, index, inject) {
|
nicholas@2538
|
690 this.parent = audioObject;
|
nicholas@2538
|
691 this.outsideReferenceHolder = document.createElement('div');
|
nicholas@2538
|
692 this.outsideReferenceHolder.id = 'outside-reference';
|
nicholas@2538
|
693 this.outsideReferenceHolder.className = 'outside-reference track-slider-disabled';
|
nicholas@2538
|
694 var outsideReferenceHolderspan = document.createElement('span');
|
nicholas@2538
|
695 outsideReferenceHolderspan.textContent = 'Reference';
|
nicholas@2538
|
696 this.outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
|
nicholas@2538
|
697 this.outsideReferenceHolder.setAttribute('track-id', index);
|
nicholas@2538
|
698
|
nicholas@2696
|
699 this.handleEvent = function (event) {
|
nicholas@2696
|
700 audioEngineContext.play(audioObject.id);
|
nicholas@2538
|
701 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1341
|
702 $('.comment-div').removeClass('comment-box-playing');
|
nicholas@2696
|
703 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nicholas@2538
|
704 };
|
nicholas@2696
|
705 this.outsideReferenceHolder.addEventListener("click", this.handleEvent);
|
nicholas@2538
|
706 inject.appendChild(this.outsideReferenceHolder);
|
nicholas@2538
|
707 this.enable = function () {
|
nicholas@2538
|
708 if (this.parent.state == 1) {
|
nicholas@2538
|
709 $(this.outsideReferenceHolder).removeClass('track-slider-disabled');
|
nicholas@2538
|
710 }
|
nicholas@2538
|
711 };
|
nicholas@2538
|
712 this.updateLoading = function (progress) {
|
nicholas@2538
|
713 if (progress != 100) {
|
nicholas@2538
|
714 progress = String(progress);
|
nicholas@2538
|
715 progress = progress.split('.')[0];
|
nicholas@2538
|
716 this.outsideReferenceHolder.firstChild.textContent = progress + '%';
|
nicholas@2538
|
717 } else {
|
nicholas@2538
|
718 this.outsideReferenceHolder.firstChild.textContent = "Play Reference";
|
nicholas@2538
|
719 }
|
nicholas@2538
|
720 };
|
nicholas@2538
|
721 this.startPlayback = function () {
|
nickjillings@1360
|
722 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1360
|
723 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nickjillings@1360
|
724 $('.comment-div').removeClass('comment-box-playing');
|
nickjillings@1360
|
725 };
|
nicholas@2538
|
726 this.stopPlayback = function () {
|
nickjillings@1360
|
727 $(this.outsideReferenceHolder).removeClass('track-slider-playing');
|
nickjillings@1360
|
728 };
|
nicholas@2538
|
729 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
730 return null;
|
nicholas@2538
|
731 };
|
nicholas@2538
|
732 this.getValue = function () {
|
nicholas@2538
|
733 return 0;
|
nicholas@2538
|
734 };
|
nicholas@2538
|
735 this.getPresentedId = function () {
|
nicholas@2538
|
736 return 'reference';
|
nicholas@2538
|
737 };
|
nicholas@2538
|
738 this.canMove = function () {
|
nicholas@2538
|
739 return false;
|
nicholas@2538
|
740 };
|
nicholas@2538
|
741 this.error = function () {
|
nicholas@2538
|
742 // audioObject has an error!!
|
nickjillings@2113
|
743 this.outsideReferenceHolder.textContent = "Error";
|
nickjillings@2113
|
744 $(this.outsideReferenceHolder).addClass("error-colour");
|
nicholas@2696
|
745 };
|
nickjillings@1341
|
746 }
|
nickjillings@1341
|
747
|
nicholas@2538
|
748 function buttonSubmitClick() {
|
nicholas@2651
|
749 var checks = testState.currentStateMap.interfaces[0].options,
|
nicholas@2651
|
750 canContinue = true;
|
nickjillings@1341
|
751
|
nicholas@2538
|
752 // Check that the anchor and reference objects are correctly placed
|
nicholas@2696
|
753 if (interfaceContext.checkHiddenAnchor() === false) {
|
nicholas@2538
|
754 return;
|
nicholas@2538
|
755 }
|
nicholas@2696
|
756 if (interfaceContext.checkHiddenReference() === false) {
|
nicholas@2538
|
757 return;
|
nicholas@2538
|
758 }
|
nicholas@2825
|
759 if (interfaceContext.checkFragmentMinPlays() === false) {
|
nicholas@2825
|
760 return;
|
nicholas@2825
|
761 }
|
nicholas@3035
|
762 if (interfaceContext.checkCommentQuestions() === false) {
|
nicholas@3035
|
763 return;
|
nicholas@3035
|
764 }
|
nicholas@2538
|
765
|
nicholas@2538
|
766 for (var i = 0; i < checks.length; i++) {
|
n@2795
|
767 var checkState = true;
|
nicholas@2538
|
768 if (checks[i].type == 'check') {
|
nicholas@2538
|
769 switch (checks[i].name) {
|
nicholas@2538
|
770 case 'fragmentPlayed':
|
nicholas@2538
|
771 // Check if all fragments have been played
|
n@2790
|
772 checkState = interfaceContext.checkAllPlayed(checks[i].errorMessage);
|
nicholas@2538
|
773 break;
|
nicholas@2538
|
774 case 'fragmentFullPlayback':
|
nicholas@2538
|
775 // Check all fragments have been played to their full length
|
n@2790
|
776 checkState = interfaceContext.checkFragmentsFullyPlayed(checks[i].errorMessage);
|
nicholas@2538
|
777 break;
|
nicholas@2538
|
778 case 'fragmentMoved':
|
nicholas@2538
|
779 // Check all fragment sliders have been moved.
|
n@2790
|
780 checkState = interfaceContext.checkAllMoved(checks[i].errorMessage);
|
nicholas@2538
|
781 break;
|
nicholas@2538
|
782 case 'fragmentComments':
|
nicholas@2538
|
783 // Check all fragment sliders have been moved.
|
n@2790
|
784 checkState = interfaceContext.checkAllCommented(checks[i].errorMessage);
|
nicholas@2538
|
785 break;
|
nicholas@2538
|
786 case 'scalerange':
|
nicholas@2538
|
787 // Check the scale is used to its full width outlined by the node
|
n@2790
|
788 checkState = interfaceContext.checkScaleRange(checks[i].errorMessage);
|
nicholas@2538
|
789 break;
|
nicholas@2538
|
790 default:
|
nicholas@2538
|
791 console.log("WARNING - Check option " + checks[i].name + " is not supported on this interface");
|
nicholas@2538
|
792 break;
|
nicholas@2538
|
793 }
|
nicholas@2538
|
794
|
nicholas@2538
|
795 }
|
nicholas@2703
|
796 if (checkState === false) {
|
nicholas@2703
|
797 canContinue = false;
|
nicholas@2538
|
798 break;
|
nicholas@2538
|
799 }
|
nicholas@2538
|
800 }
|
nicholas@2538
|
801
|
nickjillings@1341
|
802 if (canContinue) {
|
nicholas@2538
|
803 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
804 var playback = document.getElementById('playback-button');
|
nicholas@2538
|
805 playback.click();
|
nicholas@2538
|
806 // 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
|
807 } else {
|
nicholas@2696
|
808 if (audioEngineContext.timer.testStarted === false) {
|
nicholas@2538
|
809 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click a fragment to begin the test!');
|
nicholas@2538
|
810 return;
|
nicholas@2538
|
811 }
|
nicholas@2538
|
812 }
|
nicholas@2538
|
813 testState.advanceState();
|
nicholas@2538
|
814 }
|
nickjillings@1341
|
815 }
|
nickjillings@1341
|
816
|
nicholas@2538
|
817 function convSliderPosToRate(trackSlider) {
|
nicholas@2538
|
818 var slider = trackSlider.parentElement;
|
nicholas@2538
|
819 var maxPix = $(slider).width();
|
nicholas@2538
|
820 var marginsize = 50;
|
nicholas@2538
|
821 var pix = trackSlider.style.left;
|
nicholas@2538
|
822 pix = pix.substr(0, pix.length - 2);
|
nicholas@2538
|
823 var rate = (pix - marginsize) / maxPix;
|
nicholas@2538
|
824 return rate;
|
nickjillings@1341
|
825 }
|
nickjillings@1341
|
826
|
nicholas@2538
|
827 function resizeWindow(event) {
|
nicholas@2538
|
828 // Function called when the window has been resized.
|
nicholas@2538
|
829 // MANDATORY FUNCTION
|
nicholas@2538
|
830
|
nicholas@2538
|
831 // Resize the slider objects
|
nicholas@2538
|
832 for (var i = 0; i < interfaceContext.interfaceSliders.length; i++) {
|
nicholas@2538
|
833 interfaceContext.interfaceSliders[i].resize(event);
|
nicholas@2538
|
834 }
|
nickjillings@1341
|
835 }
|
nickjillings@1341
|
836
|
nicholas@2538
|
837 function pageXMLSave(store, pageSpecification) {
|
nicholas@2538
|
838 // MANDATORY
|
nicholas@2538
|
839 // Saves a specific test page
|
nicholas@2538
|
840 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nicholas@2538
|
841 // Get the current <page> information in store (remember to appendChild your data to it)
|
nicholas@2538
|
842 // pageSpecification is the current page node configuration
|
nicholas@2538
|
843 // To create new XML nodes, use storage.document.createElement();
|
nicholas@2538
|
844
|
n@3010
|
845 module.pageXMLSave(store, pageSpecification);
|
nicholas@2538
|
846 }
|