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