annotate interfaces/mushra.js @ 2438:02df8de58e7b

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