nickjillings@1345
|
1 // Once this is loaded and parsed, begin execution
|
nickjillings@1345
|
2 loadInterface();
|
nickjillings@1345
|
3
|
nickjillings@1345
|
4 function loadInterface() {
|
nickjillings@1345
|
5 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects,
|
nickjillings@1345
|
6 // holding div's, or setting up any nodes which are present for the entire test sequence
|
nickjillings@1345
|
7
|
nickjillings@1345
|
8 // The injection point into the HTML page
|
nickjillings@1345
|
9 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1345
|
10 var testContent = document.createElement('div');
|
nickjillings@1345
|
11 testContent.id = 'testContent';
|
nickjillings@1345
|
12
|
nickjillings@1345
|
13 // Create the top div for the Title element
|
nickjillings@1345
|
14 var titleAttr = specification.title;
|
nickjillings@1345
|
15 var title = document.createElement('div');
|
nickjillings@1345
|
16 title.className = "title";
|
nickjillings@1345
|
17 title.align = "center";
|
nickjillings@1345
|
18 var titleSpan = document.createElement('span');
|
nicholas@2470
|
19 titleSpan.id = "test-title";
|
nickjillings@1345
|
20
|
nickjillings@1345
|
21 // Set title to that defined in XML, else set to default
|
nickjillings@1345
|
22 if (titleAttr != undefined) {
|
nickjillings@1345
|
23 titleSpan.textContent = titleAttr;
|
nickjillings@1345
|
24 } else {
|
nickjillings@1345
|
25 titleSpan.textContent = 'Listening test';
|
nickjillings@1345
|
26 }
|
nickjillings@1345
|
27 // Insert the titleSpan element into the title div element.
|
nickjillings@1345
|
28 title.appendChild(titleSpan);
|
nickjillings@1345
|
29
|
nickjillings@1345
|
30 var pagetitle = document.createElement('div');
|
nickjillings@1345
|
31 pagetitle.className = "pageTitle";
|
nickjillings@1345
|
32 pagetitle.align = "center";
|
nickjillings@1345
|
33 var titleSpan = document.createElement('span');
|
nickjillings@1345
|
34 titleSpan.id = "pageTitle";
|
nickjillings@1345
|
35 pagetitle.appendChild(titleSpan);
|
nickjillings@1345
|
36
|
nickjillings@1345
|
37 // Create Interface buttons!
|
nickjillings@1345
|
38 var interfaceButtons = document.createElement('div');
|
nickjillings@1345
|
39 interfaceButtons.id = 'interface-buttons';
|
nickjillings@1345
|
40 interfaceButtons.style.height = '25px';
|
nickjillings@1345
|
41
|
nickjillings@1345
|
42 // Create playback start/stop points
|
nickjillings@1345
|
43 var playback = document.createElement("button");
|
nickjillings@1345
|
44 playback.innerHTML = 'Stop';
|
nickjillings@1345
|
45 playback.id = 'playback-button';
|
nickjillings@1345
|
46 playback.style.float = 'left';
|
nickjillings@1345
|
47 // onclick function. Check if it is playing or not, call the correct function in the
|
nickjillings@1345
|
48 // audioEngine, change the button text to reflect the next state.
|
nickjillings@1345
|
49 playback.onclick = function() {
|
nickjillings@1345
|
50 if (audioEngineContext.status == 1) {
|
nickjillings@1345
|
51 audioEngineContext.stop();
|
nickjillings@1345
|
52 this.innerHTML = 'Stop';
|
nickjillings@1345
|
53 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1345
|
54 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nickjillings@1345
|
55 }
|
nickjillings@1345
|
56 };
|
nicholas@2396
|
57
|
nicholas@2396
|
58 // Create outside reference holder
|
nicholas@2396
|
59 var outsideRef = document.createElement("div");
|
nicholas@2396
|
60 outsideRef.id = "outside-reference-holder";
|
nicholas@2396
|
61
|
nickjillings@1345
|
62 // Create Submit (save) button
|
nickjillings@1345
|
63 var submit = document.createElement("button");
|
nickjillings@1295
|
64 submit.innerHTML = 'Next';
|
nickjillings@1345
|
65 submit.onclick = buttonSubmitClick;
|
nickjillings@1345
|
66 submit.id = 'submit-button';
|
nickjillings@1345
|
67 submit.style.float = 'left';
|
nickjillings@1345
|
68 // Append the interface buttons into the interfaceButtons object.
|
nickjillings@1345
|
69 interfaceButtons.appendChild(playback);
|
nickjillings@1345
|
70 interfaceButtons.appendChild(submit);
|
nickjillings@1345
|
71
|
nickjillings@1345
|
72 // Create a slider box
|
nickjillings@1345
|
73 var sliderBox = document.createElement('div');
|
nickjillings@1345
|
74 sliderBox.style.width = "100%";
|
nickjillings@1345
|
75 sliderBox.style.height = window.innerHeight - 200+12 + 'px';
|
nickjillings@1345
|
76 sliderBox.style.marginBottom = '10px';
|
nickjillings@1345
|
77 sliderBox.id = 'slider';
|
nickjillings@1345
|
78 var scaleHolder = document.createElement('div');
|
nickjillings@1345
|
79 scaleHolder.id = "scale-holder";
|
nickjillings@1345
|
80 scaleHolder.style.marginLeft = "107px";
|
nickjillings@1345
|
81 sliderBox.appendChild(scaleHolder);
|
nickjillings@1345
|
82 var scaleText = document.createElement('div');
|
nickjillings@1345
|
83 scaleText.id = "scale-text-holder";
|
nickjillings@1345
|
84 scaleText.style.height = "25px";
|
nickjillings@1345
|
85 scaleText.style.width = "100%";
|
nickjillings@1345
|
86 scaleHolder.appendChild(scaleText);
|
nickjillings@1345
|
87 var scaleCanvas = document.createElement('canvas');
|
nickjillings@1345
|
88 scaleCanvas.id = "scale-canvas";
|
nickjillings@1346
|
89 scaleCanvas.style.marginLeft = "150px";
|
nickjillings@1345
|
90 scaleHolder.appendChild(scaleCanvas);
|
nickjillings@1345
|
91 var sliderObjectHolder = document.createElement('div');
|
nickjillings@1345
|
92 sliderObjectHolder.id = 'slider-holder';
|
nickjillings@1345
|
93 sliderObjectHolder.align = "center";
|
nickjillings@1345
|
94 sliderBox.appendChild(sliderObjectHolder);
|
nickjillings@1345
|
95
|
nickjillings@1345
|
96 // Global parent for the comment boxes on the page
|
nickjillings@1345
|
97 var feedbackHolder = document.createElement('div');
|
nickjillings@1345
|
98 feedbackHolder.id = 'feedbackHolder';
|
nickjillings@1345
|
99
|
nickjillings@1345
|
100 testContent.style.zIndex = 1;
|
nicholas@2381
|
101 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
|
nickjillings@1345
|
102
|
nickjillings@1345
|
103 // Inject into HTML
|
nickjillings@1345
|
104 testContent.appendChild(title); // Insert the title
|
nickjillings@1345
|
105 testContent.appendChild(pagetitle);
|
nickjillings@1345
|
106 testContent.appendChild(interfaceButtons);
|
nicholas@2396
|
107 testContent.appendChild(outsideRef);
|
nickjillings@1345
|
108 testContent.appendChild(sliderBox);
|
nickjillings@1345
|
109 testContent.appendChild(feedbackHolder);
|
nickjillings@1345
|
110 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@1345
|
111
|
nickjillings@1345
|
112 // Load the full interface
|
nickjillings@1345
|
113 testState.initialise();
|
nickjillings@1345
|
114 testState.advanceState();
|
nickjillings@1345
|
115 };
|
nickjillings@1345
|
116
|
nickjillings@1345
|
117 function loadTest(page)
|
nickjillings@1345
|
118 {
|
nickjillings@1345
|
119 // Called each time a new test page is to be build. The page specification node is the only item passed in
|
nickjillings@1345
|
120 var id = page.id;
|
nickjillings@1345
|
121
|
nickjillings@1345
|
122 var feedbackHolder = document.getElementById('feedbackHolder');
|
nicholas@2381
|
123 feedbackHolder.innerHTML = "";
|
nickjillings@1345
|
124 var interfaceObj = page.interfaces;
|
nickjillings@1345
|
125 if (interfaceObj.length > 1)
|
nickjillings@1345
|
126 {
|
nickjillings@1345
|
127 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
|
nickjillings@1345
|
128 }
|
nickjillings@1345
|
129 interfaceObj = interfaceObj[0];
|
nicholas@2470
|
130
|
nicholas@2470
|
131 // Set the page title
|
nicholas@2470
|
132 if (typeof page.title == "string" && page.title.length > 0) {
|
nicholas@2470
|
133 document.getElementById("test-title").textContent = page.title
|
nicholas@2470
|
134 }
|
nicholas@2470
|
135
|
nickjillings@1345
|
136 if(interfaceObj.title != null)
|
nickjillings@1345
|
137 {
|
nickjillings@1345
|
138 document.getElementById("pageTitle").textContent = interfaceObj.title;
|
nickjillings@1345
|
139 }
|
nickjillings@1345
|
140
|
nickjillings@1345
|
141 // Delete outside reference
|
nicholas@2396
|
142 document.getElementById("outside-reference-holder").innerHTML = "";
|
nickjillings@1345
|
143
|
nickjillings@1345
|
144 var sliderBox = document.getElementById('slider-holder');
|
nicholas@2381
|
145 sliderBox.innerHTML = "";
|
nickjillings@1345
|
146
|
nickjillings@1345
|
147 var commentBoxPrefix = "Comment on track";
|
nickjillings@1345
|
148 if (interfaceObj.commentBoxPrefix != undefined) {
|
nickjillings@1345
|
149 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
nickjillings@1345
|
150 }
|
nickjillings@1345
|
151 var loopPlayback = page.loop;
|
nickjillings@1345
|
152
|
nickjillings@1345
|
153 $(page.commentQuestions).each(function(index,element) {
|
nickjillings@1345
|
154 var node = interfaceContext.createCommentQuestion(element);
|
nickjillings@1345
|
155 feedbackHolder.appendChild(node.holder);
|
nickjillings@1345
|
156 });
|
nickjillings@1345
|
157
|
nickjillings@1345
|
158 // Find all the audioElements from the audioHolder
|
nickjillings@1295
|
159 var index = 0;
|
nickjillings@1346
|
160 var interfaceScales = testState.currentStateMap.interfaces[0].scales;
|
nickjillings@1345
|
161 $(page.audioElements).each(function(index,element){
|
nickjillings@1345
|
162 // Find URL of track
|
nickjillings@1345
|
163 // In this jQuery loop, variable 'this' holds the current audioElement.
|
nickjillings@1345
|
164
|
nickjillings@1345
|
165 var audioObject = audioEngineContext.newTrack(element);
|
nickjillings@1345
|
166 if (element.type == 'outside-reference')
|
nickjillings@1345
|
167 {
|
nickjillings@1345
|
168 // Construct outside reference;
|
nicholas@2396
|
169 var orNode = new interfaceContext.outsideReferenceDOM(audioObject,index,document.getElementById("outside-reference-holder"));
|
nickjillings@1345
|
170 audioObject.bindInterface(orNode);
|
nickjillings@1345
|
171 } else {
|
nickjillings@1345
|
172 // Create a slider per track
|
nickjillings@1295
|
173 switch(audioObject.specification.parent.label) {
|
nickjillings@1295
|
174 case "none":
|
nickjillings@1295
|
175 label = "";
|
nickjillings@1295
|
176 break;
|
nickjillings@1295
|
177 case "letter":
|
nickjillings@1295
|
178 label = String.fromCharCode(97 + index);
|
nickjillings@1295
|
179 break;
|
nickjillings@1295
|
180 case "capital":
|
nickjillings@1295
|
181 label = String.fromCharCode(65 + index);
|
nickjillings@1295
|
182 break;
|
nickjillings@1295
|
183 default:
|
nickjillings@1295
|
184 label = ""+index;
|
nickjillings@1295
|
185 break;
|
nickjillings@1295
|
186 }
|
nickjillings@1346
|
187 var sliderObj = new discreteObject(audioObject,label,interfaceScales);
|
nickjillings@1345
|
188 sliderBox.appendChild(sliderObj.holder);
|
nickjillings@1345
|
189 audioObject.bindInterface(sliderObj);
|
nickjillings@2117
|
190 interfaceContext.commentBoxes.createCommentBox(audioObject);
|
nickjillings@1295
|
191 index += 1;
|
nickjillings@1345
|
192 }
|
nickjillings@1345
|
193
|
nickjillings@1345
|
194 });
|
nickjillings@1345
|
195
|
n@2407
|
196 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
|
n@2407
|
197 for (var option of interfaceOptions)
|
nickjillings@1316
|
198 {
|
n@2407
|
199 if (option.type == "show")
|
n@2407
|
200 {
|
n@2407
|
201 switch(option.name) {
|
n@2407
|
202 case "playhead":
|
n@2407
|
203 var playbackHolder = document.getElementById('playback-holder');
|
n@2407
|
204 if (playbackHolder == null)
|
n@2407
|
205 {
|
n@2407
|
206 playbackHolder = document.createElement('div');
|
n@2407
|
207 playbackHolder.style.width = "100%";
|
n@2407
|
208 playbackHolder.align = 'center';
|
n@2407
|
209 playbackHolder.appendChild(interfaceContext.playhead.object);
|
n@2407
|
210 feedbackHolder.appendChild(playbackHolder);
|
n@2407
|
211 }
|
n@2407
|
212 break;
|
n@2407
|
213 case "page-count":
|
n@2407
|
214 var pagecountHolder = document.getElementById('page-count');
|
n@2407
|
215 if (pagecountHolder == null)
|
n@2407
|
216 {
|
n@2407
|
217 pagecountHolder = document.createElement('div');
|
n@2407
|
218 pagecountHolder.id = 'page-count';
|
n@2407
|
219 }
|
n@2407
|
220 pagecountHolder.innerHTML = '<span>Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+'</span>';
|
n@2407
|
221 var inject = document.getElementById('interface-buttons');
|
n@2407
|
222 inject.appendChild(pagecountHolder);
|
n@2407
|
223 break;
|
n@2407
|
224 case "volume":
|
n@2407
|
225 if (document.getElementById('master-volume-holder') == null)
|
n@2407
|
226 {
|
n@2407
|
227 feedbackHolder.appendChild(interfaceContext.volume.object);
|
n@2407
|
228 }
|
n@2407
|
229 break;
|
n@2407
|
230 case "comments":
|
n@2407
|
231 interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder,true);
|
n@2407
|
232 break;
|
n@2407
|
233 }
|
n@2407
|
234 }
|
nickjillings@1316
|
235 }
|
nickjillings@1316
|
236
|
n@2407
|
237 $(page.commentQuestions).each(function(index,element) {
|
n@2407
|
238 var node = interfaceContext.createCommentQuestion(element);
|
n@2407
|
239 commentHolder.appendChild(node.holder);
|
n@2407
|
240 });
|
n@2407
|
241
|
nickjillings@1345
|
242 // Auto-align
|
nickjillings@1345
|
243 resizeWindow(null);
|
nickjillings@1345
|
244 }
|
nickjillings@1345
|
245
|
nickjillings@1346
|
246 function discreteObject(audioObject,label,interfaceScales)
|
nickjillings@1345
|
247 {
|
nickjillings@1345
|
248 // An example node, you can make this however you want for each audioElement.
|
nickjillings@1345
|
249 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following
|
nickjillings@1345
|
250 // You attach them by calling audioObject.bindInterface( )
|
nickjillings@1346
|
251 if (interfaceScales == null || interfaceScales.length == 0)
|
nickjillings@1345
|
252 {
|
nickjillings@1345
|
253 console.log("WARNING: The discrete radio's are built depending on the number of scale points specified! Ensure you have some specified. Defaulting to 5 for now!");
|
nickjillings@1345
|
254 numOptions = 5;
|
nickjillings@1345
|
255 }
|
nickjillings@1345
|
256 this.parent = audioObject;
|
nickjillings@1345
|
257
|
nickjillings@1345
|
258 this.holder = document.createElement('div');
|
nickjillings@1345
|
259 this.title = document.createElement('div');
|
nickjillings@1345
|
260 this.discreteHolder = document.createElement('div');
|
nickjillings@1345
|
261 this.discretes = [];
|
nickjillings@1345
|
262 this.play = document.createElement('button');
|
nickjillings@1345
|
263
|
nickjillings@1345
|
264 this.holder.className = 'track-slider';
|
nickjillings@1345
|
265 this.holder.style.width = window.innerWidth-200 + 'px';
|
nickjillings@1345
|
266 this.holder.appendChild(this.title);
|
nickjillings@1345
|
267 this.holder.appendChild(this.discreteHolder);
|
nickjillings@1345
|
268 this.holder.appendChild(this.play);
|
nickjillings@1345
|
269 this.holder.setAttribute('trackIndex',audioObject.id);
|
nickjillings@1345
|
270 this.title.textContent = label;
|
nickjillings@1345
|
271 this.title.className = 'track-slider-title';
|
nickjillings@1345
|
272
|
nickjillings@1345
|
273 this.discreteHolder.className = "track-slider-range";
|
nickjillings@1346
|
274 this.discreteHolder.style.width = window.innerWidth-500 + 'px';
|
nickjillings@1346
|
275 for (var i=0; i<interfaceScales.length; i++)
|
nickjillings@1345
|
276 {
|
nickjillings@1345
|
277 var node = document.createElement('input');
|
nickjillings@1345
|
278 node.setAttribute('type','radio');
|
nickjillings@1346
|
279 node.className = 'track-radio';
|
nickjillings@1316
|
280 node.disabled = true;
|
nickjillings@1346
|
281 node.setAttribute('position',interfaceScales[i].position);
|
nickjillings@1345
|
282 node.setAttribute('name',audioObject.specification.id);
|
nickjillings@1345
|
283 node.setAttribute('id',audioObject.specification.id+'-'+String(i));
|
nickjillings@1345
|
284 this.discretes.push(node);
|
nickjillings@1345
|
285 this.discreteHolder.appendChild(node);
|
nickjillings@1346
|
286 node.onclick = function(event)
|
nickjillings@1345
|
287 {
|
nickjillings@1346
|
288 if (audioEngineContext.status == 0)
|
nickjillings@1346
|
289 {
|
nickjillings@1346
|
290 event.currentTarget.checked = false;
|
nickjillings@1346
|
291 return;
|
nickjillings@1346
|
292 }
|
nickjillings@1345
|
293 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1345
|
294 var id = Number(event.currentTarget.parentNode.parentNode.getAttribute('trackIndex'));
|
nickjillings@1346
|
295 var value = event.currentTarget.getAttribute('position') / 100.0;
|
nickjillings@1346
|
296 audioEngineContext.audioObjects[id].metric.moved(time,value);
|
nickjillings@1346
|
297 console.log('slider '+id+' moved to '+value+' ('+time+')');
|
nickjillings@1345
|
298 };
|
nickjillings@1345
|
299 }
|
nickjillings@1345
|
300
|
nickjillings@1345
|
301 this.play.className = 'track-slider-button';
|
nickjillings@1345
|
302 this.play.textContent = "Loading...";
|
nickjillings@1345
|
303 this.play.value = audioObject.id;
|
nickjillings@1345
|
304 this.play.disabled = true;
|
nickjillings@1377
|
305 this.play.setAttribute("playstate","ready");
|
nickjillings@1345
|
306 this.play.onclick = function(event)
|
nickjillings@1345
|
307 {
|
nickjillings@1345
|
308 var id = Number(event.currentTarget.value);
|
nickjillings@1345
|
309 //audioEngineContext.metric.sliderPlayed(id);
|
nickjillings@1377
|
310 if (event.currentTarget.getAttribute("playstate") == "ready")
|
nickjillings@1377
|
311 audioEngineContext.play(id);
|
nickjillings@1377
|
312 else if (event.currentTarget.getAttribute("playstate") == "playing")
|
nickjillings@1377
|
313 audioEngineContext.stop();
|
nickjillings@1345
|
314 };
|
nickjillings@1345
|
315 this.resize = function(event)
|
nickjillings@1345
|
316 {
|
nickjillings@1345
|
317 this.holder.style.width = window.innerWidth-200 + 'px';
|
nickjillings@1346
|
318 this.discreteHolder.style.width = window.innerWidth-500 + 'px';
|
nickjillings@1346
|
319 //text.style.left = (posPix+150-($(text).width()/2)) +'px';
|
nickjillings@1346
|
320 for (var i=0; i<this.discretes.length; i++)
|
nickjillings@1346
|
321 {
|
nickjillings@1346
|
322 var width = $(this.discreteHolder).width() - 20;
|
nickjillings@1346
|
323 var node = this.discretes[i];
|
nickjillings@1346
|
324 var nodeW = $(node).width();
|
nickjillings@1346
|
325 var position = node.getAttribute('position');
|
nickjillings@1346
|
326 var posPix = Math.round(width * (position / 100.0));
|
nickjillings@1346
|
327 node.style.left = (posPix+10 - (nodeW/2)) + 'px';
|
nickjillings@1346
|
328 }
|
nickjillings@1345
|
329 };
|
nickjillings@1345
|
330 this.enable = function()
|
nickjillings@1345
|
331 {
|
nickjillings@1345
|
332 // This is used to tell the interface object that playback of this node is ready
|
nickjillings@1345
|
333 this.play.disabled = false;
|
nickjillings@1345
|
334 this.play.textContent = "Play";
|
nickjillings@1345
|
335 $(this.slider).removeClass('track-slider-disabled');
|
nickjillings@1316
|
336 for (var radio of this.discretes)
|
nickjillings@1316
|
337 {
|
nickjillings@1316
|
338 radio.disabled = false;
|
nickjillings@1316
|
339 }
|
nickjillings@1345
|
340 };
|
nickjillings@1345
|
341 this.updateLoading = function(progress)
|
nickjillings@1345
|
342 {
|
nickjillings@1345
|
343 // progress is a value from 0 to 100 indicating the current download state of media files
|
nickjillings@1316
|
344 if (progress != 100)
|
nickjillings@1316
|
345 {
|
nickjillings@1316
|
346 progress = String(progress);
|
nickjillings@1316
|
347 progress = progress.split('.')[0];
|
nickjillings@1316
|
348 this.play.textContent = progress+'%';
|
nickjillings@1316
|
349 } else {
|
nickjillings@1316
|
350 this.play.textContent = "Play";
|
nickjillings@1316
|
351 }
|
nickjillings@1345
|
352 };
|
nickjillings@1360
|
353
|
nickjillings@1360
|
354 this.startPlayback = function()
|
nickjillings@1360
|
355 {
|
nickjillings@1360
|
356 // Called by audioObject when playback begins
|
nickjillings@1377
|
357 this.play.setAttribute("playstate","playing");
|
nickjillings@1360
|
358 $(".track-slider").removeClass('track-slider-playing');
|
nickjillings@1360
|
359 $(this.holder).addClass('track-slider-playing');
|
nickjillings@1360
|
360 var outsideReference = document.getElementById('outside-reference');
|
nickjillings@1316
|
361 this.play.textContent = "Listening";
|
nickjillings@1360
|
362 if (outsideReference != null) {
|
nickjillings@1360
|
363 $(outsideReference).removeClass('track-slider-playing');
|
nickjillings@1360
|
364 }
|
n@2428
|
365 if (this.parent.specification.parent.playOne || specification.playOne) {
|
n@2428
|
366 $('.track-slider-button').text = "Wait";
|
n@2428
|
367 $('.track-slider-button').attr("disabled","true");
|
n@2428
|
368 }
|
nickjillings@1360
|
369 }
|
nickjillings@1360
|
370 this.stopPlayback = function()
|
nickjillings@1360
|
371 {
|
nickjillings@1360
|
372 // Called by audioObject when playback stops
|
n@2428
|
373 if (this.play.getAttribute("playstate") == "playing") {
|
n@2428
|
374 this.play.setAttribute("playstate","ready");
|
n@2428
|
375 $(this.holder).removeClass('track-slider-playing');
|
n@2428
|
376 $('.track-slider-button').text = "Play";
|
n@2428
|
377 this.play.textContent = "Play";
|
n@2428
|
378 $('.track-slider-button').removeAttr("disabled");
|
n@2428
|
379 }
|
nickjillings@1360
|
380 }
|
nickjillings@1360
|
381
|
nickjillings@1345
|
382 this.getValue = function()
|
nickjillings@1345
|
383 {
|
nickjillings@1346
|
384 // Return the current value of the object. If there is no value, return -1
|
nickjillings@1346
|
385 var value = -1;
|
nickjillings@1346
|
386 for (var i=0; i<this.discretes.length; i++)
|
nickjillings@1346
|
387 {
|
nickjillings@1346
|
388 if (this.discretes[i].checked == true)
|
nickjillings@1346
|
389 {
|
nickjillings@1346
|
390 value = this.discretes[i].getAttribute('position') / 100.0;
|
nickjillings@1346
|
391 break;
|
nickjillings@1346
|
392 }
|
nickjillings@1346
|
393 }
|
nickjillings@1346
|
394 return value;
|
nickjillings@1345
|
395 };
|
nickjillings@1345
|
396 this.getPresentedId = function()
|
nickjillings@1345
|
397 {
|
nickjillings@1345
|
398 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale
|
nickjillings@1345
|
399 return this.title.textContent;
|
nickjillings@1345
|
400 };
|
nickjillings@1345
|
401 this.canMove = function()
|
nickjillings@1345
|
402 {
|
nickjillings@1345
|
403 // Return either true or false if the interface object can be moved. AB / Reference cannot, whilst sliders can and therefore have a continuous scale.
|
nickjillings@1345
|
404 // These are checked primarily if the interface check option 'fragmentMoved' is enabled.
|
nickjillings@1345
|
405 return true;
|
nickjillings@1345
|
406 };
|
nickjillings@1345
|
407 this.exportXMLDOM = function(audioObject) {
|
nickjillings@1345
|
408 // Called by the audioObject holding this element to export the interface <value> node.
|
nickjillings@1345
|
409 // If there is no value node (such as outside reference), return null
|
nickjillings@1345
|
410 // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute
|
nickjillings@1345
|
411 // Use storage.document.createElement('value'); to generate the XML node.
|
nickjillings@1346
|
412 var node = storage.document.createElement('value');
|
nickjillings@1346
|
413 node.textContent = this.getValue();
|
nickjillings@1346
|
414 return node;
|
nickjillings@1345
|
415 };
|
nickjillings@2113
|
416 this.error = function() {
|
nickjillings@2113
|
417 // audioObject has an error!!
|
nickjillings@2113
|
418 this.playback.textContent = "Error";
|
nickjillings@2113
|
419 $(this.playback).addClass("error-colour");
|
nickjillings@2113
|
420 }
|
nickjillings@1345
|
421 };
|
nickjillings@1345
|
422
|
nickjillings@1345
|
423 function resizeWindow(event)
|
nickjillings@1345
|
424 {
|
nickjillings@1345
|
425 // Called on every window resize event, use this to scale your page properly
|
nickjillings@1345
|
426 var numObj = document.getElementsByClassName('track-slider').length;
|
nickjillings@1345
|
427 var totalHeight = (numObj * 66)-30;
|
nickjillings@1345
|
428 document.getElementById('scale-holder').style.width = window.innerWidth-220 + 'px';
|
nicholas@2381
|
429 // Cheers edge for making me delete a canvas every resize.
|
nickjillings@1345
|
430 var canvas = document.getElementById('scale-canvas');
|
nicholas@2381
|
431 var new_canvas = document.createElement("canvas");
|
nicholas@2381
|
432 new_canvas.id = 'scale-canvas';
|
nicholas@2381
|
433 new_canvas.style.marginLeft = "150px";
|
nicholas@2381
|
434 canvas.parentElement.appendChild(new_canvas);
|
nicholas@2381
|
435 canvas.parentElement.removeChild(canvas);
|
nicholas@2381
|
436 new_canvas.width = window.innerWidth-520;
|
nicholas@2381
|
437 new_canvas.height = totalHeight;
|
nickjillings@1345
|
438 for (var i in audioEngineContext.audioObjects)
|
nickjillings@1345
|
439 {
|
nickjillings@1345
|
440 if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference'){
|
nickjillings@1345
|
441 audioEngineContext.audioObjects[i].interfaceDOM.resize(event);
|
nickjillings@1345
|
442 }
|
nickjillings@1345
|
443 }
|
nickjillings@1354
|
444 document.getElementById('slider-holder').style.height = totalHeight + 'px';
|
nickjillings@1354
|
445 document.getElementById('slider').style.height = totalHeight + 70 + 'px';
|
nickjillings@1345
|
446 drawScale();
|
nickjillings@1345
|
447 }
|
nickjillings@1345
|
448
|
nickjillings@1345
|
449 function drawScale()
|
nickjillings@1345
|
450 {
|
nickjillings@1345
|
451 var interfaceObj = testState.currentStateMap.interfaces[0];
|
nickjillings@1345
|
452 var scales = testState.currentStateMap.interfaces[0].scales;
|
nickjillings@1345
|
453 scales = scales.sort(function(a,b) {
|
nickjillings@1345
|
454 return a.position - b.position;
|
nickjillings@1345
|
455 });
|
nickjillings@1345
|
456 var canvas = document.getElementById('scale-canvas');
|
nickjillings@1345
|
457 var ctx = canvas.getContext("2d");
|
nickjillings@1345
|
458 var height = canvas.height;
|
nickjillings@1345
|
459 var width = canvas.width;
|
nickjillings@1345
|
460 var textHolder = document.getElementById('scale-text-holder');
|
nicholas@2381
|
461 textHolder.innerHTML = "";
|
nickjillings@1345
|
462 ctx.fillStyle = "#000000";
|
nickjillings@1345
|
463 ctx.setLineDash([1,4]);
|
nickjillings@1345
|
464 for (var scale of scales)
|
nickjillings@1345
|
465 {
|
nickjillings@1345
|
466 var posPercent = scale.position / 100.0;
|
nickjillings@1345
|
467 var posPix = Math.round(width * posPercent);
|
nickjillings@1345
|
468 if(posPix<=0){posPix=1;}
|
nickjillings@1345
|
469 if(posPix>=width){posPix=width-1;}
|
nickjillings@1345
|
470 ctx.moveTo(posPix,0);
|
nickjillings@1345
|
471 ctx.lineTo(posPix,height);
|
nickjillings@1345
|
472 ctx.stroke();
|
nickjillings@1345
|
473
|
nickjillings@1345
|
474 var text = document.createElement('div');
|
nickjillings@1345
|
475 text.align = "center";
|
nickjillings@1345
|
476 var textC = document.createElement('span');
|
nickjillings@1345
|
477 textC.textContent = scale.text;
|
nickjillings@1345
|
478 text.appendChild(textC);
|
nickjillings@1345
|
479 text.className = "scale-text";
|
nickjillings@1345
|
480 textHolder.appendChild(text);
|
nickjillings@1346
|
481 text.style.width = $(text.children[0]).width()+'px';
|
nickjillings@1346
|
482 text.style.left = (posPix+150-($(text).width()/2)) +'px';
|
nickjillings@1345
|
483 }
|
nickjillings@1345
|
484 }
|
nickjillings@1345
|
485
|
nickjillings@1345
|
486 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
nickjillings@1345
|
487 {
|
nickjillings@1345
|
488 var checks = [];
|
nickjillings@1345
|
489 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
|
nickjillings@1345
|
490 checks = checks.concat(specification.interfaces.options);
|
nickjillings@1345
|
491 var canContinue = true;
|
nickjillings@1345
|
492
|
nickjillings@1345
|
493 // Check that the anchor and reference objects are correctly placed
|
nickjillings@1345
|
494 if (interfaceContext.checkHiddenAnchor() == false) {return;}
|
nickjillings@1345
|
495 if (interfaceContext.checkHiddenReference() == false) {return;}
|
nickjillings@1345
|
496
|
nickjillings@1345
|
497 for (var i=0; i<checks.length; i++) {
|
nickjillings@1345
|
498 if (checks[i].type == 'check')
|
nickjillings@1345
|
499 {
|
nickjillings@1345
|
500 switch(checks[i].name) {
|
nickjillings@1345
|
501 case 'fragmentPlayed':
|
nickjillings@1345
|
502 // Check if all fragments have been played
|
nickjillings@1345
|
503 var checkState = interfaceContext.checkAllPlayed();
|
nickjillings@1345
|
504 if (checkState == false) {canContinue = false;}
|
nickjillings@1345
|
505 break;
|
nickjillings@1345
|
506 case 'fragmentFullPlayback':
|
nickjillings@1345
|
507 // Check all fragments have been played to their full length
|
nickjillings@1345
|
508 var checkState = interfaceContext.checkAllPlayed();
|
nickjillings@1345
|
509 if (checkState == false) {canContinue = false;}
|
nickjillings@1345
|
510 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
|
nickjillings@1345
|
511 break;
|
nickjillings@1345
|
512 case 'fragmentMoved':
|
nickjillings@1345
|
513 // Check all fragment sliders have been moved.
|
nickjillings@1345
|
514 var checkState = interfaceContext.checkAllMoved();
|
nickjillings@1345
|
515 if (checkState == false) {canContinue = false;}
|
nickjillings@1345
|
516 break;
|
nickjillings@1345
|
517 case 'fragmentComments':
|
nickjillings@1345
|
518 // Check all fragment sliders have been moved.
|
nickjillings@1345
|
519 var checkState = interfaceContext.checkAllCommented();
|
nickjillings@1345
|
520 if (checkState == false) {canContinue = false;}
|
nickjillings@1345
|
521 break;
|
nicholas@2310
|
522 case 'scalerange':
|
nicholas@2310
|
523 // Check the scale has been used effectively
|
nicholas@2310
|
524 var checkState = interfaceContext.checkScaleRange(checks[i].min,checks[i].max);
|
nicholas@2310
|
525 if (checkState == false) {canContinue = false;}
|
nicholas@2310
|
526 break;
|
nickjillings@1345
|
527 default:
|
nickjillings@1345
|
528 console.log("WARNING - Check option "+checks[i].check+" is not supported on this interface");
|
nickjillings@1345
|
529 break;
|
nickjillings@1345
|
530 }
|
nickjillings@1345
|
531
|
nickjillings@1345
|
532 }
|
nickjillings@1345
|
533 if (!canContinue) {break;}
|
nickjillings@1345
|
534 }
|
nickjillings@1345
|
535
|
nickjillings@1345
|
536 if (canContinue) {
|
nickjillings@1345
|
537 if (audioEngineContext.status == 1) {
|
nickjillings@1345
|
538 var playback = document.getElementById('playback-button');
|
nickjillings@1345
|
539 playback.click();
|
nickjillings@1345
|
540 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nickjillings@1345
|
541 } else
|
nickjillings@1345
|
542 {
|
nickjillings@1345
|
543 if (audioEngineContext.timer.testStarted == false)
|
nickjillings@1345
|
544 {
|
nicholas@2362
|
545 interfaceContext.lightbox.post("Warning",'You have not started the test! Please press start to begin the test!');
|
nickjillings@1345
|
546 return;
|
nickjillings@1345
|
547 }
|
nickjillings@1345
|
548 }
|
nickjillings@1345
|
549 testState.advanceState();
|
nickjillings@1345
|
550 }
|
nickjillings@1345
|
551 }
|
nickjillings@1345
|
552
|
nickjillings@1345
|
553 function pageXMLSave(store, pageSpecification)
|
nickjillings@1345
|
554 {
|
nickjillings@1345
|
555 // MANDATORY
|
nickjillings@1345
|
556 // Saves a specific test page
|
nickjillings@1345
|
557 // You can use this space to add any extra nodes to your XML <audioHolder> saves
|
nickjillings@1345
|
558 // Get the current <page> information in store (remember to appendChild your data to it)
|
nickjillings@1345
|
559 // pageSpecification is the current page node configuration
|
nickjillings@1345
|
560 // To create new XML nodes, use storage.document.createElement();
|
nickjillings@1345
|
561 } |