annotate interfaces/mushra.js @ 2921:b08ccdb5cb8f

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