annotate interfaces/discrete.js @ 1096:9820063ea96a

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