nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@38
|
6 // preTest - In preTest state
|
n@38
|
7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
8 // testRunPost-ID - Post test of test ID
|
n@38
|
9 // testRunPre-ID - Pre-test of test ID
|
n@38
|
10 // postTest - End of test, final submission!
|
n@38
|
11
|
n@32
|
12
|
nicholas@2
|
13 // Once this is loaded and parsed, begin execution
|
n@181
|
14 loadInterface();
|
nicholas@2
|
15
|
n@181
|
16 function loadInterface() {
|
nicholas@2
|
17
|
n@16
|
18 // Get the dimensions of the screen available to the page
|
nicholas@2
|
19 var width = window.innerWidth;
|
nicholas@2
|
20 var height = window.innerHeight;
|
nicholas@2
|
21
|
nicholas@2
|
22 // The injection point into the HTML page
|
n@182
|
23 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
n@22
|
24 var testContent = document.createElement('div');
|
nicholas@135
|
25
|
n@22
|
26 testContent.id = 'testContent';
|
n@176
|
27
|
n@34
|
28
|
n@52
|
29 // Create APE specific metric functions
|
n@52
|
30 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
31 {
|
n@52
|
32 };
|
n@52
|
33
|
n@52
|
34 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
35 {
|
n@183
|
36
|
n@52
|
37 var id = this.data;
|
n@52
|
38 this.data = -1;
|
n@52
|
39 var position = convSliderPosToRate(id);
|
b@115
|
40 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
|
n@52
|
41 if (audioEngineContext.timer.testStarted)
|
n@52
|
42 {
|
n@52
|
43 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
44 }
|
n@52
|
45 };
|
n@52
|
46
|
n@52
|
47 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
48 {
|
n@52
|
49 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
50 if (audioEngineContext.timer.testStarted)
|
n@52
|
51 {
|
n@52
|
52 if (this.lastClicked >= 0)
|
n@52
|
53 {
|
n@52
|
54 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
55 }
|
n@52
|
56 this.lastClicked = id;
|
n@52
|
57 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
58 }
|
b@115
|
59 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
n@52
|
60 };
|
n@52
|
61
|
n@177
|
62 // Bindings for audioObjects
|
n@177
|
63
|
nicholas@2
|
64 // Create the top div for the Title element
|
n@181
|
65 var titleAttr = specification.title;
|
nicholas@2
|
66 var title = document.createElement('div');
|
nicholas@2
|
67 title.className = "title";
|
nicholas@2
|
68 title.align = "center";
|
nicholas@2
|
69 var titleSpan = document.createElement('span');
|
nicholas@2
|
70
|
nicholas@2
|
71 // Set title to that defined in XML, else set to default
|
nicholas@2
|
72 if (titleAttr != undefined) {
|
n@181
|
73 titleSpan.textContent = titleAttr;
|
nicholas@2
|
74 } else {
|
n@181
|
75 titleSpan.textContent = 'Listening test';
|
nicholas@2
|
76 }
|
nicholas@2
|
77 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
78 title.appendChild(titleSpan);
|
nicholas@2
|
79
|
n@47
|
80 var pagetitle = document.createElement('div');
|
n@47
|
81 pagetitle.className = "pageTitle";
|
n@47
|
82 pagetitle.align = "center";
|
n@47
|
83 var titleSpan = document.createElement('span');
|
n@47
|
84 titleSpan.id = "pageTitle";
|
n@47
|
85 pagetitle.appendChild(titleSpan);
|
n@47
|
86
|
nicholas@7
|
87 // Create Interface buttons!
|
nicholas@7
|
88 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
89 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
90
|
nicholas@7
|
91 // Create playback start/stop points
|
nicholas@7
|
92 var playback = document.createElement("button");
|
b@101
|
93 playback.innerHTML = 'Stop';
|
n@49
|
94 playback.id = 'playback-button';
|
n@16
|
95 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
96 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
97 playback.onclick = function() {
|
b@101
|
98 if (audioEngineContext.status == 1) {
|
b@101
|
99 audioEngineContext.stop();
|
n@25
|
100 this.innerHTML = 'Stop';
|
b@115
|
101 var time = audioEngineContext.timer.getTestTime();
|
b@115
|
102 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@7
|
103 }
|
n@16
|
104 };
|
nicholas@7
|
105 // Create Submit (save) button
|
nicholas@7
|
106 var submit = document.createElement("button");
|
n@25
|
107 submit.innerHTML = 'Submit';
|
n@43
|
108 submit.onclick = buttonSubmitClick;
|
n@49
|
109 submit.id = 'submit-button';
|
n@16
|
110 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
111 interfaceButtons.appendChild(playback);
|
nicholas@7
|
112 interfaceButtons.appendChild(submit);
|
nicholas@7
|
113
|
nicholas@2
|
114 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
115
|
n@16
|
116 // Create the div box to center align
|
nicholas@2
|
117 var sliderBox = document.createElement('div');
|
nicholas@2
|
118 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
119 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
120
|
n@16
|
121 // Create the slider box to hold the slider elements
|
nicholas@5
|
122 var canvas = document.createElement('div');
|
nicholas@2
|
123 canvas.id = 'slider';
|
n@127
|
124 canvas.align = "left";
|
n@127
|
125 canvas.addEventListener('dragover',function(event){
|
n@127
|
126 event.preventDefault();
|
n@127
|
127 return false;
|
n@127
|
128 },false);
|
n@127
|
129 var sliderMargin = document.createAttribute('marginsize');
|
n@127
|
130 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
|
n@16
|
131 // Must have a known EXACT width, as this is used later to determine the ratings
|
n@127
|
132 var w = (Number(sliderMargin.nodeValue)+8)*2;
|
n@127
|
133 canvas.style.width = width - w +"px";
|
n@127
|
134 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
|
n@127
|
135 canvas.setAttributeNode(sliderMargin);
|
nicholas@2
|
136 sliderBox.appendChild(canvas);
|
n@16
|
137
|
n@47
|
138 // Create the div to hold any scale objects
|
n@47
|
139 var scale = document.createElement('div');
|
n@47
|
140 scale.className = 'sliderScale';
|
n@47
|
141 scale.id = 'sliderScaleHolder';
|
n@47
|
142 scale.align = 'left';
|
n@47
|
143 sliderBox.appendChild(scale);
|
n@47
|
144
|
n@16
|
145 // Global parent for the comment boxes on the page
|
nicholas@3
|
146 var feedbackHolder = document.createElement('div');
|
n@34
|
147 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
148
|
n@38
|
149 testContent.style.zIndex = 1;
|
n@182
|
150 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
151
|
n@38
|
152 // Inject into HTML
|
n@38
|
153 testContent.appendChild(title); // Insert the title
|
n@47
|
154 testContent.appendChild(pagetitle);
|
n@38
|
155 testContent.appendChild(interfaceButtons);
|
n@38
|
156 testContent.appendChild(sliderBox);
|
n@38
|
157 testContent.appendChild(feedbackHolder);
|
n@182
|
158 interfaceContext.insertPoint.appendChild(testContent);
|
n@22
|
159
|
n@36
|
160 // Load the full interface
|
nicholas@129
|
161 testState.initialise();
|
nicholas@129
|
162 testState.advanceState();
|
nicholas@135
|
163
|
nicholas@2
|
164 }
|
nicholas@5
|
165
|
n@181
|
166 function loadTest(audioHolderObject)
|
n@34
|
167 {
|
nicholas@110
|
168
|
nicholas@110
|
169 // Reset audioEngineContext.Metric globals for new test
|
n@113
|
170 audioEngineContext.newTestPage();
|
nicholas@110
|
171
|
n@181
|
172 var id = audioHolderObject.id;
|
n@34
|
173
|
n@34
|
174 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
175 var canvas = document.getElementById('slider');
|
n@34
|
176 feedbackHolder.innerHTML = null;
|
n@34
|
177 canvas.innerHTML = null;
|
n@47
|
178
|
n@47
|
179 // Setup question title
|
n@184
|
180 var interfaceObj = audioHolderObject.interfaces;
|
n@184
|
181 var commentBoxPrefix = "Comment on track";
|
n@184
|
182 if (interfaceObj.length != 0) {
|
n@184
|
183 interfaceObj = interfaceObj[0];
|
n@184
|
184 var titleNode = interfaceObj.title;
|
n@184
|
185 if (titleNode != undefined)
|
n@184
|
186 {
|
n@184
|
187 document.getElementById('pageTitle').textContent = titleNode;
|
n@184
|
188 }
|
n@184
|
189 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@184
|
190 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@184
|
191 var scale = document.getElementById('sliderScaleHolder');
|
n@184
|
192 scale.innerHTML = null;
|
n@184
|
193 $(interfaceObj.scale).each(function(index,scaleObj){
|
n@184
|
194 var value = document.createAttribute('value');
|
n@184
|
195 var position = Number(scaleObj[0])*0.01;
|
n@184
|
196 value.nodeValue = position;
|
n@184
|
197 var pixelPosition = (position*positionScale)+offset;
|
n@184
|
198 var scaleDOM = document.createElement('span');
|
n@184
|
199 scaleDOM.textContent = scaleObj[1];
|
n@184
|
200 scale.appendChild(scaleDOM);
|
n@184
|
201 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@184
|
202 scaleDOM.setAttributeNode(value);
|
n@184
|
203 });
|
n@184
|
204
|
n@184
|
205 if (interfaceObj.commentBoxPrefix != undefined) {
|
n@184
|
206 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
n@184
|
207 }
|
n@174
|
208 }
|
n@34
|
209
|
n@34
|
210 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@181
|
211 if (audioHolderObject.sampleRate != undefined) {
|
n@181
|
212 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
|
n@184
|
213 var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
214 alert(errStr);
|
n@34
|
215 return;
|
n@34
|
216 }
|
n@34
|
217 }
|
n@45
|
218
|
n@181
|
219 var commentShow = audioHolderObject.elementComments;
|
nicholas@66
|
220
|
n@181
|
221 var loopPlayback = audioHolderObject.loop;
|
n@181
|
222
|
n@57
|
223 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
224 // Create AudioEngine bindings for playback
|
n@57
|
225 if (loopPlayback) {
|
n@57
|
226 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
227 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
228 {
|
n@57
|
229 if (id == i) {
|
nicholas@132
|
230 this.audioObjects[i].loopStart();
|
n@57
|
231 } else {
|
nicholas@132
|
232 this.audioObjects[i].loopStop();
|
n@57
|
233 }
|
n@57
|
234 }
|
n@57
|
235 };
|
n@57
|
236 } else {
|
n@57
|
237 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
238 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
239 {
|
n@97
|
240 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@97
|
241 this.audioObjects[i].stop();
|
n@57
|
242 }
|
n@99
|
243 if (this.status == 1) {
|
n@99
|
244 this.audioObjects[id].outputGain.gain.value = 1.0;
|
n@99
|
245 this.audioObjects[id].play(audioContext.currentTime+0.01);
|
n@99
|
246 }
|
n@57
|
247 };
|
n@57
|
248 }
|
n@57
|
249
|
n@46
|
250 currentTestHolder = document.createElement('audioHolder');
|
n@181
|
251 currentTestHolder.id = audioHolderObject.id;
|
n@181
|
252 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
n@46
|
253
|
n@181
|
254 var randomise = audioHolderObject.randomiseOrder;
|
n@45
|
255
|
n@181
|
256 var audioElements = audioHolderObject.audioElements;
|
nicholas@58
|
257 currentTrackOrder = [];
|
n@45
|
258 if (randomise) {
|
n@181
|
259 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
|
n@45
|
260 }
|
n@45
|
261
|
nicholas@58
|
262 // Delete any previous audioObjects associated with the audioEngine
|
nicholas@58
|
263 audioEngineContext.audioObjects = [];
|
nicholas@58
|
264
|
n@45
|
265 // Find all the audioElements from the audioHolder
|
n@181
|
266 $(audioHolderObject.audioElements).each(function(index,element){
|
n@34
|
267 // Find URL of track
|
n@34
|
268 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
269
|
n@34
|
270 // Now load each audio sample. First create the new track by passing the full URL
|
n@181
|
271 var trackURL = audioHolderObject.hostURL + element.url;
|
n@182
|
272 var audioObject = audioEngineContext.newTrack(element);
|
nicholas@66
|
273
|
nicholas@66
|
274 if (commentShow) {
|
n@182
|
275 var node = interfaceContext.createCommentBox(audioObject);
|
nicholas@66
|
276 }
|
n@34
|
277
|
n@34
|
278 // Create a slider per track
|
n@183
|
279 audioObject.interfaceDOM = new sliderObject(audioObject);
|
n@154
|
280
|
n@34
|
281 // Distribute it randomnly
|
n@138
|
282 var w = window.innerWidth - (offset+8)*2;
|
n@34
|
283 w = Math.random()*w;
|
n@138
|
284 w = Math.floor(w+(offset+8));
|
n@183
|
285 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
|
n@34
|
286
|
n@183
|
287 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
|
n@183
|
288 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
|
b@102
|
289
|
n@34
|
290 });
|
n@182
|
291 if (commentShow) {
|
n@182
|
292 interfaceContext.showCommentBoxes(feedbackHolder,true);
|
n@182
|
293 }
|
n@39
|
294
|
nicholas@65
|
295 // Append any commentQuestion boxes
|
n@181
|
296 $(audioHolderObject.commentQuestions).each(function(index,element) {
|
nicholas@65
|
297 // Create document objects to hold the comment boxes
|
nicholas@65
|
298 var trackComment = document.createElement('div');
|
nicholas@65
|
299 trackComment.className = 'comment-div commentQuestion';
|
n@181
|
300 trackComment.id = element.id;
|
nicholas@65
|
301 // Create a string next to each comment asking for a comment
|
nicholas@65
|
302 var trackString = document.createElement('span');
|
n@181
|
303 trackString.innerHTML = element.question;
|
nicholas@65
|
304 // Create the HTML5 comment box 'textarea'
|
nicholas@65
|
305 var trackCommentBox = document.createElement('textarea');
|
nicholas@65
|
306 trackCommentBox.rows = '4';
|
nicholas@65
|
307 trackCommentBox.cols = '100';
|
nicholas@65
|
308 trackCommentBox.name = 'commentQuestion'+index;
|
nicholas@65
|
309 trackCommentBox.className = 'trackComment';
|
nicholas@65
|
310 var br = document.createElement('br');
|
nicholas@65
|
311 // Add to the holder.
|
nicholas@65
|
312 trackComment.appendChild(trackString);
|
nicholas@65
|
313 trackComment.appendChild(br);
|
nicholas@65
|
314 trackComment.appendChild(trackCommentBox);
|
nicholas@65
|
315 feedbackHolder.appendChild(trackComment);
|
nicholas@65
|
316 });
|
n@153
|
317
|
n@153
|
318
|
n@153
|
319 testWaitIndicator();
|
n@39
|
320 }
|
n@39
|
321
|
n@183
|
322 function sliderObject(audioObject) {
|
n@183
|
323 // Create a new slider object;
|
n@183
|
324 this.parent = audioObject;
|
n@183
|
325 this.trackSliderObj = document.createElement('div');
|
n@183
|
326 this.trackSliderObj.className = 'track-slider';
|
n@183
|
327 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
|
n@183
|
328
|
n@183
|
329 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
|
n@183
|
330 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
|
n@183
|
331 this.trackSliderObj.draggable = true;
|
n@183
|
332 this.trackSliderObj.ondragend = dragEnd;
|
n@183
|
333
|
n@183
|
334 // Onclick, switch playback to that track
|
n@183
|
335 this.trackSliderObj.onclick = function() {
|
n@183
|
336 // Start the test on first click, that way timings are more accurate.
|
n@183
|
337 audioEngineContext.play();
|
n@183
|
338 if (audioEngineContext.audioObjectsReady) {
|
n@183
|
339 // Cannot continue to issue play command until audioObjects reported as ready!
|
n@183
|
340 // Get the track ID from the object ID
|
n@183
|
341 var id = Number(event.srcElement.attributes['trackIndex'].value);
|
n@183
|
342 //audioEngineContext.metric.sliderPlayed(id);
|
n@183
|
343 audioEngineContext.selectedTrack(id);
|
n@183
|
344 // Currently playing track red, rest green
|
n@183
|
345
|
n@183
|
346 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
n@183
|
347 $('.track-slider').removeClass('track-slider-playing');
|
n@183
|
348 $(event.srcElement).addClass('track-slider-playing');
|
n@183
|
349 $('.comment-div').removeClass('comment-box-playing');
|
n@183
|
350 $('#comment-div-'+id).addClass('comment-box-playing');
|
n@183
|
351 }
|
n@183
|
352 };
|
n@183
|
353
|
n@183
|
354 this.exportXMLDOM = function() {
|
n@183
|
355 // Called by the audioObject holding this element. Must be present
|
n@183
|
356 var node = document.createElement('value');
|
n@183
|
357 node.textContent = convSliderPosToRate(this.trackSliderObj);
|
n@183
|
358 return node;
|
n@183
|
359 };
|
n@183
|
360 }
|
nicholas@119
|
361
|
nicholas@5
|
362 function dragEnd(ev) {
|
nicholas@5
|
363 // Function call when a div has been dropped
|
n@33
|
364 var slider = document.getElementById('slider');
|
n@127
|
365 var marginSize = Number(slider.attributes['marginsize'].value);
|
n@51
|
366 var w = slider.style.width;
|
n@51
|
367 w = Number(w.substr(0,w.length-2));
|
nicholas@133
|
368 var x = ev.x;
|
n@127
|
369 if (x >= marginSize && x < w+marginSize) {
|
n@51
|
370 this.style.left = (x)+'px';
|
nicholas@5
|
371 } else {
|
n@127
|
372 if (x<marginSize) {
|
n@127
|
373 this.style.left = marginSize+'px';
|
nicholas@5
|
374 } else {
|
n@127
|
375 this.style.left = (w+marginSize) + 'px';
|
nicholas@5
|
376 }
|
nicholas@5
|
377 }
|
n@183
|
378 var time = audioEngineContext.timer.getTestTime();
|
n@183
|
379 var id = Number(ev.srcElement.getAttribute('trackindex'));
|
n@183
|
380 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
|
nicholas@5
|
381 }
|
nicholas@7
|
382
|
b@101
|
383 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
n@40
|
384 {
|
nicholas@107
|
385 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nicholas@107
|
386 if (hasBeenPlayed.length == 0) {
|
nicholas@107
|
387 if (audioEngineContext.status == 1) {
|
nicholas@107
|
388 var playback = document.getElementById('playback-button');
|
nicholas@107
|
389 playback.click();
|
nicholas@107
|
390 // 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
|
391 } else
|
nicholas@107
|
392 {
|
nicholas@107
|
393 if (audioEngineContext.timer.testStarted == false)
|
nicholas@107
|
394 {
|
nicholas@107
|
395 alert('You have not started the test! Please press start to begin the test!');
|
nicholas@107
|
396 return;
|
nicholas@107
|
397 }
|
nicholas@107
|
398 }
|
nicholas@129
|
399 testState.advanceState();
|
b@102
|
400 } else // if a fragment has not been played yet
|
b@102
|
401 {
|
nicholas@107
|
402 str = "";
|
nicholas@107
|
403 if (hasBeenPlayed.length > 1) {
|
nicholas@107
|
404 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nicholas@107
|
405 str = str + hasBeenPlayed[i];
|
nicholas@107
|
406 if (i < hasBeenPlayed.length-2){
|
nicholas@107
|
407 str += ", ";
|
nicholas@107
|
408 } else if (i == hasBeenPlayed.length-2) {
|
nicholas@107
|
409 str += " or ";
|
nicholas@107
|
410 }
|
nicholas@107
|
411 }
|
nicholas@107
|
412 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@107
|
413 } else {
|
nicholas@107
|
414 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@107
|
415 }
|
b@102
|
416 return;
|
b@102
|
417 }
|
n@40
|
418 }
|
n@40
|
419
|
n@183
|
420 function convSliderPosToRate(slider)
|
n@51
|
421 {
|
n@51
|
422 var w = document.getElementById('slider').style.width;
|
n@127
|
423 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@51
|
424 var maxPix = w.substr(0,w.length-2);
|
n@51
|
425 var pix = slider.style.left;
|
n@51
|
426 pix = pix.substr(0,pix.length-2);
|
n@127
|
427 var rate = (pix-marginsize)/maxPix;
|
n@51
|
428 return rate;
|
n@51
|
429 }
|
n@51
|
430
|
n@127
|
431 function resizeWindow(event){
|
n@127
|
432 // Function called when the window has been resized.
|
n@127
|
433 // MANDATORY FUNCTION
|
n@127
|
434
|
n@127
|
435 // Store the slider marker values
|
n@127
|
436 var holdValues = [];
|
n@127
|
437 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
438 holdValues.push(convSliderPosToRate(index));
|
n@127
|
439 });
|
n@127
|
440
|
n@127
|
441 var width = event.target.innerWidth;
|
n@127
|
442 var canvas = document.getElementById('sliderCanvasHolder');
|
n@127
|
443 var sliderDiv = canvas.children[0];
|
n@127
|
444 var sliderScaleDiv = canvas.children[1];
|
n@127
|
445 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
|
n@127
|
446 var w = (marginsize+8)*2;
|
n@127
|
447 sliderDiv.style.width = width - w + 'px';
|
n@127
|
448 var width = width - w;
|
n@127
|
449 // Move sliders into new position
|
n@127
|
450 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
451 var pos = holdValues[index];
|
n@127
|
452 var pix = pos * width;
|
n@127
|
453 sliderObj.style.left = pix+marginsize+'px';
|
n@127
|
454 });
|
n@127
|
455
|
n@127
|
456 // Move scale labels
|
n@127
|
457 $(sliderScaleDiv.children).each(function(index,scaleObj){
|
n@127
|
458 var position = Number(scaleObj.attributes['value'].value);
|
n@127
|
459 var pixelPosition = (position*width)+marginsize;
|
n@127
|
460 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
|
n@127
|
461 });
|
n@127
|
462 }
|
n@127
|
463
|
n@181
|
464 function pageXMLSave(store, testXML)
|
n@44
|
465 {
|
n@44
|
466 // Saves a specific test page
|
nicholas@129
|
467 var xmlDoc = store;
|
n@50
|
468 // Check if any session wide metrics are enabled
|
nicholas@67
|
469
|
n@181
|
470 var commentShow = testXML.elementComments;
|
nicholas@67
|
471
|
n@50
|
472 var metric = document.createElement('metric');
|
n@50
|
473 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
474 {
|
n@50
|
475 var testTime = document.createElement('metricResult');
|
n@50
|
476 testTime.id = 'testTime';
|
n@50
|
477 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
478 metric.appendChild(testTime);
|
n@50
|
479 }
|
n@50
|
480 xmlDoc.appendChild(metric);
|
n@178
|
481 var audioObjects = audioEngineContext.audioObjects;
|
n@178
|
482 for (var i=0; i<audioObjects.length; i++)
|
n@45
|
483 {
|
n@183
|
484 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
|
n@45
|
485 xmlDoc.appendChild(audioElement);
|
n@45
|
486 }
|
nicholas@65
|
487 var commentQuestion = document.getElementsByClassName('commentQuestion');
|
nicholas@65
|
488 for (var i=0; i<commentQuestion.length; i++)
|
nicholas@65
|
489 {
|
nicholas@65
|
490 var cqHolder = document.createElement('CommentQuestion');
|
nicholas@65
|
491 var comment = document.createElement('comment');
|
nicholas@65
|
492 var question = document.createElement('question');
|
nicholas@65
|
493 cqHolder.id = commentQuestion[i].id;
|
nicholas@65
|
494 comment.textContent = commentQuestion[i].children[2].value;
|
nicholas@65
|
495 question.textContent = commentQuestion[i].children[0].textContent;
|
n@124
|
496 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY
|
nicholas@65
|
497 cqHolder.appendChild(question);
|
nicholas@65
|
498 cqHolder.appendChild(comment);
|
nicholas@65
|
499 xmlDoc.appendChild(cqHolder);
|
nicholas@65
|
500 }
|
nicholas@129
|
501 store = xmlDoc;
|
nicholas@67
|
502 } |