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