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