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