annotate interfaces/mushra.js @ 3141:335bc77627e0 tip

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