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@2538
|
459
|
nicholas@2538
|
460 var pagetitle = document.createElement('div');
|
nicholas@2538
|
461 pagetitle.className = "pageTitle";
|
nicholas@2538
|
462 pagetitle.align = "center";
|
nicholas@2538
|
463 var titleSpan = document.createElement('span');
|
nicholas@2538
|
464 titleSpan.id = "pageTitle-" + this.id;
|
nicholas@2696
|
465 if (interfaceObject.title !== undefined && typeof interfaceObject.title == "string") {
|
nicholas@2538
|
466 titleSpan.textContent = interfaceObject.title;
|
nicholas@2538
|
467 } else {
|
nicholas@2538
|
468 titleSpan.textContent = "Axis " + String(this.id + 1);
|
nicholas@2538
|
469 }
|
nicholas@2538
|
470 pagetitle.appendChild(titleSpan);
|
nicholas@2538
|
471 this.sliderDOM.appendChild(pagetitle);
|
nicholas@2538
|
472
|
nicholas@2538
|
473 // Create the slider box to hold the slider elements
|
nicholas@2538
|
474 this.canvas = document.createElement('div');
|
nicholas@2696
|
475 if (this.name !== undefined)
|
nicholas@2538
|
476 this.canvas.id = 'slider-' + this.name;
|
nicholas@2538
|
477 else
|
nicholas@2538
|
478 this.canvas.id = 'slider-' + this.id;
|
nicholas@2538
|
479 this.canvas.setAttribute("interfaceid", this.id);
|
nicholas@2538
|
480 this.canvas.className = 'slider';
|
nicholas@2538
|
481 this.canvas.align = "left";
|
nicholas@2538
|
482 this.canvas.addEventListener('dragover', function (event) {
|
nicholas@2538
|
483 event.preventDefault();
|
nicholas@2538
|
484 event.dataTransfer.effectAllowed = 'none';
|
nicholas@2538
|
485 event.dataTransfer.dropEffect = 'copy';
|
nicholas@2538
|
486 return false;
|
nicholas@2538
|
487 }, false);
|
nicholas@2538
|
488 this.sliderDOM.appendChild(this.canvas);
|
nicholas@2538
|
489
|
nicholas@2538
|
490 // Create the div to hold any scale objects
|
nicholas@2538
|
491 this.scale = document.createElement('div');
|
nicholas@2538
|
492 this.scale.className = 'sliderScale';
|
nicholas@2538
|
493 this.scale.id = 'sliderScaleHolder-' + this.id;
|
nicholas@2538
|
494 this.scale.align = 'left';
|
nicholas@2538
|
495 this.sliderDOM.appendChild(this.scale);
|
nicholas@2538
|
496 var positionScale = this.canvas.style.width.substr(0, this.canvas.style.width.length - 2);
|
nicholas@2538
|
497 var offset = 50;
|
nickjillings@1317
|
498 var dest = document.getElementById("slider-holder").appendChild(this.sliderDOM);
|
nicholas@2696
|
499 interfaceObject.scales.forEach(function (scaleObj) {
|
nicholas@2538
|
500 var position = Number(scaleObj.position) * 0.01;
|
nicholas@2538
|
501 var pixelPosition = (position * $(this.canvas).width()) + offset;
|
nicholas@2538
|
502 var scaleDOM = document.createElement('span');
|
nicholas@2391
|
503 scaleDOM.className = "ape-marker-text";
|
nicholas@2538
|
504 scaleDOM.textContent = scaleObj.text;
|
nicholas@2696
|
505 scaleDOM.setAttribute('value', position);
|
nicholas@2538
|
506 this.scale.appendChild(scaleDOM);
|
nicholas@2538
|
507 scaleDOM.style.left = Math.floor((pixelPosition - ($(scaleDOM).width() / 2))) + 'px';
|
nicholas@2696
|
508 }, this);
|
nicholas@2538
|
509
|
nicholas@2538
|
510 this.createSliderObject = function (audioObject, label) {
|
nicholas@2538
|
511 var trackObj = document.createElement('div');
|
nickjillings@1317
|
512 trackObj.align = "center";
|
nicholas@2538
|
513 trackObj.className = 'track-slider track-slider-disabled track-slider-' + audioObject.id;
|
nicholas@2538
|
514 trackObj.id = 'track-slider-' + this.id + '-' + audioObject.id;
|
nicholas@2538
|
515 trackObj.setAttribute('trackIndex', audioObject.id);
|
nicholas@2696
|
516 if (this.name !== undefined) {
|
nicholas@2538
|
517 trackObj.setAttribute('interface-name', this.name);
|
nicholas@2538
|
518 } else {
|
nicholas@2538
|
519 trackObj.setAttribute('interface-name', this.id);
|
nicholas@2538
|
520 }
|
nicholas@2538
|
521 var offset = 50;
|
nicholas@2538
|
522 // Distribute it randomnly
|
nicholas@2538
|
523 var w = window.innerWidth - (offset + 8) * 2;
|
nicholas@2538
|
524 w = Math.random() * w;
|
nicholas@2538
|
525 w = Math.floor(w + (offset + 8));
|
nicholas@2538
|
526 trackObj.style.left = w + 'px';
|
nicholas@2538
|
527 this.canvas.appendChild(trackObj);
|
nicholas@2538
|
528 this.sliders.push(trackObj);
|
nicholas@2538
|
529 this.metrics.push(new metricTracker(this));
|
nicholas@2538
|
530 var labelHolder = document.createElement("span");
|
nickjillings@2168
|
531 labelHolder.textContent = label;
|
nickjillings@2168
|
532 trackObj.appendChild(labelHolder);
|
nicholas@2391
|
533 var rate = convSliderPosToRate(trackObj);
|
nicholas@2538
|
534 this.metrics[this.metrics.length - 1].initialise(rate);
|
nicholas@2538
|
535 trackObj.setAttribute("slider-value", rate);
|
nicholas@2538
|
536 return trackObj;
|
nicholas@2538
|
537 };
|
nicholas@2538
|
538
|
nicholas@2538
|
539 this.resize = function (event) {
|
nicholas@2538
|
540 var sliderDiv = this.canvas;
|
nicholas@2538
|
541 var sliderScaleDiv = this.scale;
|
nicholas@2538
|
542 var width = $(sliderDiv).width();
|
nicholas@2391
|
543 var marginsize = 50;
|
nicholas@2538
|
544 // Move sliders into new position
|
nicholas@2696
|
545 this.sliders.forEach(function (slider, index) {
|
nicholas@2696
|
546 var pix = Number(slider.getAttribute("slider-value")) * width;
|
nicholas@2696
|
547 slider.style.left = (pix + marginsize) + 'px';
|
nicholas@2696
|
548 });
|
nicholas@2538
|
549
|
nicholas@2538
|
550 // Move scale labels
|
nicholas@2538
|
551 for (var index = 0; index < this.scale.children.length; index++) {
|
nicholas@2538
|
552 var scaleObj = this.scale.children[index];
|
nicholas@2696
|
553 var position = Number(scaleObj.attributes.value.value);
|
nicholas@2538
|
554 var pixelPosition = (position * width) + marginsize;
|
nicholas@2538
|
555 scaleObj.style.left = Math.floor((pixelPosition - ($(scaleObj).width() / 2))) + 'px';
|
nicholas@2538
|
556 }
|
nicholas@2538
|
557 };
|
nickjillings@1341
|
558 }
|
nickjillings@1341
|
559
|
nicholas@2538
|
560 function sliderObject(audioObject, interfaceObjects, index) {
|
nicholas@2538
|
561 // Create a new slider object;
|
nicholas@2538
|
562 this.parent = audioObject;
|
nicholas@2538
|
563 this.trackSliderObjects = [];
|
nicholas@2596
|
564 this.label = interfaceContext.getLabel(audioObject.specification.parent.label, index, audioObject.specification.parent.labelStart);
|
n@2428
|
565 this.playing = false;
|
nicholas@2538
|
566 for (var i = 0; i < interfaceContext.interfaceSliders.length; i++) {
|
nicholas@2538
|
567 var trackObj = interfaceContext.interfaceSliders[i].createSliderObject(audioObject, this.label);
|
nicholas@2538
|
568 this.trackSliderObjects.push(trackObj);
|
nicholas@2538
|
569 }
|
nickjillings@1341
|
570
|
nicholas@2538
|
571 // Onclick, switch playback to that track
|
nicholas@2538
|
572
|
nicholas@2538
|
573 this.enable = function () {
|
nicholas@2538
|
574 if (this.parent.state == 1) {
|
nicholas@2538
|
575 $(this.trackSliderObjects).each(function (i, trackObj) {
|
nicholas@2538
|
576 $(trackObj).removeClass('track-slider-disabled');
|
nicholas@2538
|
577 });
|
nicholas@2538
|
578 }
|
nicholas@2538
|
579 };
|
nicholas@2538
|
580 this.updateLoading = function (progress) {
|
nicholas@2538
|
581 if (progress != 100) {
|
nicholas@2538
|
582 progress = String(progress);
|
nicholas@2538
|
583 progress = progress.split('.')[0];
|
nicholas@2538
|
584 this.trackSliderObjects[0].children[0].textContent = progress + '%';
|
nicholas@2538
|
585 } else {
|
nicholas@2538
|
586 this.trackSliderObjects[0].children[0].textContent = this.label;
|
nicholas@2538
|
587 }
|
nicholas@2538
|
588 };
|
nicholas@2538
|
589 this.startPlayback = function () {
|
nickjillings@1360
|
590 $('.track-slider').removeClass('track-slider-playing');
|
nicholas@2538
|
591 var name = ".track-slider-" + this.parent.id;
|
nickjillings@1360
|
592 $(name).addClass('track-slider-playing');
|
nicholas@2726
|
593 interfaceContext.commentBoxes.highlightById(audioObject.id);
|
n@2428
|
594 $('.outside-reference').removeClass('track-slider-playing');
|
n@2428
|
595 this.playing = true;
|
nicholas@2538
|
596
|
n@2428
|
597 if (this.parent.specification.parent.playOne || specification.playOne) {
|
n@2428
|
598 $('.track-slider').addClass('track-slider-disabled');
|
n@2428
|
599 $('.outside-reference').addClass('track-slider-disabled');
|
n@2428
|
600 }
|
nickjillings@1360
|
601 };
|
nicholas@2538
|
602 this.stopPlayback = function () {
|
n@2428
|
603 if (this.playing) {
|
n@2428
|
604 this.playing = false;
|
nicholas@2538
|
605 var name = ".track-slider-" + this.parent.id;
|
n@2428
|
606 $(name).removeClass('track-slider-playing');
|
n@2428
|
607 $('.track-slider').removeClass('track-slider-disabled');
|
n@2428
|
608 $('.outside-reference').removeClass('track-slider-disabled');
|
nicholas@2726
|
609 var box = interfaceContext.commentBoxes.boxes.find(function (a) {
|
nicholas@2726
|
610 return a.id === audioObject.id;
|
nicholas@2726
|
611 });
|
nicholas@2726
|
612 if (box) {
|
nicholas@2726
|
613 box.highlight(false);
|
nicholas@2726
|
614 }
|
n@2428
|
615 }
|
nickjillings@1360
|
616 };
|
nicholas@2538
|
617 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
618 // Called by the audioObject holding this element. Must be present
|
nicholas@2538
|
619 var obj = [];
|
nicholas@2538
|
620 $(this.trackSliderObjects).each(function (i, trackObj) {
|
nicholas@2538
|
621 var node = storage.document.createElement('value');
|
nicholas@2538
|
622 node.setAttribute("interface-name", trackObj.getAttribute("interface-name"));
|
nicholas@2538
|
623 node.textContent = convSliderPosToRate(trackObj);
|
nicholas@2538
|
624 obj.push(node);
|
nicholas@2538
|
625 });
|
nicholas@2538
|
626
|
nicholas@2538
|
627 return obj;
|
nicholas@2538
|
628 };
|
nicholas@2538
|
629 this.getValue = function () {
|
nicholas@2538
|
630 return convSliderPosToRate(this.trackSliderObjects[0]);
|
nicholas@2538
|
631 };
|
nicholas@2538
|
632 this.getPresentedId = function () {
|
nicholas@2538
|
633 return this.label;
|
nicholas@2538
|
634 };
|
nicholas@2538
|
635 this.canMove = function () {
|
nicholas@2538
|
636 return true;
|
nicholas@2538
|
637 };
|
nicholas@2538
|
638 this.error = function () {
|
nicholas@2538
|
639 // audioObject has an error!!
|
nickjillings@2113
|
640 this.playback.textContent = "Error";
|
nickjillings@2113
|
641 $(this.playback).addClass("error-colour");
|
nicholas@2696
|
642 };
|
nickjillings@1341
|
643 }
|
nickjillings@1341
|
644
|
nicholas@2538
|
645 function outsideReferenceDOM(audioObject, index, inject) {
|
nicholas@2538
|
646 this.parent = audioObject;
|
nicholas@2538
|
647 this.outsideReferenceHolder = document.createElement('div');
|
nicholas@2538
|
648 this.outsideReferenceHolder.id = 'outside-reference';
|
nicholas@2538
|
649 this.outsideReferenceHolder.className = 'outside-reference track-slider-disabled';
|
nicholas@2538
|
650 var outsideReferenceHolderspan = document.createElement('span');
|
nicholas@2538
|
651 outsideReferenceHolderspan.textContent = 'Reference';
|
nicholas@2538
|
652 this.outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
|
nicholas@2538
|
653 this.outsideReferenceHolder.setAttribute('track-id', index);
|
nicholas@2538
|
654
|
nicholas@2696
|
655 this.handleEvent = function (event) {
|
nicholas@2696
|
656 audioEngineContext.play(audioObject.id);
|
nicholas@2538
|
657 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1341
|
658 $('.comment-div').removeClass('comment-box-playing');
|
nicholas@2696
|
659 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nicholas@2538
|
660 };
|
nicholas@2696
|
661 this.outsideReferenceHolder.addEventListener("click", this.handleEvent);
|
nicholas@2538
|
662 inject.appendChild(this.outsideReferenceHolder);
|
nicholas@2538
|
663 this.enable = function () {
|
nicholas@2538
|
664 if (this.parent.state == 1) {
|
nicholas@2538
|
665 $(this.outsideReferenceHolder).removeClass('track-slider-disabled');
|
nicholas@2538
|
666 }
|
nicholas@2538
|
667 };
|
nicholas@2538
|
668 this.updateLoading = function (progress) {
|
nicholas@2538
|
669 if (progress != 100) {
|
nicholas@2538
|
670 progress = String(progress);
|
nicholas@2538
|
671 progress = progress.split('.')[0];
|
nicholas@2538
|
672 this.outsideReferenceHolder.firstChild.textContent = progress + '%';
|
nicholas@2538
|
673 } else {
|
nicholas@2538
|
674 this.outsideReferenceHolder.firstChild.textContent = "Play Reference";
|
nicholas@2538
|
675 }
|
nicholas@2538
|
676 };
|
nicholas@2538
|
677 this.startPlayback = function () {
|
nickjillings@1360
|
678 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1360
|
679 $(this.outsideReferenceHolder).addClass('track-slider-playing');
|
nickjillings@1360
|
680 $('.comment-div').removeClass('comment-box-playing');
|
nickjillings@1360
|
681 };
|
nicholas@2538
|
682 this.stopPlayback = function () {
|
nickjillings@1360
|
683 $(this.outsideReferenceHolder).removeClass('track-slider-playing');
|
nickjillings@1360
|
684 };
|
nicholas@2538
|
685 this.exportXMLDOM = function (audioObject) {
|
nicholas@2538
|
686 return null;
|
nicholas@2538
|
687 };
|
nicholas@2538
|
688 this.getValue = function () {
|
nicholas@2538
|
689 return 0;
|
nicholas@2538
|
690 };
|
nicholas@2538
|
691 this.getPresentedId = function () {
|
nicholas@2538
|
692 return 'reference';
|
nicholas@2538
|
693 };
|
nicholas@2538
|
694 this.canMove = function () {
|
nicholas@2538
|
695 return false;
|
nicholas@2538
|
696 };
|
nicholas@2538
|
697 this.error = function () {
|
nicholas@2538
|
698 // audioObject has an error!!
|
nickjillings@2113
|
699 this.outsideReferenceHolder.textContent = "Error";
|
nickjillings@2113
|
700 $(this.outsideReferenceHolder).addClass("error-colour");
|
nicholas@2696
|
701 };
|
nickjillings@1341
|
702 }
|
nickjillings@1341
|
703
|
nicholas@2538
|
704 function buttonSubmitClick() {
|
nicholas@2651
|
705 var checks = testState.currentStateMap.interfaces[0].options,
|
nicholas@2651
|
706 canContinue = true;
|
nickjillings@1341
|
707
|
nicholas@2538
|
708 // Check that the anchor and reference objects are correctly placed
|
nicholas@2696
|
709 if (interfaceContext.checkHiddenAnchor() === false) {
|
nicholas@2538
|
710 return;
|
nicholas@2538
|
711 }
|
nicholas@2696
|
712 if (interfaceContext.checkHiddenReference() === false) {
|
nicholas@2538
|
713 return;
|
nicholas@2538
|
714 }
|
nicholas@2538
|
715
|
nicholas@2538
|
716 for (var i = 0; i < checks.length; i++) {
|
nicholas@2538
|
717 if (checks[i].type == 'check') {
|
nicholas@2703
|
718 var checkState = true;
|
nicholas@2538
|
719 switch (checks[i].name) {
|
nicholas@2538
|
720 case 'fragmentPlayed':
|
nicholas@2538
|
721 // Check if all fragments have been played
|
nicholas@2696
|
722 checkState = interfaceContext.checkAllPlayed();
|
nicholas@2538
|
723 break;
|
nicholas@2538
|
724 case 'fragmentFullPlayback':
|
nicholas@2538
|
725 // Check all fragments have been played to their full length
|
nicholas@2696
|
726 checkState = interfaceContext.checkFragmentsFullyPlayed();
|
nicholas@2538
|
727 break;
|
nicholas@2538
|
728 case 'fragmentMoved':
|
nicholas@2538
|
729 // Check all fragment sliders have been moved.
|
nicholas@2696
|
730 checkState = interfaceContext.checkAllMoved();
|
nicholas@2538
|
731 break;
|
nicholas@2538
|
732 case 'fragmentComments':
|
nicholas@2538
|
733 // Check all fragment sliders have been moved.
|
nicholas@2696
|
734 checkState = interfaceContext.checkAllCommented();
|
nicholas@2538
|
735 break;
|
nicholas@2538
|
736 case 'scalerange':
|
nicholas@2538
|
737 // Check the scale is used to its full width outlined by the node
|
nicholas@2696
|
738 checkState = interfaceContext.checkScaleRange();
|
nicholas@2538
|
739 break;
|
nicholas@2538
|
740 default:
|
nicholas@2538
|
741 console.log("WARNING - Check option " + checks[i].name + " is not supported on this interface");
|
nicholas@2538
|
742 break;
|
nicholas@2538
|
743 }
|
nicholas@2538
|
744
|
nicholas@2538
|
745 }
|
nicholas@2703
|
746 if (checkState === false) {
|
nicholas@2703
|
747 canContinue = false;
|
nicholas@2538
|
748 break;
|
nicholas@2538
|
749 }
|
nicholas@2538
|
750 }
|
nicholas@2538
|
751
|
nickjillings@1341
|
752 if (canContinue) {
|
nicholas@2538
|
753 if (audioEngineContext.status == 1) {
|
nicholas@2538
|
754 var playback = document.getElementById('playback-button');
|
nicholas@2538
|
755 playback.click();
|
nicholas@2538
|
756 // 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
|
757 } else {
|
nicholas@2696
|
758 if (audioEngineContext.timer.testStarted === false) {
|
nicholas@2538
|
759 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click a fragment to begin the test!');
|
nicholas@2538
|
760 return;
|
nicholas@2538
|
761 }
|
nicholas@2538
|
762 }
|
nicholas@2538
|
763 testState.advanceState();
|
nicholas@2538
|
764 }
|
nickjillings@1341
|
765 }
|
nickjillings@1341
|
766
|
nicholas@2538
|
767 function convSliderPosToRate(trackSlider) {
|
nicholas@2538
|
768 var slider = trackSlider.parentElement;
|
nicholas@2538
|
769 var maxPix = $(slider).width();
|
nicholas@2538
|
770 var marginsize = 50;
|
nicholas@2538
|
771 var pix = trackSlider.style.left;
|
nicholas@2538
|
772 pix = pix.substr(0, pix.length - 2);
|
nicholas@2538
|
773 var rate = (pix - marginsize) / maxPix;
|
nicholas@2538
|
774 return rate;
|
nickjillings@1341
|
775 }
|
nickjillings@1341
|
776
|
nicholas@2538
|
777 function resizeWindow(event) {
|
nicholas@2538
|
778 // Function called when the window has been resized.
|
nicholas@2538
|
779 // MANDATORY FUNCTION
|
nicholas@2538
|
780
|
nicholas@2538
|
781 // Resize the slider objects
|
nicholas@2538
|
782 for (var i = 0; i < interfaceContext.interfaceSliders.length; i++) {
|
nicholas@2538
|
783 interfaceContext.interfaceSliders[i].resize(event);
|
nicholas@2538
|
784 }
|
nickjillings@1341
|
785 }
|
nickjillings@1341
|
786
|
nicholas@2538
|
787 function pageXMLSave(store, pageSpecification) {
|
nicholas@2538
|
788 // MANDATORY
|
nicholas@2538
|
789 // Saves a specific test page
|
nicholas@2538
|
790 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nicholas@2538
|
791 // Get the current <page> information in store (remember to appendChild your data to it)
|
nicholas@2538
|
792 // pageSpecification is the current page node configuration
|
nicholas@2538
|
793 // To create new XML nodes, use storage.document.createElement();
|
nicholas@2538
|
794
|
nicholas@2538
|
795 if (interfaceContext.interfaceSliders.length == 1) {
|
nicholas@2538
|
796 // If there is only one axis, there only needs to be one metric return
|
nicholas@2538
|
797 return;
|
nicholas@2538
|
798 }
|
nicholas@2538
|
799 var audioelements = store.getElementsByTagName("audioelement");
|
nicholas@2538
|
800 for (var i = 0; i < audioelements.length; i++) {
|
nicholas@2538
|
801 // Have to append the metric specific nodes
|
nicholas@2696
|
802 if (pageSpecification.outsideReference === undefined || pageSpecification.outsideReference.id != audioelements[i].id) {
|
nicholas@2538
|
803 var inject = audioelements[i].getElementsByTagName("metric");
|
nicholas@2696
|
804 if (inject.length === 0) {
|
nicholas@2538
|
805 inject = storage.document.createElement("metric");
|
nicholas@2538
|
806 } else {
|
nicholas@2538
|
807 inject = inject[0];
|
nicholas@2538
|
808 }
|
nicholas@2538
|
809 for (var k = 0; k < interfaceContext.interfaceSliders.length; k++) {
|
nicholas@2538
|
810 var mrnodes = interfaceContext.interfaceSliders[k].metrics[i].exportXMLDOM(inject);
|
nicholas@2538
|
811 for (var j = 0; j < mrnodes.length; j++) {
|
nicholas@2538
|
812 var name = mrnodes[j].getAttribute("name");
|
nicholas@2538
|
813 if (name == "elementTracker" || name == "elementTrackerFull" || name == "elementInitialPosition" || name == "elementFlagMoved") {
|
nicholas@2538
|
814 mrnodes[j].setAttribute("interface-name", interfaceContext.interfaceSliders[k].name);
|
nicholas@2538
|
815 mrnodes[j].setAttribute("interface-id", k);
|
nicholas@2538
|
816 }
|
nicholas@2538
|
817 }
|
nicholas@2538
|
818 }
|
nicholas@2538
|
819 }
|
nicholas@2538
|
820 }
|
nicholas@2538
|
821 }
|