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