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