annotate interfaces/mushra.js @ 2470:1647bb807186

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