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 interfaceContext.checkAllPlayed = function () {
|
nicholas@2696
|
25 var hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nicholas@2538
|
26 if (hasBeenPlayed.length > 0) // if a fragment has not been played yet
|
nicholas@2538
|
27 {
|
nicholas@2538
|
28 var str = "";
|
nicholas@2538
|
29 if (hasBeenPlayed.length > 1) {
|
nicholas@2538
|
30 for (var i = 0; i < hasBeenPlayed.length; i++) {
|
nicholas@2284
|
31 var ao_id = audioEngineContext.audioObjects[hasBeenPlayed[i]].interfaceDOM.getPresentedId();
|
nicholas@2538
|
32 str = str + ao_id; // start from 1
|
nicholas@2538
|
33 if (i < hasBeenPlayed.length - 2) {
|
nicholas@2538
|
34 str += ", ";
|
nicholas@2538
|
35 } else if (i == hasBeenPlayed.length - 2) {
|
nicholas@2538
|
36 str += " or ";
|
nicholas@2538
|
37 }
|
nicholas@2538
|
38 }
|
nicholas@2313
|
39 str = 'You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.';
|
nicholas@2538
|
40 } else {
|
nicholas@2538
|
41 str = 'You have not played fragment ' + (audioEngineContext.audioObjects[hasBeenPlayed[0]].interfaceDOM.getPresentedId()) + ' yet. Please listen, rate and comment all samples before submitting.';
|
nicholas@2538
|
42 }
|
nicholas@2313
|
43 this.storeErrorNode(str);
|
nicholas@2538
|
44 interfaceContext.lightbox.post("Message", str);
|
nicholas@2538
|
45 return false;
|
nicholas@2538
|
46 }
|
nicholas@2538
|
47 return true;
|
nicholas@2538
|
48 };
|
nicholas@2538
|
49
|
nicholas@2538
|
50 interfaceContext.checkAllMoved = function () {
|
nicholas@2538
|
51 var state = true;
|
nicholas@2538
|
52 var str = 'You have not moved the following sliders. ';
|
nicholas@2538
|
53 for (var i = 0; i < this.interfaceSliders.length; i++) {
|
nicholas@2538
|
54 var interfaceTID = [];
|
nicholas@2538
|
55 for (var j = 0; j < this.interfaceSliders[i].metrics.length; j++) {
|
nicholas@2285
|
56 var ao_id = this.interfaceSliders[i].sliders[j].getAttribute("trackIndex");
|
nicholas@2696
|
57 if (this.interfaceSliders[i].metrics[j].wasMoved === false && audioEngineContext.audioObjects[ao_id].interfaceDOM.canMove()) {
|
nicholas@2538
|
58 state = false;
|
nicholas@2538
|
59 interfaceTID.push(j);
|
nicholas@2538
|
60 }
|
nicholas@2538
|
61 }
|
nicholas@2696
|
62 if (interfaceTID.length !== 0) {
|
nicholas@2538
|
63 var interfaceName = this.interfaceSliders[i].interfaceObject.title;
|
nicholas@2696
|
64 if (interfaceName === undefined) {
|
nicholas@2538
|
65 str += 'On axis ' + String(i + 1) + ' you must move ';
|
nicholas@2538
|
66 } else {
|
nicholas@2538
|
67 str += 'On axis "' + interfaceName + '" you must move ';
|
nicholas@2538
|
68 }
|
nicholas@2538
|
69 if (interfaceTID.length == 1) {
|
nicholas@2538
|
70 str += 'slider ' + (audioEngineContext.audioObjects[interfaceTID[0]].interfaceDOM.getPresentedId()) + '. '; // start from 1
|
nicholas@2538
|
71 } else {
|
nicholas@2538
|
72 str += 'sliders ';
|
nicholas@2538
|
73 for (var k = 0; k < interfaceTID.length - 1; k++) {
|
nicholas@2538
|
74 str += (audioEngineContext.audioObjects[interfaceTID[k]].interfaceDOM.getPresentedId()) + ', '; // start from 1
|
nicholas@2538
|
75 }
|
nicholas@2538
|
76 str += (audioEngineContext.audioObjects[interfaceTID[interfaceTID.length - 1]].interfaceDOM.getPresentedId()) + '. ';
|
nicholas@2538
|
77 }
|
nicholas@2538
|
78 }
|
nicholas@2538
|
79 }
|
nicholas@2696
|
80 if (state !== true) {
|
nicholas@2313
|
81 this.storeErrorNode(str);
|
nicholas@2538
|
82 interfaceContext.lightbox.post("Message", str);
|
nicholas@2538
|
83 console.log(str);
|
nicholas@2538
|
84 }
|
nicholas@2538
|
85 return state;
|
nicholas@2538
|
86 };
|
nicholas@2703
|
87
|
nicholas@2698
|
88 interfaceContext.checkScaleRange = function () {
|
nicholas@2538
|
89 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@2538
|
90 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@2696
|
91 var interfaceObject = this.interfaceSliders[0].interfaceObject;
|
nicholas@2538
|
92 var state = true;
|
nicholas@2538
|
93 var str = '';
|
nicholas@2696
|
94 this.interfaceSliders.forEach(function (sliderHolder, i) {
|
nicholas@2696
|
95 var scales = (function () {
|
nicholas@2696
|
96 var scaleRange = interfaceObject.options.find(function (a) {
|
nicholas@2696
|
97 return a.name == "scalerange";
|
nicholas@2696
|
98 });
|
nicholas@2696
|
99 return {
|
nicholas@2696
|
100 min: scaleRange.min,
|
nicholas@2696
|
101 max: scaleRange.max
|
nicholas@2696
|
102 };
|
nicholas@2696
|
103 })();
|
nicholas@2704
|
104 var range = sliderHolder.sliders.reduce(function (a, b) {
|
nicholas@2704
|
105 var v = convSliderPosToRate(b) * 100.0;
|
nicholas@2704
|
106 return {
|
nicholas@2704
|
107 min: Math.min(a.min, v),
|
nicholas@2704
|
108 max: Math.max(a.max, v)
|
nicholas@2538
|
109 }
|
nicholas@2704
|
110 }, {
|
nicholas@2704
|
111 min: 100,
|
nicholas@2704
|
112 max: 0
|
nicholas@2696
|
113 });
|
nicholas@2704
|
114 if (range.min >= scales.min || range.max <= scales.max) {
|
nicholas@2696
|
115 state = false;
|
nicholas@2696
|
116 str += 'On axis "' + sliderHolder.interfaceObject.title + '" you have not used the full width of the scale. ';
|
nicholas@2538
|
117 }
|
nicholas@2696
|
118 });
|
nicholas@2696
|
119 if (state !== true) {
|
nicholas@2313
|
120 this.storeErrorNode(str);
|
nicholas@2538
|
121 interfaceContext.lightbox.post("Message", str);
|
nicholas@2538
|
122 console.log(str);
|
nicholas@2538
|
123 }
|
nicholas@2538
|
124 return state;
|
nicholas@2538
|
125 };
|
nicholas@2538
|
126
|
nicholas@2538
|
127 Interface.prototype.objectSelected = null;
|
nicholas@2538
|
128 Interface.prototype.objectMoved = false;
|
nicholas@2538
|
129 Interface.prototype.selectObject = function (object) {
|
nicholas@2696
|
130 if (this.objectSelected === null) {
|
nicholas@2538
|
131 this.objectSelected = object;
|
nicholas@2538
|
132 this.objectMoved = false;
|
nicholas@2538
|
133 }
|
nicholas@2538
|
134 };
|
nicholas@2538
|
135 Interface.prototype.moveObject = function () {
|
nicholas@2696
|
136 if (this.objectMoved === false) {
|
nicholas@2538
|
137 this.objectMoved = true;
|
nicholas@2538
|
138 }
|
nicholas@2538
|
139 };
|
nicholas@2538
|
140 Interface.prototype.releaseObject = function () {
|
nicholas@2538
|
141 this.objectSelected = null;
|
nicholas@2538
|
142 this.objectMoved = false;
|
nicholas@2538
|
143 };
|
nicholas@2538
|
144 Interface.prototype.getSelectedObject = function () {
|
nicholas@2538
|
145 return this.objectSelected;
|
nicholas@2538
|
146 };
|
nicholas@2538
|
147 Interface.prototype.hasSelectedObjectMoved = function () {
|
nicholas@2538
|
148 return this.objectMoved;
|
nicholas@2538
|
149 };
|
nicholas@2538
|
150
|
nicholas@2538
|
151 // Bindings for slider interfaces
|
nicholas@2538
|
152 Interface.prototype.interfaceSliders = [];
|
nicholas@2538
|
153
|
nicholas@2538
|
154 // Bindings for audioObjects
|
nicholas@2538
|
155
|
nicholas@2538
|
156 // Create the top div for the Title element
|
nicholas@2538
|
157 var titleAttr = specification.title;
|
nicholas@2538
|
158 var title = document.createElement('div');
|
nicholas@2538
|
159 title.className = "title";
|
nicholas@2538
|
160 title.align = "center";
|
nicholas@2538
|
161 var titleSpan = document.createElement('span');
|
nicholas@2470
|
162 titleSpan.id = "test-title";
|
nicholas@2538
|
163
|
nicholas@2538
|
164 // Set title to that defined in XML, else set to default
|
nicholas@2696
|
165 if (titleAttr !== undefined) {
|
nicholas@2538
|
166 titleSpan.textContent = titleAttr;
|
nicholas@2538
|
167 } else {
|
nicholas@2538
|
168 titleSpan.textContent = 'Listening test';
|
nicholas@2538
|
169 }
|
nicholas@2538
|
170 // Insert the titleSpan element into the title div element.
|
nicholas@2538
|
171 title.appendChild(titleSpan);
|
nicholas@2538
|
172
|
nicholas@2538
|
173 // Create Interface buttons!
|
nicholas@2538
|
174 var interfaceButtons = document.createElement('div');
|
nicholas@2538
|
175 interfaceButtons.id = 'interface-buttons';
|
nicholas@2538
|
176
|
nicholas@2538
|
177 // Create playback start/stop points
|
nicholas@2538
|
178 var playback = document.createElement("button");
|
nicholas@2538
|
179 playback.innerHTML = 'Stop';
|
nicholas@2538
|
180 playback.id = 'playback-button';
|
nicholas@2538
|
181 // onclick function. Check if it is playing or not, call the correct function in the
|
nicholas@2538
|
182 // audioEngine, change the button text to reflect the next state.
|
nicholas@2538
|
183 playback.onclick = function () {
|
nicholas@2538
|
184 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
185 audioEngineContext.stop();
|
nicholas@2538
|
186 this.innerHTML = 'Stop';
|
nickjillings@1341
|
187 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1341
|
188 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@2538
|
189 }
|
nicholas@2538
|
190 };
|
nicholas@2538
|
191 // Create Submit (save) button
|
nicholas@2538
|
192 var submit = document.createElement("button");
|
nicholas@2538
|
193 submit.innerHTML = 'Next';
|
nicholas@2538
|
194 submit.onclick = buttonSubmitClick;
|
nicholas@2538
|
195 submit.id = 'submit-button';
|
nicholas@2538
|
196 // Append the interface buttons into the interfaceButtons object.
|
nicholas@2538
|
197 interfaceButtons.appendChild(playback);
|
nicholas@2538
|
198 interfaceButtons.appendChild(submit);
|
nicholas@2538
|
199
|
nicholas@2538
|
200 var sliderHolder = document.createElement("div");
|
nicholas@2538
|
201 sliderHolder.id = "slider-holder";
|
nicholas@2538
|
202
|
nicholas@2396
|
203 // Create outside reference holder
|
nicholas@2396
|
204 var outsideRef = document.createElement("div");
|
nicholas@2396
|
205 outsideRef.id = "outside-reference-holder";
|
nicholas@2538
|
206
|
nicholas@2538
|
207 // Global parent for the comment boxes on the page
|
nicholas@2538
|
208 var feedbackHolder = document.createElement('div');
|
nicholas@2538
|
209 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2538
|
210
|
nicholas@2538
|
211 testContent.style.zIndex = 1;
|
nicholas@2538
|
212 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
|
nicholas@2538
|
213
|
nicholas@2538
|
214 // Inject into HTML
|
nicholas@2538
|
215 testContent.appendChild(title); // Insert the title
|
nicholas@2538
|
216 testContent.appendChild(interfaceButtons);
|
nicholas@2396
|
217 testContent.appendChild(outsideRef);
|
nicholas@2538
|
218 testContent.appendChild(sliderHolder);
|
nicholas@2538
|
219 testContent.appendChild(feedbackHolder);
|
nicholas@2538
|
220 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@1341
|
221
|
nicholas@2538
|
222 // Load the full interface
|
nicholas@2538
|
223 testState.initialise();
|
nicholas@2538
|
224 testState.advanceState();
|
nicholas@2538
|
225
|
nickjillings@1341
|
226 }
|
nickjillings@1341
|
227
|
nicholas@2538
|
228 function loadTest(audioHolderObject) {
|
nicholas@2538
|
229 var width = window.innerWidth;
|
nicholas@2538
|
230 var height = window.innerHeight;
|
nicholas@2538
|
231 var id = audioHolderObject.id;
|
nicholas@2538
|
232
|
nicholas@2538
|
233 interfaceContext.interfaceSliders = [];
|
nicholas@2538
|
234
|
nicholas@2538
|
235 var feedbackHolder = document.getElementById('feedbackHolder');
|
nicholas@2538
|
236 var sliderHolder = document.getElementById('slider-holder');
|
nicholas@2538
|
237 feedbackHolder.innerHTML = "";
|
nicholas@2538
|
238 sliderHolder.innerHTML = "";
|
nicholas@2538
|
239
|
nicholas@2596
|
240 // Set labelType if default to number
|
nicholas@2696
|
241 if (audioHolderObject.label === "default" || audioHolderObject.label === "") {
|
nicholas@2596
|
242 audioHolderObject.label = "number";
|
nicholas@2596
|
243 }
|
nicholas@2470
|
244 // Set the page title
|
nicholas@2470
|
245 if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) {
|
nicholas@2696
|
246 document.getElementById("test-title").textContent = audioHolderObject.title;
|
nicholas@2470
|
247 }
|
nicholas@2538
|
248
|
nicholas@2538
|
249
|
nicholas@2538
|
250 // Delete outside reference
|
nicholas@2538
|
251 document.getElementById("outside-reference-holder").innerHTML = "";
|
nicholas@2538
|
252
|
nicholas@2651
|
253 var interfaceObj = interfaceContext.getCombinedInterfaces(audioHolderObject);
|
nicholas@2696
|
254 interfaceObj.forEach(function (interfaceObjectInstance) {
|
nicholas@2538
|
255 // Create the div box to center align
|
nicholas@2696
|
256 interfaceContext.interfaceSliders.push(new interfaceSliderHolder(interfaceObjectInstance));
|
nicholas@2696
|
257 });
|
nicholas@2651
|
258 interfaceObj.forEach(function (interface) {
|
nicholas@2696
|
259 interface.options.forEach(function (option) {
|
nicholas@2651
|
260 if (option.type == "show") {
|
nicholas@2651
|
261 switch (option.name) {
|
nicholas@2651
|
262 case "playhead":
|
nicholas@2651
|
263 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@2696
|
264 if (playbackHolder === null) {
|
nicholas@2651
|
265 playbackHolder = document.createElement('div');
|
nicholas@2651
|
266 playbackHolder.style.width = "100%";
|
nicholas@2651
|
267 playbackHolder.align = 'center';
|
nicholas@2651
|
268 playbackHolder.appendChild(interfaceContext.playhead.object);
|
nicholas@2651
|
269 feedbackHolder.insertBefore(playbackHolder, feedbackHolder.firstElementChild);
|
nicholas@2651
|
270 }
|
nicholas@2651
|
271 break;
|
nicholas@2651
|
272 case "page-count":
|
nicholas@2651
|
273 var pagecountHolder = document.getElementById('page-count');
|
nicholas@2696
|
274 if (pagecountHolder === null) {
|
nicholas@2651
|
275 pagecountHolder = document.createElement('div');
|
nicholas@2651
|
276 pagecountHolder.id = 'page-count';
|
nicholas@2651
|
277 }
|
nicholas@2651
|
278 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
|
nicholas@2651
|
279 var inject = document.getElementById('interface-buttons');
|
nicholas@2651
|
280 inject.appendChild(pagecountHolder);
|
nicholas@2651
|
281 break;
|
nicholas@2651
|
282 case "volume":
|
nicholas@2696
|
283 if (document.getElementById('master-volume-holder') === null) {
|
nicholas@2651
|
284 feedbackHolder.appendChild(interfaceContext.volume.object);
|
nicholas@2651
|
285 }
|
nicholas@2651
|
286 break;
|
nicholas@2651
|
287 case "comments":
|
nicholas@2651
|
288 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
|
nicholas@2651
|
289 break;
|
nickjillings@1356
|
290 }
|
nickjillings@1356
|
291 }
|
nicholas@2696
|
292 });
|
nicholas@2651
|
293 });
|
nickjillings@1341
|
294
|
nicholas@2538
|
295 var commentBoxPrefix = "Comment on fragment";
|
nicholas@2538
|
296
|
nicholas@2538
|
297 var commentShow = audioHolderObject.elementComments;
|
nicholas@2538
|
298
|
nicholas@2538
|
299 var loopPlayback = audioHolderObject.loop;
|
nicholas@2538
|
300
|
nicholas@2696
|
301 var currentTestHolder = document.createElement('audioHolder');
|
nicholas@2538
|
302 currentTestHolder.id = audioHolderObject.id;
|
nicholas@2538
|
303 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
nicholas@2538
|
304
|
nicholas@2538
|
305 // Find all the audioElements from the audioHolder
|
nicholas@2538
|
306 $(audioHolderObject.audioElements).each(function (index, element) {
|
nicholas@2538
|
307 // Find URL of track
|
nicholas@2538
|
308 // In this jQuery loop, variable 'this' holds the current audioElement.
|
nicholas@2538
|
309 var audioObject = audioEngineContext.newTrack(element);
|
nicholas@2538
|
310 // Check if an outside reference
|
nicholas@2538
|
311 if (element.type == 'outside-reference') {
|
nicholas@2538
|
312 // Construct outside reference;
|
nicholas@2538
|
313 var orNode = new outsideReferenceDOM(audioObject, index, document.getElementById("outside-reference-holder"));
|
nicholas@2538
|
314 audioObject.bindInterface(orNode);
|
nicholas@2538
|
315 } else {
|
nicholas@2538
|
316 // Create a slider per track
|
nicholas@2538
|
317 var sliderNode = new sliderObject(audioObject, interfaceObj, index);
|
nicholas@2538
|
318 audioObject.bindInterface(sliderNode);
|
nickjillings@2117
|
319 interfaceContext.commentBoxes.createCommentBox(audioObject);
|
nicholas@2538
|
320 }
|
nicholas@2538
|
321 });
|
nicholas@2538
|
322
|
nicholas@2538
|
323 // Initialse the interfaceSlider object metrics
|
nicholas@2538
|
324
|
nicholas@2538
|
325 $('.track-slider').mousedown(function (event) {
|
nicholas@2538
|
326 interfaceContext.selectObject($(this)[0]);
|
nicholas@2538
|
327 });
|
nicholas@2538
|
328 $('.track-slider').on('touchstart', null, function (event) {
|
nicholas@2538
|
329 interfaceContext.selectObject($(this)[0]);
|
nicholas@2538
|
330 });
|
nicholas@2538
|
331
|
nicholas@2538
|
332 $('.track-slider').mousemove(function (event) {
|
nicholas@2538
|
333 event.preventDefault();
|
nicholas@2538
|
334 });
|
nicholas@2538
|
335
|
nicholas@2538
|
336 $('.slider').mousemove(function (event) {
|
nicholas@2538
|
337 event.preventDefault();
|
nicholas@2538
|
338 var obj = interfaceContext.getSelectedObject();
|
nicholas@2696
|
339 if (obj === null) {
|
nicholas@2538
|
340 return;
|
nicholas@2538
|
341 }
|
nicholas@2538
|
342 var move = event.clientX - 6;
|
nicholas@2459
|
343 var w = $(event.currentTarget).width();
|
nicholas@2538
|
344 move = Math.max(50, move);
|
nicholas@2538
|
345 move = Math.min(w + 50, move);
|
nicholas@2538
|
346 $(obj).css("left", move + "px");
|
nicholas@2538
|
347 interfaceContext.moveObject();
|
nicholas@2538
|
348 });
|
nicholas@2538
|
349
|
nicholas@2538
|
350 $('.slider').on('touchmove', null, function (event) {
|
nicholas@2538
|
351 event.preventDefault();
|
nicholas@2538
|
352 var obj = interfaceContext.getSelectedObject();
|
nicholas@2696
|
353 if (obj === null) {
|
nicholas@2538
|
354 return;
|
nicholas@2538
|
355 }
|
nicholas@2538
|
356 var move = event.originalEvent.targetTouches[0].clientX - 6;
|
nicholas@2459
|
357 var w = $(event.currentTarget).width();
|
nicholas@2538
|
358 move = Math.max(50, move);
|
nicholas@2538
|
359 move = Math.min(w + 50, move);
|
nicholas@2538
|
360 $(obj).css("left", move + "px");
|
nicholas@2538
|
361 interfaceContext.moveObject();
|
nicholas@2538
|
362 });
|
nickjillings@1341
|
363
|
nicholas@2538
|
364 $(document).mouseup(function (event) {
|
nicholas@2538
|
365 event.preventDefault();
|
nicholas@2538
|
366 var obj = interfaceContext.getSelectedObject();
|
nicholas@2696
|
367 if (obj === null) {
|
nicholas@2538
|
368 return;
|
nicholas@2538
|
369 }
|
nicholas@2538
|
370 var interfaceID = obj.parentElement.getAttribute("interfaceid");
|
nicholas@2538
|
371 var trackID = obj.getAttribute("trackindex");
|
nicholas@2696
|
372 var id;
|
nicholas@2696
|
373 if (interfaceContext.hasSelectedObjectMoved() === true) {
|
nicholas@2538
|
374 var l = $(obj).css("left");
|
nicholas@2696
|
375 id = obj.getAttribute('trackIndex');
|
nicholas@2538
|
376 var time = audioEngineContext.timer.getTestTime();
|
nicholas@2538
|
377 var rate = convSliderPosToRate(obj);
|
nicholas@2538
|
378 audioEngineContext.audioObjects[id].metric.moved(time, rate);
|
nicholas@2538
|
379 interfaceContext.interfaceSliders[interfaceID].metrics[trackID].moved(time, rate);
|
nicholas@2538
|
380 console.log("slider " + id + " moved to " + rate + ' (' + time + ')');
|
nicholas@2538
|
381 obj.setAttribute("slider-value", convSliderPosToRate(obj));
|
nicholas@2538
|
382 } else {
|
nicholas@2696
|
383 id = Number(obj.attributes.trackIndex.value);
|
nicholas@2538
|
384 //audioEngineContext.metric.sliderPlayed(id);
|
nicholas@2538
|
385 audioEngineContext.play(id);
|
nicholas@2538
|
386 }
|
nicholas@2538
|
387 interfaceContext.releaseObject();
|
nicholas@2538
|
388 });
|
nicholas@2538
|
389
|
nicholas@2538
|
390 $('.slider').on('touchend', null, function (event) {
|
nicholas@2538
|
391 var obj = interfaceContext.getSelectedObject();
|
nicholas@2696
|
392 if (obj === null) {
|
nicholas@2538
|
393 return;
|
nicholas@2538
|
394 }
|
nicholas@2538
|
395 var interfaceID = obj.parentElement.getAttribute("interfaceid");
|
nicholas@2538
|
396 var trackID = obj.getAttribute("trackindex");
|
nicholas@2696
|
397 if (interfaceContext.hasSelectedObjectMoved() === true) {
|
nicholas@2538
|
398 var l = $(obj).css("left");
|
nicholas@2538
|
399 var id = obj.getAttribute('trackIndex');
|
nicholas@2538
|
400 var time = audioEngineContext.timer.getTestTime();
|
nicholas@2538
|
401 var rate = convSliderPosToRate(obj);
|
nicholas@2538
|
402 audioEngineContext.audioObjects[id].metric.moved(time, rate);
|
nicholas@2538
|
403 interfaceContext.interfaceSliders[interfaceID].metrics[trackID].moved(time, rate);
|
nicholas@2538
|
404 console.log("slider " + id + " moved to " + rate + ' (' + time + ')');
|
nicholas@2538
|
405 }
|
nicholas@2538
|
406 interfaceContext.releaseObject();
|
nicholas@2538
|
407 });
|
nicholas@2538
|
408
|
n@2407
|
409 var interfaceList = audioHolderObject.interfaces.concat(specification.interfaces);
|
nicholas@2538
|
410 for (var k = 0; k < interfaceList.length; k++) {
|
nicholas@2538
|
411 for (var i = 0; i < interfaceList[k].options.length; i++) {
|
nicholas@2538
|
412 if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'playhead') {
|
n@2407
|
413 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@2696
|
414 if (playbackHolder === null) {
|
n@2407
|
415 playbackHolder = document.createElement('div');
|
n@2407
|
416 playbackHolder.id = "playback-holder";
|
n@2407
|
417 playbackHolder.style.width = "100%";
|
n@2407
|
418 playbackHolder.align = 'center';
|
n@2407
|
419 playbackHolder.appendChild(interfaceContext.playhead.object);
|
n@2407
|
420 feedbackHolder.appendChild(playbackHolder);
|
n@2407
|
421 }
|
nicholas@2538
|
422 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'page-count') {
|
n@2407
|
423 var pagecountHolder = document.getElementById('page-count');
|
nicholas@2696
|
424 if (pagecountHolder === null) {
|
n@2407
|
425 pagecountHolder = document.createElement('div');
|
n@2407
|
426 pagecountHolder.id = 'page-count';
|
n@2407
|
427 }
|
nicholas@2538
|
428 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
|
n@2407
|
429 var inject = document.getElementById('interface-buttons');
|
n@2407
|
430 inject.appendChild(pagecountHolder);
|
n@2407
|
431 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'volume') {
|
nicholas@2696
|
432 if (document.getElementById('master-volume-holder') === null) {
|
n@2407
|
433 feedbackHolder.appendChild(interfaceContext.volume.object);
|
n@2407
|
434 }
|
n@2407
|
435 } else if (interfaceList[k].options[i].type == 'show' && interfaceList[k].options[i].name == 'comments') {
|
nicholas@2538
|
436 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
|
n@2407
|
437 break;
|
n@2407
|
438 }
|
n@2407
|
439 }
|
n@2407
|
440 }
|
nicholas@2538
|
441
|
nicholas@2538
|
442 $(audioHolderObject.commentQuestions).each(function (index, element) {
|
nicholas@2538
|
443 var node = interfaceContext.createCommentQuestion(element);
|
nicholas@2538
|
444 feedbackHolder.appendChild(node.holder);
|
nicholas@2538
|
445 });
|
nicholas@2538
|
446
|
nicholas@2538
|
447 //testWaitIndicator();
|
nickjillings@1341
|
448 }
|
nickjillings@1341
|
449
|
nicholas@2538
|
450 function interfaceSliderHolder(interfaceObject) {
|
nicholas@2538
|
451 this.sliders = [];
|
nicholas@2538
|
452 this.metrics = [];
|
nicholas@2538
|
453 this.id = document.getElementsByClassName("sliderCanvasDiv").length;
|
nicholas@2538
|
454 this.name = interfaceObject.name;
|
nicholas@2538
|
455 this.interfaceObject = interfaceObject;
|
nicholas@2538
|
456 this.sliderDOM = document.createElement('div');
|
nicholas@2538
|
457 this.sliderDOM.className = 'sliderCanvasDiv';
|
nicholas@2538
|
458 this.sliderDOM.id = 'sliderCanvasHolder-' + this.id;
|
nicholas@2782
|
459 this.imageHolder = (function () {
|
nicholas@2782
|
460 var imageController = {};
|
nicholas@2782
|
461 imageController.root = document.createElement("div");
|
nicholas@2782
|
462 imageController.root.className = "imageController";
|
nicholas@2782
|
463 imageController.img = document.createElement("img");
|
nicholas@2782
|
464 imageController.root.appendChild(imageController.img);
|
nicholas@2782
|
465 imageController.setImage = function (src) {
|
nicholas@2782
|
466 imageController.img.src = "";
|
nicholas@2782
|
467 if (typeof src !== "string" || src.length == undefined) {
|
nicholas@2782
|
468 return;
|
nicholas@2782
|
469 }
|
nicholas@2782
|
470 imageController.img.src = src;
|
nicholas@2782
|
471 }
|
nicholas@2782
|
472 return imageController;
|
nicholas@2782
|
473 })();
|
nicholas@2538
|
474
|
nicholas@2538
|
475 var pagetitle = document.createElement('div');
|
nicholas@2538
|
476 pagetitle.className = "pageTitle";
|
nicholas@2538
|
477 pagetitle.align = "center";
|
nicholas@2538
|
478 var titleSpan = document.createElement('span');
|
nicholas@2538
|
479 titleSpan.id = "pageTitle-" + this.id;
|
nicholas@2696
|
480 if (interfaceObject.title !== undefined && typeof interfaceObject.title == "string") {
|
nicholas@2538
|
481 titleSpan.textContent = interfaceObject.title;
|
nicholas@2538
|
482 } else {
|
nicholas@2538
|
483 titleSpan.textContent = "Axis " + String(this.id + 1);
|
nicholas@2538
|
484 }
|
nicholas@2538
|
485 pagetitle.appendChild(titleSpan);
|
nicholas@2538
|
486 this.sliderDOM.appendChild(pagetitle);
|
nicholas@2538
|
487
|
nicholas@2782
|
488 if (interfaceObject.image !== undefined) {
|
nicholas@2782
|
489 this.sliderDOM.appendChild(this.imageHolder.root);
|
nicholas@2782
|
490 this.imageHolder.setImage(interfaceObject.image);
|
nicholas@2782
|
491 }
|
nicholas@2538
|
492 // Create the slider box to hold the slider elements
|
nicholas@2538
|
493 this.canvas = document.createElement('div');
|
nicholas@2696
|
494 if (this.name !== undefined)
|
nicholas@2538
|
495 this.canvas.id = 'slider-' + this.name;
|
nicholas@2538
|
496 else
|
nicholas@2538
|
497 this.canvas.id = 'slider-' + this.id;
|
nicholas@2538
|
498 this.canvas.setAttribute("interfaceid", this.id);
|
nicholas@2538
|
499 this.canvas.className = 'slider';
|
nicholas@2538
|
500 this.canvas.align = "left";
|
nicholas@2538
|
501 this.canvas.addEventListener('dragover', function (event) {
|
nicholas@2538
|
502 event.preventDefault();
|
nicholas@2538
|
503 event.dataTransfer.effectAllowed = 'none';
|
nicholas@2538
|
504 event.dataTransfer.dropEffect = 'copy';
|
nicholas@2538
|
505 return false;
|
nicholas@2538
|
506 }, false);
|
nicholas@2538
|
507 this.sliderDOM.appendChild(this.canvas);
|
nicholas@2538
|
508
|
nicholas@2538
|
509 // Create the div to hold any scale objects
|
nicholas@2538
|
510 this.scale = document.createElement('div');
|
nicholas@2538
|
511 this.scale.className = 'sliderScale';
|
nicholas@2538
|
512 this.scale.id = 'sliderScaleHolder-' + this.id;
|
nicholas@2538
|
513 this.scale.align = 'left';
|
nicholas@2538
|
514 this.sliderDOM.appendChild(this.scale);
|
nicholas@2538
|
515 var positionScale = this.canvas.style.width.substr(0, this.canvas.style.width.length - 2);
|
nicholas@2538
|
516 var offset = 50;
|
nickjillings@1317
|
517 var dest = document.getElementById("slider-holder").appendChild(this.sliderDOM);
|
nicholas@2696
|
518 interfaceObject.scales.forEach(function (scaleObj) {
|
nicholas@2538
|
519 var position = Number(scaleObj.position) * 0.01;
|
nicholas@2538
|
520 var pixelPosition = (position * $(this.canvas).width()) + offset;
|
nicholas@2538
|
521 var scaleDOM = document.createElement('span');
|
nicholas@2391
|
522 scaleDOM.className = "ape-marker-text";
|
nicholas@2538
|
523 scaleDOM.textContent = scaleObj.text;
|
nicholas@2696
|
524 scaleDOM.setAttribute('value', position);
|
nicholas@2538
|
525 this.scale.appendChild(scaleDOM);
|
nicholas@2538
|
526 scaleDOM.style.left = Math.floor((pixelPosition - ($(scaleDOM).width() / 2))) + 'px';
|
nicholas@2696
|
527 }, this);
|
nicholas@2538
|
528
|
nicholas@2538
|
529 this.createSliderObject = function (audioObject, label) {
|
nicholas@2538
|
530 var trackObj = document.createElement('div');
|
nickjillings@1317
|
531 trackObj.align = "center";
|
nicholas@2538
|
532 trackObj.className = 'track-slider track-slider-disabled track-slider-' + audioObject.id;
|
nicholas@2538
|
533 trackObj.id = 'track-slider-' + this.id + '-' + audioObject.id;
|
nicholas@2538
|
534 trackObj.setAttribute('trackIndex', audioObject.id);
|
nicholas@2696
|
535 if (this.name !== undefined) {
|
nicholas@2538
|
536 trackObj.setAttribute('interface-name', this.name);
|
nicholas@2538
|
537 } else {
|
nicholas@2538
|
538 trackObj.setAttribute('interface-name', this.id);
|
nicholas@2538
|
539 }
|
nicholas@2538
|
540 var offset = 50;
|
nicholas@2538
|
541 // Distribute it randomnly
|
nicholas@2538
|
542 var w = window.innerWidth - (offset + 8) * 2;
|
nicholas@2538
|
543 w = Math.random() * w;
|
nicholas@2538
|
544 w = Math.floor(w + (offset + 8));
|
nicholas@2538
|
545 trackObj.style.left = w + 'px';
|
nicholas@2538
|
546 this.canvas.appendChild(trackObj);
|
nicholas@2538
|
547 this.sliders.push(trackObj);
|
nicholas@2538
|
548 this.metrics.push(new metricTracker(this));
|
nicholas@2538
|
549 var labelHolder = document.createElement("span");
|
nickjillings@2168
|
550 labelHolder.textContent = label;
|
nickjillings@2168
|
551 trackObj.appendChild(labelHolder);
|
nicholas@2391
|
552 var rate = convSliderPosToRate(trackObj);
|
nicholas@2538
|
553 this.metrics[this.metrics.length - 1].initialise(rate);
|
nicholas@2538
|
554 trackObj.setAttribute("slider-value", rate);
|
nicholas@2538
|
555 return trackObj;
|
nicholas@2538
|
556 };
|
nicholas@2538
|
557
|
nicholas@2538
|
558 this.resize = function (event) {
|
nicholas@2538
|
559 var sliderDiv = this.canvas;
|
nicholas@2538
|
560 var sliderScaleDiv = this.scale;
|
nicholas@2538
|
561 var width = $(sliderDiv).width();
|
nicholas@2391
|
562 var marginsize = 50;
|
nicholas@2538
|
563 // Move sliders into new position
|
nicholas@2696
|
564 this.sliders.forEach(function (slider, index) {
|
nicholas@2696
|
565 var pix = Number(slider.getAttribute("slider-value")) * width;
|
nicholas@2696
|
566 slider.style.left = (pix + marginsize) + 'px';
|
nicholas@2696
|
567 });
|
nicholas@2538
|
568
|
nicholas@2538
|
569 // Move scale labels
|
nicholas@2538
|
570 for (var index = 0; index < this.scale.children.length; index++) {
|
nicholas@2538
|
571 var scaleObj = this.scale.children[index];
|
nicholas@2696
|
572 var position = Number(scaleObj.attributes.value.value);
|
nicholas@2538
|
573 var pixelPosition = (position * width) + marginsize;
|
nicholas@2538
|
574 scaleObj.style.left = Math.floor((pixelPosition - ($(scaleObj).width() / 2))) + 'px';
|
nicholas@2538
|
575 }
|
nicholas@2538
|
576 };
|
nickjillings@1341
|
577 }
|
nickjillings@1341
|
578
|
nicholas@2538
|
579 function sliderObject(audioObject, interfaceObjects, index) {
|
nicholas@2538
|
580 // Create a new slider object;
|
nicholas@2538
|
581 this.parent = audioObject;
|
nicholas@2538
|
582 this.trackSliderObjects = [];
|
nicholas@2596
|
583 this.label = interfaceContext.getLabel(audioObject.specification.parent.label, index, audioObject.specification.parent.labelStart);
|
n@2428
|
584 this.playing = false;
|
nicholas@2538
|
585 for (var i = 0; i < interfaceContext.interfaceSliders.length; i++) {
|
nicholas@2538
|
586 var trackObj = interfaceContext.interfaceSliders[i].createSliderObject(audioObject, this.label);
|
nicholas@2538
|
587 this.trackSliderObjects.push(trackObj);
|
nicholas@2538
|
588 }
|
nickjillings@1341
|
589
|
nicholas@2538
|
590 // Onclick, switch playback to that track
|
nicholas@2538
|
591
|
nicholas@2538
|
592 this.enable = function () {
|
nicholas@2538
|
593 if (this.parent.state == 1) {
|
nicholas@2538
|
594 $(this.trackSliderObjects).each(function (i, trackObj) {
|
nicholas@2538
|
595 $(trackObj).removeClass('track-slider-disabled');
|
nicholas@2538
|
596 });
|
nicholas@2538
|
597 }
|
nicholas@2538
|
598 };
|
nicholas@2538
|
599 this.updateLoading = function (progress) {
|
nicholas@2538
|
600 if (progress != 100) {
|
nicholas@2538
|
601 progress = String(progress);
|
nicholas@2538
|
602 progress = progress.split('.')[0];
|
nicholas@2538
|
603 this.trackSliderObjects[0].children[0].textContent = progress + '%';
|
nicholas@2538
|
604 } else {
|
nicholas@2538
|
605 this.trackSliderObjects[0].children[0].textContent = this.label;
|
nicholas@2538
|
606 }
|
nicholas@2538
|
607 };
|
nicholas@2538
|
608 this.startPlayback = function () {
|
nickjillings@1360
|
609 $('.track-slider').removeClass('track-slider-playing');
|
nicholas@2538
|
610 var name = ".track-slider-" + this.parent.id;
|
nickjillings@1360
|
611 $(name).addClass('track-slider-playing');
|
nicholas@2726
|
612 interfaceContext.commentBoxes.highlightById(audioObject.id);
|
n@2428
|
613 $('.outside-reference').removeClass('track-slider-playing');
|
n@2428
|
614 this.playing = true;
|
nicholas@2538
|
615
|
n@2428
|
616 if (this.parent.specification.parent.playOne || specification.playOne) {
|
n@2428
|
617 $('.track-slider').addClass('track-slider-disabled');
|
n@2428
|
618 $('.outside-reference').addClass('track-slider-disabled');
|
n@2428
|
619 }
|
nickjillings@1360
|
620 };
|
nicholas@2538
|
621 this.stopPlayback = function () {
|
n@2428
|
622 if (this.playing) {
|
n@2428
|
623 this.playing = false;
|
nicholas@2538
|
624 var name = ".track-slider-" + this.parent.id;
|
n@2428
|
625 $(name).removeClass('track-slider-playing');
|
n@2428
|
626 $('.track-slider').removeClass('track-slider-disabled');
|
n@2428
|
627 $('.outside-reference').removeClass('track-slider-disabled');
|
nicholas@2726
|
628 var box = interfaceContext.commentBoxes.boxes.find(function (a) {
|
nicholas@2726
|
629 return a.id === audioObject.id;
|
nicholas@2726
|
630 });
|
nicholas@2726
|
631 if (box) {
|
nicholas@2726
|
632 box.highlight(false);
|
nicholas@2726
|
633 }
|
n@2428
|
634 }
|
nickjillings@1360
|
635 };
|
nicholas@2538
|
636 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
637 // Called by the audioObject holding this element. Must be present
|
nicholas@2538
|
638 var obj = [];
|
nicholas@2538
|
639 $(this.trackSliderObjects).each(function (i, trackObj) {
|
nicholas@2538
|
640 var node = storage.document.createElement('value');
|
nicholas@2538
|
641 node.setAttribute("interface-name", trackObj.getAttribute("interface-name"));
|
nicholas@2538
|
642 node.textContent = convSliderPosToRate(trackObj);
|
nicholas@2538
|
643 obj.push(node);
|
nicholas@2538
|
644 });
|
nicholas@2538
|
645
|
nicholas@2538
|
646 return obj;
|
nicholas@2538
|
647 };
|
nicholas@2538
|
648 this.getValue = function () {
|
nicholas@2538
|
649 return convSliderPosToRate(this.trackSliderObjects[0]);
|
nicholas@2538
|
650 };
|
nicholas@2538
|
651 this.getPresentedId = function () {
|
nicholas@2538
|
652 return this.label;
|
nicholas@2538
|
653 };
|
nicholas@2538
|
654 this.canMove = function () {
|
nicholas@2538
|
655 return true;
|
nicholas@2538
|
656 };
|
nicholas@2538
|
657 this.error = function () {
|
nicholas@2538
|
658 // audioObject has an error!!
|
nickjillings@2113
|
659 this.playback.textContent = "Error";
|
nickjillings@2113
|
660 $(this.playback).addClass("error-colour");
|
nicholas@2696
|
661 };
|
nickjillings@1341
|
662 }
|
nickjillings@1341
|
663
|
nicholas@2538
|
664 function outsideReferenceDOM(audioObject, index, inject) {
|
nicholas@2538
|
665 this.parent = audioObject;
|
nicholas@2538
|
666 this.outsideReferenceHolder = document.createElement('div');
|
nicholas@2538
|
667 this.outsideReferenceHolder.id = 'outside-reference';
|
nicholas@2538
|
668 this.outsideReferenceHolder.className = 'outside-reference track-slider-disabled';
|
nicholas@2538
|
669 var outsideReferenceHolderspan = document.createElement('span');
|
nicholas@2538
|
670 outsideReferenceHolderspan.textContent = 'Reference';
|
nicholas@2538
|
671 this.outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
|
nicholas@2538
|
672 this.outsideReferenceHolder.setAttribute('track-id', index);
|
nicholas@2538
|
673
|
nicholas@2696
|
674 this.handleEvent = function (event) {
|
nicholas@2696
|
675 audioEngineContext.play(audioObject.id);
|
nicholas@2538
|
676 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1341
|
677 $('.comment-div').removeClass('comment-box-playing');
|
nicholas@2696
|
678 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nicholas@2538
|
679 };
|
nicholas@2696
|
680 this.outsideReferenceHolder.addEventListener("click", this.handleEvent);
|
nicholas@2538
|
681 inject.appendChild(this.outsideReferenceHolder);
|
nicholas@2538
|
682 this.enable = function () {
|
nicholas@2538
|
683 if (this.parent.state == 1) {
|
nicholas@2538
|
684 $(this.outsideReferenceHolder).removeClass('track-slider-disabled');
|
nicholas@2538
|
685 }
|
nicholas@2538
|
686 };
|
nicholas@2538
|
687 this.updateLoading = function (progress) {
|
nicholas@2538
|
688 if (progress != 100) {
|
nicholas@2538
|
689 progress = String(progress);
|
nicholas@2538
|
690 progress = progress.split('.')[0];
|
nicholas@2538
|
691 this.outsideReferenceHolder.firstChild.textContent = progress + '%';
|
nicholas@2538
|
692 } else {
|
nicholas@2538
|
693 this.outsideReferenceHolder.firstChild.textContent = "Play Reference";
|
nicholas@2538
|
694 }
|
nicholas@2538
|
695 };
|
nicholas@2538
|
696 this.startPlayback = function () {
|
nickjillings@1360
|
697 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1360
|
698 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nickjillings@1360
|
699 $('.comment-div').removeClass('comment-box-playing');
|
nickjillings@1360
|
700 };
|
nicholas@2538
|
701 this.stopPlayback = function () {
|
nickjillings@1360
|
702 $(this.outsideReferenceHolder).removeClass('track-slider-playing');
|
nickjillings@1360
|
703 };
|
nicholas@2538
|
704 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
705 return null;
|
nicholas@2538
|
706 };
|
nicholas@2538
|
707 this.getValue = function () {
|
nicholas@2538
|
708 return 0;
|
nicholas@2538
|
709 };
|
nicholas@2538
|
710 this.getPresentedId = function () {
|
nicholas@2538
|
711 return 'reference';
|
nicholas@2538
|
712 };
|
nicholas@2538
|
713 this.canMove = function () {
|
nicholas@2538
|
714 return false;
|
nicholas@2538
|
715 };
|
nicholas@2538
|
716 this.error = function () {
|
nicholas@2538
|
717 // audioObject has an error!!
|
nickjillings@2113
|
718 this.outsideReferenceHolder.textContent = "Error";
|
nickjillings@2113
|
719 $(this.outsideReferenceHolder).addClass("error-colour");
|
nicholas@2696
|
720 };
|
nickjillings@1341
|
721 }
|
nickjillings@1341
|
722
|
nicholas@2538
|
723 function buttonSubmitClick() {
|
nicholas@2651
|
724 var checks = testState.currentStateMap.interfaces[0].options,
|
nicholas@2651
|
725 canContinue = true;
|
nickjillings@1341
|
726
|
nicholas@2538
|
727 // Check that the anchor and reference objects are correctly placed
|
nicholas@2696
|
728 if (interfaceContext.checkHiddenAnchor() === false) {
|
nicholas@2538
|
729 return;
|
nicholas@2538
|
730 }
|
nicholas@2696
|
731 if (interfaceContext.checkHiddenReference() === false) {
|
nicholas@2538
|
732 return;
|
nicholas@2538
|
733 }
|
nicholas@2538
|
734
|
nicholas@2538
|
735 for (var i = 0; i < checks.length; i++) {
|
nicholas@2538
|
736 if (checks[i].type == 'check') {
|
nicholas@2703
|
737 var checkState = true;
|
nicholas@2538
|
738 switch (checks[i].name) {
|
nicholas@2538
|
739 case 'fragmentPlayed':
|
nicholas@2538
|
740 // Check if all fragments have been played
|
nicholas@2696
|
741 checkState = interfaceContext.checkAllPlayed();
|
nicholas@2538
|
742 break;
|
nicholas@2538
|
743 case 'fragmentFullPlayback':
|
nicholas@2538
|
744 // Check all fragments have been played to their full length
|
nicholas@2696
|
745 checkState = interfaceContext.checkFragmentsFullyPlayed();
|
nicholas@2538
|
746 break;
|
nicholas@2538
|
747 case 'fragmentMoved':
|
nicholas@2538
|
748 // Check all fragment sliders have been moved.
|
nicholas@2696
|
749 checkState = interfaceContext.checkAllMoved();
|
nicholas@2538
|
750 break;
|
nicholas@2538
|
751 case 'fragmentComments':
|
nicholas@2538
|
752 // Check all fragment sliders have been moved.
|
nicholas@2696
|
753 checkState = interfaceContext.checkAllCommented();
|
nicholas@2538
|
754 break;
|
nicholas@2538
|
755 case 'scalerange':
|
nicholas@2538
|
756 // Check the scale is used to its full width outlined by the node
|
nicholas@2696
|
757 checkState = interfaceContext.checkScaleRange();
|
nicholas@2538
|
758 break;
|
nicholas@2538
|
759 default:
|
nicholas@2538
|
760 console.log("WARNING - Check option " + checks[i].name + " is not supported on this interface");
|
nicholas@2538
|
761 break;
|
nicholas@2538
|
762 }
|
nicholas@2538
|
763
|
nicholas@2538
|
764 }
|
nicholas@2703
|
765 if (checkState === false) {
|
nicholas@2703
|
766 canContinue = false;
|
nicholas@2538
|
767 break;
|
nicholas@2538
|
768 }
|
nicholas@2538
|
769 }
|
nicholas@2538
|
770
|
nickjillings@1341
|
771 if (canContinue) {
|
nicholas@2538
|
772 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
773 var playback = document.getElementById('playback-button');
|
nicholas@2538
|
774 playback.click();
|
nicholas@2538
|
775 // 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
|
776 } else {
|
nicholas@2696
|
777 if (audioEngineContext.timer.testStarted === false) {
|
nicholas@2538
|
778 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click a fragment to begin the test!');
|
nicholas@2538
|
779 return;
|
nicholas@2538
|
780 }
|
nicholas@2538
|
781 }
|
nicholas@2538
|
782 testState.advanceState();
|
nicholas@2538
|
783 }
|
nickjillings@1341
|
784 }
|
nickjillings@1341
|
785
|
nicholas@2538
|
786 function convSliderPosToRate(trackSlider) {
|
nicholas@2538
|
787 var slider = trackSlider.parentElement;
|
nicholas@2538
|
788 var maxPix = $(slider).width();
|
nicholas@2538
|
789 var marginsize = 50;
|
nicholas@2538
|
790 var pix = trackSlider.style.left;
|
nicholas@2538
|
791 pix = pix.substr(0, pix.length - 2);
|
nicholas@2538
|
792 var rate = (pix - marginsize) / maxPix;
|
nicholas@2538
|
793 return rate;
|
nickjillings@1341
|
794 }
|
nickjillings@1341
|
795
|
nicholas@2538
|
796 function resizeWindow(event) {
|
nicholas@2538
|
797 // Function called when the window has been resized.
|
nicholas@2538
|
798 // MANDATORY FUNCTION
|
nicholas@2538
|
799
|
nicholas@2538
|
800 // Resize the slider objects
|
nicholas@2538
|
801 for (var i = 0; i < interfaceContext.interfaceSliders.length; i++) {
|
nicholas@2538
|
802 interfaceContext.interfaceSliders[i].resize(event);
|
nicholas@2538
|
803 }
|
nickjillings@1341
|
804 }
|
nickjillings@1341
|
805
|
nicholas@2538
|
806 function pageXMLSave(store, pageSpecification) {
|
nicholas@2538
|
807 // MANDATORY
|
nicholas@2538
|
808 // Saves a specific test page
|
nicholas@2538
|
809 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nicholas@2538
|
810 // Get the current <page> information in store (remember to appendChild your data to it)
|
nicholas@2538
|
811 // pageSpecification is the current page node configuration
|
nicholas@2538
|
812 // To create new XML nodes, use storage.document.createElement();
|
nicholas@2538
|
813
|
nicholas@2538
|
814 if (interfaceContext.interfaceSliders.length == 1) {
|
nicholas@2538
|
815 // If there is only one axis, there only needs to be one metric return
|
nicholas@2538
|
816 return;
|
nicholas@2538
|
817 }
|
nicholas@2538
|
818 var audioelements = store.getElementsByTagName("audioelement");
|
nicholas@2538
|
819 for (var i = 0; i < audioelements.length; i++) {
|
nicholas@2538
|
820 // Have to append the metric specific nodes
|
nicholas@2696
|
821 if (pageSpecification.outsideReference === undefined || pageSpecification.outsideReference.id != audioelements[i].id) {
|
nicholas@2538
|
822 var inject = audioelements[i].getElementsByTagName("metric");
|
nicholas@2696
|
823 if (inject.length === 0) {
|
nicholas@2538
|
824 inject = storage.document.createElement("metric");
|
nicholas@2538
|
825 } else {
|
nicholas@2538
|
826 inject = inject[0];
|
nicholas@2538
|
827 }
|
nicholas@2538
|
828 for (var k = 0; k < interfaceContext.interfaceSliders.length; k++) {
|
nicholas@2538
|
829 var mrnodes = interfaceContext.interfaceSliders[k].metrics[i].exportXMLDOM(inject);
|
nicholas@2538
|
830 for (var j = 0; j < mrnodes.length; j++) {
|
nicholas@2538
|
831 var name = mrnodes[j].getAttribute("name");
|
nicholas@2538
|
832 if (name == "elementTracker" || name == "elementTrackerFull" || name == "elementInitialPosition" || name == "elementFlagMoved") {
|
nicholas@2538
|
833 mrnodes[j].setAttribute("interface-name", interfaceContext.interfaceSliders[k].name);
|
nicholas@2538
|
834 mrnodes[j].setAttribute("interface-id", k);
|
nicholas@2538
|
835 }
|
nicholas@2538
|
836 }
|
nicholas@2538
|
837 }
|
nicholas@2538
|
838 }
|
nicholas@2538
|
839 }
|
nicholas@2538
|
840 }
|