annotate interfaces/mushra.js @ 1295:ba8c8c7f1de5

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