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