n@470
|
1 // Once this is loaded and parsed, begin execution
|
n@470
|
2 loadInterface();
|
n@470
|
3
|
n@470
|
4 function loadInterface() {
|
n@470
|
5 // Get the dimensions of the screen available to the page
|
n@470
|
6 var width = window.innerWidth;
|
n@470
|
7 var height = window.innerHeight;
|
n@470
|
8 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
|
n@470
|
9
|
n@470
|
10 // Custom Comparitor Object
|
n@470
|
11 Interface.prototype.comparitor = null;
|
n@470
|
12
|
n@470
|
13 // The injection point into the HTML page
|
n@470
|
14 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
n@470
|
15 var testContent = document.createElement('div');
|
n@470
|
16 testContent.id = 'testContent';
|
n@470
|
17
|
n@470
|
18 // Create the top div for the Title element
|
n@470
|
19 var titleAttr = specification.title;
|
n@470
|
20 var title = document.createElement('div');
|
n@470
|
21 title.className = "title";
|
n@470
|
22 title.align = "center";
|
n@470
|
23 var titleSpan = document.createElement('span');
|
n@470
|
24
|
n@470
|
25 // Set title to that defined in XML, else set to default
|
n@470
|
26 if (titleAttr != undefined) {
|
n@470
|
27 titleSpan.textContent = titleAttr;
|
n@470
|
28 } else {
|
n@470
|
29 titleSpan.textContent = 'Listening test';
|
n@470
|
30 }
|
n@470
|
31 // Insert the titleSpan element into the title div element.
|
n@470
|
32 title.appendChild(titleSpan);
|
n@470
|
33
|
n@470
|
34 var pagetitle = document.createElement('div');
|
n@470
|
35 pagetitle.className = "pageTitle";
|
n@470
|
36 pagetitle.align = "center";
|
n@470
|
37 var titleSpan = document.createElement('span');
|
n@470
|
38 titleSpan.id = "pageTitle";
|
n@470
|
39 pagetitle.appendChild(titleSpan);
|
n@470
|
40
|
n@470
|
41 // Create Interface buttons!
|
n@470
|
42 var interfaceButtons = document.createElement('div');
|
n@470
|
43 interfaceButtons.id = 'interface-buttons';
|
n@470
|
44 interfaceButtons.style.height = '25px';
|
n@470
|
45
|
n@470
|
46 // Create playback start/stop points
|
n@470
|
47 var playback = document.createElement("button");
|
n@470
|
48 playback.innerHTML = 'Stop';
|
n@470
|
49 playback.id = 'playback-button';
|
n@470
|
50 playback.style.float = 'left';
|
n@470
|
51 // onclick function. Check if it is playing or not, call the correct function in the
|
n@470
|
52 // audioEngine, change the button text to reflect the next state.
|
n@470
|
53 playback.onclick = function() {
|
n@470
|
54 if (audioEngineContext.status == 1) {
|
n@470
|
55 audioEngineContext.stop();
|
n@470
|
56 this.innerHTML = 'Stop';
|
n@470
|
57 var time = audioEngineContext.timer.getTestTime();
|
n@470
|
58 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
n@470
|
59 }
|
n@470
|
60 };
|
n@470
|
61 // Append the interface buttons into the interfaceButtons object.
|
n@470
|
62 interfaceButtons.appendChild(playback);
|
n@470
|
63
|
n@470
|
64 // Global parent for the comment boxes on the page
|
n@470
|
65 var feedbackHolder = document.createElement('div');
|
n@470
|
66 feedbackHolder.id = 'feedbackHolder';
|
n@470
|
67
|
n@470
|
68 // Construct the AB Boxes
|
n@470
|
69 var boxes = document.createElement('div');
|
n@470
|
70 boxes.align = "center";
|
n@470
|
71 boxes.id = "box-holders";
|
n@470
|
72 boxes.style.float = "left";
|
n@470
|
73
|
n@470
|
74 var submit = document.createElement('button');
|
n@470
|
75 submit.id = "submit";
|
n@470
|
76 submit.onclick = buttonSubmitClick;
|
n@470
|
77 submit.className = "big-button";
|
n@470
|
78 submit.textContent = "submit";
|
n@470
|
79 submit.style.position = "relative";
|
n@470
|
80 submit.style.left = (window.innerWidth-250)/2 + 'px';
|
n@470
|
81
|
n@470
|
82 feedbackHolder.appendChild(boxes);
|
n@470
|
83
|
n@470
|
84 // Inject into HTML
|
n@470
|
85 testContent.appendChild(title); // Insert the title
|
n@470
|
86 testContent.appendChild(pagetitle);
|
n@470
|
87 testContent.appendChild(interfaceButtons);
|
n@470
|
88 testContent.appendChild(feedbackHolder);
|
n@470
|
89 testContent.appendChild(submit);
|
n@470
|
90 interfaceContext.insertPoint.appendChild(testContent);
|
n@470
|
91
|
n@470
|
92 // Load the full interface
|
n@470
|
93 testState.initialise();
|
n@470
|
94 testState.advanceState();
|
n@470
|
95 }
|
n@470
|
96
|
n@470
|
97 function loadTest(audioHolderObject)
|
n@470
|
98 {
|
n@470
|
99 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@470
|
100 var interfaceObj = audioHolderObject.interfaces;
|
n@470
|
101 if (interfaceObj.length > 1)
|
n@470
|
102 {
|
n@470
|
103 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
|
n@470
|
104 }
|
n@470
|
105 interfaceObj = interfaceObj[0];
|
n@470
|
106
|
n@470
|
107 if(interfaceObj.title != null)
|
n@470
|
108 {
|
n@470
|
109 document.getElementById("pageTitle").textContent = interfaceObj.title;
|
n@470
|
110 }
|
n@470
|
111
|
n@470
|
112 // Populate the comparitor object
|
n@470
|
113 interfaceContext.comparitor = new Comparitor(audioHolderObject);
|
n@470
|
114 resizeWindow(null);
|
n@470
|
115 }
|
n@470
|
116
|
n@470
|
117 function Comparitor(audioHolderObject)
|
n@470
|
118 {
|
n@470
|
119 this.comparitorBox = function(audioElement,id,text)
|
n@470
|
120 {
|
n@470
|
121 this.parent = audioElement;
|
n@470
|
122 this.id = id;
|
n@470
|
123 this.value = 0;
|
n@470
|
124 this.disabled = true;
|
n@470
|
125 this.box = document.createElement('div');
|
n@470
|
126 this.box.className = 'comparitor-holder';
|
n@470
|
127 this.box.setAttribute('track-id',audioElement.id);
|
n@470
|
128 this.box.id = 'comparitor-'+text;
|
n@470
|
129 this.selector = document.createElement('div');
|
n@470
|
130 this.selector.className = 'comparitor-selector disabled';
|
n@470
|
131 var selectorText = document.createElement('span');
|
n@470
|
132 selectorText.textContent = text;
|
n@470
|
133 this.selector.appendChild(selectorText);
|
n@470
|
134 this.playback = document.createElement('button');
|
n@470
|
135 this.playback.className = 'comparitor-button';
|
n@470
|
136 this.playback.disabled = true;
|
n@470
|
137 this.playback.textContent = "Listen";
|
n@470
|
138 this.box.appendChild(this.selector);
|
n@470
|
139 this.box.appendChild(this.playback);
|
n@478
|
140 this.selector.onclick = function(event)
|
n@470
|
141 {
|
n@470
|
142 var time = audioEngineContext.timer.getTestTime();
|
n@470
|
143 if ($(event.currentTarget).hasClass('disabled'))
|
n@470
|
144 {
|
n@470
|
145 console.log("Please wait until sample has loaded");
|
n@470
|
146 return;
|
n@470
|
147 }
|
n@470
|
148 if (audioEngineContext.status == 0)
|
n@470
|
149 {
|
n@470
|
150 alert("Please listen to the samples before making a selection");
|
n@470
|
151 console.log("Please listen to the samples before making a selection");
|
n@470
|
152 return;
|
n@470
|
153 }
|
n@470
|
154 $(".comparitor-selector").removeClass('selected');
|
n@470
|
155 var id = event.currentTarget.parentElement.getAttribute('track-id');
|
n@470
|
156 interfaceContext.comparitor.selected = id;
|
n@470
|
157 $(event.currentTarget).addClass('selected');
|
n@470
|
158 for (var i=0; i<interfaceContext.comparitor.comparitors.length; i++)
|
n@470
|
159 {
|
n@470
|
160 var obj = interfaceContext.comparitor.comparitors[i];
|
n@470
|
161 if (i == id) {
|
n@470
|
162 obj.value = 1;
|
n@470
|
163 } else {
|
n@470
|
164 obj.value = 0;
|
n@470
|
165 }
|
n@470
|
166 obj.parent.metric.moved(time,obj.value);
|
n@470
|
167 }
|
n@470
|
168 console.log("Selected "+id+' ('+time+')');
|
n@470
|
169 };
|
n@478
|
170 this.playback.onclick = function(event)
|
n@470
|
171 {
|
n@470
|
172 $('.comparitor-button').text('Listen');
|
n@470
|
173 var id = event.currentTarget.parentElement.getAttribute('track-id');
|
n@470
|
174 audioEngineContext.play(id);
|
n@470
|
175 $(event.currentTarget).text('Playing');
|
n@470
|
176 };
|
n@470
|
177
|
n@470
|
178 this.enable = function()
|
n@470
|
179 {
|
n@470
|
180 if (this.parent.state == 1)
|
n@470
|
181 {
|
n@470
|
182 $(this.selector).removeClass('disabled');
|
n@470
|
183 this.playback.disabled = false;
|
n@470
|
184 }
|
n@470
|
185 };
|
n@470
|
186 this.updateLoading = function(progress)
|
n@470
|
187 {
|
n@470
|
188 if (progress != 100)
|
n@470
|
189 {
|
n@470
|
190 progress = String(progress);
|
n@470
|
191 progress = progress.split('.')[0];
|
n@470
|
192 this.playback.textContent = progress+'%';
|
n@470
|
193 } else {
|
n@470
|
194 this.playback.textContent = "Listen";
|
n@470
|
195 }
|
n@470
|
196 };
|
n@470
|
197 this.exportXMLDOM = function(audioObject)
|
n@470
|
198 {
|
n@470
|
199 var node = storage.document.createElement('value');
|
n@470
|
200 node.textContent = this.value;
|
n@470
|
201 return node;
|
n@470
|
202 };
|
n@470
|
203 this.getValue = function() {
|
n@470
|
204 return this.value;
|
n@470
|
205 };
|
n@470
|
206 this.getPresentedId = function()
|
n@470
|
207 {
|
n@470
|
208 return this.selector.children[0].textContent;
|
n@470
|
209 };
|
n@470
|
210 this.canMove = function()
|
n@470
|
211 {
|
n@470
|
212 return false;
|
n@470
|
213 };
|
n@470
|
214 };
|
n@470
|
215
|
n@470
|
216 this.boxHolders = document.getElementById('box-holders');
|
n@470
|
217 this.boxHolders.innerHTML = null;
|
n@470
|
218 this.comparitors = [];
|
n@470
|
219 this.selected = null;
|
n@470
|
220
|
n@470
|
221 // First generate the Audio Objects for the Audio Engine
|
n@470
|
222 for (var index=0; index<audioHolderObject.audioElements.length; index++)
|
n@470
|
223 {
|
n@470
|
224 var element = audioHolderObject.audioElements[index];
|
n@470
|
225 if (index == audioHolderObject.outsideReference || element.type == 'outside-reference')
|
n@470
|
226 {
|
n@470
|
227 console.log("WARNING - AB cannot have fixed reference");
|
n@470
|
228 }
|
n@470
|
229 var audioObject = audioEngineContext.newTrack(element);
|
n@470
|
230 var node = new this.comparitorBox(audioObject,index,String.fromCharCode(65 + index));
|
n@470
|
231 audioObject.bindInterface(node);
|
n@470
|
232 this.comparitors.push(node);
|
n@470
|
233 this.boxHolders.appendChild(node.box);
|
n@470
|
234 }
|
n@470
|
235 return this;
|
n@470
|
236 }
|
n@470
|
237
|
n@470
|
238 function resizeWindow(event)
|
n@470
|
239 {
|
n@470
|
240 document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px';
|
n@470
|
241 var numObj = interfaceContext.comparitor.comparitors.length;
|
n@470
|
242 var boxW = numObj*312;
|
n@470
|
243 var diff = window.innerWidth - boxW;
|
n@470
|
244 while (diff < 0)
|
n@470
|
245 {
|
n@470
|
246 numObj = Math.ceil(numObj/2);
|
n@470
|
247 boxW = numObj*312;
|
n@470
|
248 diff = window.innerWidth - boxW;
|
n@470
|
249 }
|
n@470
|
250 document.getElementById('box-holders').style.marginLeft = diff/2 + 'px';
|
n@470
|
251 document.getElementById('box-holders').style.marginRight = diff/2 + 'px';
|
n@470
|
252 document.getElementById('box-holders').style.width = boxW + 'px';
|
n@470
|
253 }
|
n@470
|
254
|
n@470
|
255 function buttonSubmitClick()
|
n@470
|
256 {
|
n@470
|
257 var checks = [];
|
n@470
|
258 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
|
n@470
|
259 checks = checks.concat(specification.interfaces.options);
|
n@470
|
260 var canContinue = true;
|
n@470
|
261
|
n@470
|
262 for (var i=0; i<checks.length; i++) {
|
n@470
|
263 if (checks[i].type == 'check')
|
n@470
|
264 {
|
n@470
|
265 switch(checks[i].name) {
|
n@470
|
266 case 'fragmentPlayed':
|
n@470
|
267 // Check if all fragments have been played
|
n@470
|
268 var checkState = interfaceContext.checkAllPlayed();
|
n@470
|
269 if (checkState == false) {canContinue = false;}
|
n@470
|
270 break;
|
n@470
|
271 case 'fragmentFullPlayback':
|
n@470
|
272 // Check all fragments have been played to their full length
|
n@470
|
273 var checkState = interfaceContext.checkFragmentsFullyPlayed();
|
n@470
|
274 if (checkState == false) {canContinue = false;}
|
n@470
|
275 break;
|
n@470
|
276 case 'fragmentMoved':
|
n@470
|
277 // Check all fragment sliders have been moved.
|
n@470
|
278 var checkState = interfaceContext.checkAllMoved();
|
n@470
|
279 if (checkState == false) {canContinue = false;}
|
n@470
|
280 break;
|
n@470
|
281 case 'fragmentComments':
|
n@470
|
282 // Check all fragment sliders have been moved.
|
n@470
|
283 var checkState = interfaceContext.checkAllCommented();
|
n@470
|
284 if (checkState == false) {canContinue = false;}
|
n@470
|
285 break;
|
n@470
|
286 default:
|
n@470
|
287 console.log("WARNING - Check option "+checks[i].check+" is not supported on this interface");
|
n@470
|
288 break;
|
n@470
|
289 }
|
n@470
|
290
|
n@470
|
291 }
|
n@470
|
292 if (!canContinue) {break;}
|
n@470
|
293 }
|
n@470
|
294 if (canContinue)
|
n@470
|
295 {
|
n@470
|
296 if (audioEngineContext.status == 1) {
|
n@470
|
297 var playback = document.getElementById('playback-button');
|
n@470
|
298 playback.click();
|
n@470
|
299 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
n@470
|
300 } else
|
n@470
|
301 {
|
n@470
|
302 if (audioEngineContext.timer.testStarted == false)
|
n@470
|
303 {
|
n@470
|
304 alert('You have not started the test! Please press start to begin the test!');
|
n@470
|
305 return;
|
n@470
|
306 }
|
n@470
|
307 }
|
n@470
|
308 testState.advanceState();
|
n@470
|
309 }
|
n@470
|
310 }
|
n@470
|
311
|
n@470
|
312 function pageXMLSave(store, pageSpecification)
|
n@470
|
313 {
|
n@470
|
314 // MANDATORY
|
n@470
|
315 // Saves a specific test page
|
n@470
|
316 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
n@470
|
317 // Get the current <page> information in store (remember to appendChild your data to it)
|
n@470
|
318 // pageSpecification is the current page node configuration
|
n@470
|
319 // To create new XML nodes, use storage.document.createElement();
|
n@470
|
320 } |