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