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