annotate interfaces/horizontal-sliders.js @ 2113:d2abe3b139d2

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