annotate interfaces/ABX.js @ 2695:211364181d16

JSHint ABX (#180)
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Sat, 11 Mar 2017 18:38:12 +0000
parents 22efb2d04bc9
children 536cb44c7292
rev   line source
nickjillings@2161 1 /**
nickjillings@2161 2 * WAET Blank Template
nickjillings@2161 3 * Use this to start building your custom interface
nickjillings@2161 4 */
nickjillings@2161 5
nickjillings@2161 6 // Once this is loaded and parsed, begin execution
n@2695 7 /* globals interfaceContext, Interface, testState, audioEngineContext, console, document, window, feedbackHolder, $, specification, storage*/
nickjillings@2161 8 loadInterface();
nickjillings@2161 9
nickjillings@2161 10 function loadInterface() {
nicholas@2538 11 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects,
nicholas@2538 12 // holding div's, or setting up any nodes which are present for the entire test sequence
nicholas@2538 13
nicholas@2381 14 interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema
nicholas@2538 15
nicholas@2538 16 Interface.prototype.checkScaleRange = function (min, max) {
nicholas@2359 17 var page = testState.getCurrentTestPage();
nicholas@2359 18 var audioObjects = audioEngineContext.audioObjects;
nicholas@2359 19 var state = true;
nicholas@2359 20 var str = "Please keep listening. ";
nicholas@2359 21 var minRanking = Infinity;
nicholas@2359 22 var maxRanking = -Infinity;
nicholas@2359 23 for (var ao of audioObjects) {
nicholas@2359 24 var rank = ao.interfaceDOM.getValue();
nicholas@2538 25 if (rank < minRanking) {
nicholas@2538 26 minRanking = rank;
nicholas@2538 27 }
nicholas@2538 28 if (rank > maxRanking) {
nicholas@2538 29 maxRanking = rank;
nicholas@2538 30 }
nicholas@2359 31 }
nicholas@2538 32 if (maxRanking * 100 < max) {
n@2695 33 str += "At least one fragment must be selected.";
nicholas@2359 34 state = false;
nicholas@2359 35 }
nicholas@2359 36 if (!state) {
nicholas@2359 37 console.log(str);
nicholas@2359 38 this.storeErrorNode(str);
nicholas@2538 39 interfaceContext.lightbox.post("Message", str);
nicholas@2359 40 }
nicholas@2359 41 return state;
n@2695 42 };
nicholas@2538 43
nickjillings@2161 44 // Custom comparator Object
nicholas@2538 45 Interface.prototype.comparator = null;
nicholas@2538 46
nickjillings@2161 47 // The injection point into the HTML page
nicholas@2538 48 interfaceContext.insertPoint = document.getElementById("topLevelBody");
nicholas@2538 49 var testContent = document.createElement('div');
nicholas@2538 50 testContent.id = 'testContent';
nicholas@2538 51
nickjillings@2161 52 // Create the top div for the Title element
nicholas@2538 53 var titleAttr = specification.title;
nicholas@2538 54 var title = document.createElement('div');
nicholas@2538 55 title.className = "title";
nicholas@2538 56 title.align = "center";
nicholas@2538 57 var titleSpan = document.createElement('span');
nicholas@2470 58 titleSpan.id = "test-title";
nicholas@2538 59
nickjillings@2161 60 // Set title to that defined in XML, else set to default
n@2695 61 if (titleAttr !== undefined) {
nicholas@2538 62 titleSpan.textContent = titleAttr;
nicholas@2538 63 } else {
nicholas@2538 64 titleSpan.textContent = 'Listening test';
nicholas@2538 65 }
nicholas@2538 66 // Insert the titleSpan element into the title div element.
nicholas@2538 67 title.appendChild(titleSpan);
nicholas@2538 68
nickjillings@2161 69 var pagetitle = document.createElement('div');
nicholas@2538 70 pagetitle.className = "pageTitle";
nicholas@2538 71 pagetitle.align = "center";
n@2695 72
n@2695 73 titleSpan = document.createElement('span');
nicholas@2538 74 titleSpan.id = "pageTitle";
nicholas@2538 75 pagetitle.appendChild(titleSpan);
nicholas@2538 76
nicholas@2538 77 // Create Interface buttons!
nicholas@2538 78 var interfaceButtons = document.createElement('div');
nicholas@2538 79 interfaceButtons.id = 'interface-buttons';
nicholas@2538 80 interfaceButtons.style.height = '25px';
nicholas@2538 81
nicholas@2538 82 // Create playback start/stop points
nicholas@2538 83 var playback = document.createElement("button");
nicholas@2538 84 playback.innerHTML = 'Stop';
nicholas@2538 85 playback.id = 'playback-button';
nicholas@2538 86 playback.style.float = 'left';
nicholas@2538 87 // onclick function. Check if it is playing or not, call the correct function in the
nicholas@2538 88 // audioEngine, change the button text to reflect the next state.
nicholas@2538 89 playback.onclick = function () {
nicholas@2538 90 if (audioEngineContext.status == 1) {
nicholas@2538 91 audioEngineContext.stop();
nicholas@2538 92 this.innerHTML = 'Stop';
nickjillings@2161 93 var time = audioEngineContext.timer.getTestTime();
nickjillings@2161 94 console.log('Stopped at ' + time); // DEBUG/SAFETY
nicholas@2538 95 }
nicholas@2538 96 };
nicholas@2538 97 // Append the interface buttons into the interfaceButtons object.
nicholas@2538 98 interfaceButtons.appendChild(playback);
nicholas@2538 99
nicholas@2538 100 // Global parent for the comment boxes on the page
nicholas@2538 101 var feedbackHolder = document.createElement('div');
nicholas@2538 102 feedbackHolder.id = 'feedbackHolder';
nicholas@2538 103
nicholas@2538 104 // Construct the AB Boxes
nicholas@2538 105 var boxes = document.createElement('div');
nicholas@2538 106 boxes.align = "center";
nicholas@2538 107 boxes.id = "box-holders";
nickjillings@2161 108 boxes.style.float = "left";
nicholas@2538 109
nicholas@2538 110 var submit = document.createElement('button');
nicholas@2538 111 submit.id = "submit";
nicholas@2538 112 submit.onclick = buttonSubmitClick;
nicholas@2538 113 submit.className = "big-button";
nicholas@2538 114 submit.textContent = "submit";
nicholas@2538 115 submit.style.position = "relative";
nicholas@2538 116 submit.style.left = (window.innerWidth - 250) / 2 + 'px';
nicholas@2538 117
nicholas@2538 118 feedbackHolder.appendChild(boxes);
nicholas@2538 119
nicholas@2475 120 // Create holder for comment boxes
nicholas@2475 121 var comments = document.createElement("div");
nicholas@2475 122 comments.id = "comment-box-holder";
nicholas@2538 123
nicholas@2538 124 // Inject into HTML
nicholas@2538 125 testContent.appendChild(title); // Insert the title
nicholas@2538 126 testContent.appendChild(pagetitle);
nicholas@2538 127 testContent.appendChild(interfaceButtons);
nicholas@2538 128 testContent.appendChild(feedbackHolder);
nicholas@2538 129 testContent.appendChild(submit);
nicholas@2475 130 testContent.appendChild(comments);
nicholas@2538 131 interfaceContext.insertPoint.appendChild(testContent);
nickjillings@2161 132
nicholas@2538 133 // Load the full interface
nicholas@2538 134 testState.initialise();
nicholas@2538 135 testState.advanceState();
n@2695 136 }
nickjillings@2161 137
nicholas@2538 138 function loadTest(page) {
nicholas@2538 139 // Called each time a new test page is to be build. The page specification node is the only item passed in
nicholas@2381 140 document.getElementById('box-holders').innerHTML = "";
nicholas@2538 141
nicholas@2651 142 var interfaceObj = interfaceContext.getCombinedInterfaces(page);
nicholas@2538 143 if (interfaceObj.length > 1) {
nicholas@2538 144 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
nicholas@2538 145 }
nicholas@2538 146 interfaceObj = interfaceObj[0];
nicholas@2538 147
nicholas@2475 148 var commentHolder = document.getElementById("comment-box-holder");
nicholas@2475 149 commentHolder.innerHTML = "";
nicholas@2538 150
nicholas@2470 151 // Set the page title
nicholas@2470 152 if (typeof page.title == "string" && page.title.length > 0) {
n@2695 153 document.getElementById("test-title").textContent = page.title;
nicholas@2470 154 }
nicholas@2538 155
n@2695 156 if (interfaceObj.title !== null) {
nicholas@2538 157 document.getElementById("pageTitle").textContent = interfaceObj.title;
nicholas@2538 158 }
nicholas@2538 159
nicholas@2469 160 interfaceContext.comparator = new comparator(page);
nicholas@2538 161
nicholas@2651 162 var interfaceOptions = interfaceObj.options;
nicholas@2538 163 for (var option of interfaceOptions) {
nicholas@2538 164 if (option.type == "show") {
nicholas@2538 165 switch (option.name) {
nickjillings@2163 166 case "playhead":
nickjillings@2163 167 var playbackHolder = document.getElementById('playback-holder');
n@2695 168 if (playbackHolder === null) {
nickjillings@2163 169 playbackHolder = document.createElement('div');
nickjillings@2163 170 playbackHolder.style.width = "100%";
nickjillings@2163 171 playbackHolder.style.float = "left";
nickjillings@2163 172 playbackHolder.align = 'center';
nickjillings@2163 173 playbackHolder.appendChild(interfaceContext.playhead.object);
nickjillings@2163 174 feedbackHolder.appendChild(playbackHolder);
nickjillings@2163 175 }
nickjillings@2163 176 break;
nickjillings@2163 177 case "page-count":
nickjillings@2163 178 var pagecountHolder = document.getElementById('page-count');
n@2695 179 if (pagecountHolder === null) {
nickjillings@2163 180 pagecountHolder = document.createElement('div');
nickjillings@2163 181 pagecountHolder.id = 'page-count';
nickjillings@2163 182 }
nicholas@2538 183 pagecountHolder.innerHTML = '<span>Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + '</span>';
nickjillings@2163 184 var inject = document.getElementById('interface-buttons');
nickjillings@2163 185 inject.appendChild(pagecountHolder);
nickjillings@2163 186 break;
nickjillings@2163 187 case "volume":
n@2695 188 if (document.getElementById('master-volume-holder') === null) {
nickjillings@2163 189 feedbackHolder.appendChild(interfaceContext.volume.object);
nickjillings@2163 190 }
nickjillings@2163 191 break;
nicholas@2469 192 case "comments":
nicholas@2469 193 // Generate one comment box per presented page
nicholas@2538 194 for (var element of audioEngineContext.audioObjects) {
nicholas@2469 195 interfaceContext.commentBoxes.createCommentBox(element);
nicholas@2469 196 }
nicholas@2538 197 interfaceContext.commentBoxes.showCommentBoxes(commentHolder, true);
nicholas@2469 198 break;
nickjillings@2163 199 }
nickjillings@2163 200 }
nickjillings@2163 201 }
nicholas@2538 202
nicholas@2538 203 $(page.commentQuestions).each(function (index, element) {
nicholas@2538 204 var node = interfaceContext.createCommentQuestion(element);
nicholas@2538 205 commentHolder.appendChild(node.holder);
nicholas@2538 206 });
nicholas@2538 207
nickjillings@2163 208 resizeWindow(null);
nickjillings@2161 209 }
nickjillings@2161 210
nicholas@2538 211 function comparator(page) {
nickjillings@2161 212 // Build prototype constructor
nicholas@2538 213 this.interfaceObject = function (element, label) {
nickjillings@2161 214 // An example node, you can make this however you want for each audioElement.
nickjillings@2161 215 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following
nickjillings@2161 216 // You attach them by calling audioObject.bindInterface( )
nickjillings@2161 217 this.parent = element;
nickjillings@2161 218 this.id = element.id;
nickjillings@2161 219 this.value = 0;
nickjillings@2161 220 this.disabled = true;
nickjillings@2161 221 this.box = document.createElement('div');
nickjillings@2161 222 this.box.className = 'comparator-holder';
nicholas@2538 223 this.box.setAttribute('track-id', element.id);
nicholas@2538 224 this.box.id = 'comparator-' + label;
nickjillings@2161 225 this.selector = document.createElement('div');
nicholas@2538 226 this.selector.className = 'comparator-selector disabled';
nicholas@2538 227 var selectorText = document.createElement('span');
nicholas@2538 228 selectorText.textContent = label;
nicholas@2538 229 this.selector.appendChild(selectorText);
nicholas@2538 230 this.playback = document.createElement('button');
nicholas@2538 231 this.playback.className = 'comparator-button';
nicholas@2538 232 this.playback.disabled = true;
nicholas@2538 233 this.playback.textContent = "Listen";
nicholas@2538 234 this.box.appendChild(this.selector);
nicholas@2538 235 this.box.appendChild(this.playback);
n@2695 236 this.selectorClicked = function (event) {
nicholas@2538 237 if (label == "X" || label == "x") {
nicholas@2538 238 return;
nickjillings@2161 239 }
nicholas@2538 240 var time = audioEngineContext.timer.getTestTime();
n@2695 241 if (this.disabled) {
n@2695 242 interfaceContext.lightbox.post("Message", "Please wait until sample has loaded");
nicholas@2538 243 console.log("Please wait until sample has loaded");
nicholas@2538 244 return;
nicholas@2538 245 }
n@2695 246 if (audioEngineContext.status === 0) {
nicholas@2538 247 interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection");
nicholas@2538 248 console.log("Please listen to the samples before making a selection");
nicholas@2538 249 return;
nicholas@2538 250 }
n@2695 251 interfaceContext.comparator.selected = this.id;
n@2695 252 $(".comparator-selector").removeClass('selected');
n@2695 253 $(this.selector).addClass('selected');
n@2695 254 interfaceContext.comparator.pair.forEach(function (obj) {
n@2695 255 obj.value = 1.0 * obj === this;
n@2695 256 obj.parent.metric.moved(time, obj.value);
n@2695 257 });
n@2695 258 console.log("Selected " + this.id + ' (' + time + ')');
nicholas@2538 259 };
nicholas@2538 260 this.playback.setAttribute("playstate", "ready");
n@2695 261 this.playbackClicked = function (event) {
n@2695 262 if (this.playback.getAttribute("playstate") == "ready") {
n@2695 263 audioEngineContext.play(this.id);
nickjillings@2161 264 } else if (event.currentTarget.getAttribute("playstate") == "playing") {
nickjillings@2161 265 audioEngineContext.stop();
nickjillings@2161 266 }
nicholas@2538 267
nicholas@2538 268 };
n@2695 269 this.handleEvent = function (event) {
n@2695 270 if (event.currentTarget === this.playback) {
n@2695 271 this.playbackClicked(event);
n@2695 272 } else if (event.currentTarget === this.selector) {
n@2695 273 this.selectorClicked(event);
n@2695 274 }
n@2695 275 };
n@2695 276 this.playback.addEventListener("click", this);
n@2695 277 this.selector.addEventListener("click", this);
nicholas@2538 278 this.enable = function () {
nickjillings@2161 279 // This is used to tell the interface object that playback of this node is ready
nicholas@2538 280 if (this.parent.state == 1) {
nicholas@2538 281 $(this.selector).removeClass('disabled');
nicholas@2538 282 this.playback.disabled = false;
n@2695 283 this.disabled = false;
nicholas@2538 284 }
nickjillings@2161 285 };
nicholas@2538 286 this.updateLoading = function (progress) {
nickjillings@2161 287 // progress is a value from 0 to 100 indicating the current download state of media files
nicholas@2538 288 if (progress != 100) {
nicholas@2538 289 progress = String(progress);
nicholas@2538 290 progress = progress.split('.')[0];
nicholas@2538 291 this.playback.textContent = progress + '%';
nicholas@2538 292 } else {
nicholas@2538 293 this.playback.textContent = "Play";
nicholas@2538 294 }
nickjillings@2161 295 };
nicholas@2538 296 this.error = function () {
nickjillings@2161 297 // audioObject has an error!!
nickjillings@2161 298 this.playback.textContent = "Error";
nickjillings@2161 299 $(this.playback).addClass("error-colour");
nickjillings@2161 300 };
nicholas@2538 301 this.startPlayback = function () {
n@2428 302 if (this.parent.specification.parent.playOne || specification.playOne) {
n@2428 303 $('.comparator-button').text('Wait');
nicholas@2538 304 $('.comparator-button').attr("disabled", "true");
nicholas@2503 305 $(this.playback).removeAttr("disabled");
n@2428 306 } else {
n@2428 307 $('.comparator-button').text('Listen');
n@2428 308 }
nickjillings@2161 309 $(this.playback).text('Stop');
nicholas@2538 310 this.playback.setAttribute("playstate", "playing");
nickjillings@2161 311 };
nicholas@2538 312 this.stopPlayback = function () {
n@2428 313 if (this.playback.getAttribute("playstate") == "playing") {
n@2428 314 $('.comparator-button').text('Listen');
n@2428 315 $('.comparator-button').removeAttr("disabled");
nicholas@2538 316 this.playback.setAttribute("playstate", "ready");
n@2428 317 }
nickjillings@2161 318 };
nicholas@2538 319 this.getValue = function () {
nickjillings@2161 320 // Return the current value of the object. If there is no value, return 0
nickjillings@2161 321 return this.value;
nickjillings@2161 322 };
nicholas@2538 323 this.getPresentedId = function () {
nickjillings@2161 324 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale
nickjillings@2161 325 return this.selector.children[0].textContent;
nickjillings@2161 326 };
nicholas@2538 327 this.canMove = function () {
nickjillings@2161 328 // 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@2161 329 // These are checked primarily if the interface check option 'fragmentMoved' is enabled.
nickjillings@2161 330 return false;
nickjillings@2161 331 };
nicholas@2538 332 this.exportXMLDOM = function (audioObject) {
nickjillings@2161 333 // Called by the audioObject holding this element to export the interface <value> node.
nickjillings@2161 334 // If there is no value node (such as outside reference), return null
nickjillings@2161 335 // 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@2161 336 // Use storage.document.createElement('value'); to generate the XML node.
nickjillings@2161 337 var node = storage.document.createElement('value');
nicholas@2538 338 node.textContent = this.value;
nicholas@2538 339 return node;
nickjillings@2161 340
nickjillings@2161 341 };
nicholas@2538 342 this.error = function () {
nickjillings@2161 343 // If there is an error with the audioObject, this will be called to indicate a failure
n@2695 344 };
nickjillings@2161 345 };
nickjillings@2161 346 // Ensure there are only two comparisons per page
nickjillings@2161 347 if (page.audioElements.length != 2) {
nicholas@2538 348 console.error('FATAL - There must be 2 <audioelement> nodes on each <page>: ' + page.id);
nickjillings@2161 349 return;
nickjillings@2161 350 }
nickjillings@2161 351 // Build the three audio elements
n@2695 352
n@2695 353 function buildElement(index, audioObject) {
n@2695 354 var label;
n@2695 355 switch (index) {
n@2695 356 case 0:
n@2695 357 label = "A";
n@2695 358 break;
n@2695 359 case 1:
n@2695 360 label = "B";
n@2695 361 break;
n@2695 362 default:
n@2695 363 label = "X";
n@2695 364 break;
n@2695 365 }
n@2695 366 var node = new this.interfaceObject(audioObject, label);
n@2695 367 audioObject.bindInterface(node);
n@2695 368 return node;
n@2695 369 }
n@2695 370
nickjillings@2161 371 this.pair = [];
nickjillings@2161 372 this.X = null;
nickjillings@2161 373 this.boxHolders = document.getElementById('box-holders');
n@2695 374 var node;
n@2695 375 page.audioElements.forEach(function (element, index) {
nicholas@2538 376 if (element.type != 'normal') {
nicholas@2538 377 console.log("WARNING - ABX can only have normal elements. Page " + page.id + ", Element " + element.id);
nickjillings@2161 378 element.type = "normal";
nicholas@2538 379 }
n@2695 380 node = buildElement.call(this, index, audioEngineContext.newTrack(element));
nickjillings@2161 381 this.pair.push(node);
nickjillings@2161 382 this.boxHolders.appendChild(node.box);
n@2695 383 }, this);
nickjillings@2161 384 var elementId = Math.floor(Math.random() * 2); //Randomly pick A or B to be X
giuliomoro@2291 385 var element = new page.audioElementNode(specification);
nickjillings@2161 386 for (var atr in page.audioElements[elementId]) {
n@2695 387 element[atr] = page.audioElements[elementId][atr];
nickjillings@2161 388 }
nickjillings@2161 389 element.id += "-X";
nicholas@2538 390 if (typeof element.name == "string") {
nicholas@2538 391 element.name += "-X";
nicholas@2538 392 }
nickjillings@2161 393 page.audioElements.push(element);
nickjillings@2161 394 // Create the save place-holder for the 'X' element
nickjillings@2161 395 var root = testState.currentStore.XMLDOM;
nickjillings@2161 396 var aeNode = storage.document.createElement('audioelement');
nicholas@2538 397 aeNode.setAttribute('ref', element.id);
nicholas@2538 398 if (typeof element.name == "string") {
nicholas@2538 399 aeNode.setAttribute('name', element.name);
nicholas@2538 400 }
nicholas@2538 401 aeNode.setAttribute('type', 'normal');
nicholas@2538 402 aeNode.setAttribute('url', element.url);
nicholas@2538 403 aeNode.setAttribute('gain', element.gain);
nickjillings@2161 404 aeNode.appendChild(storage.document.createElement('metric'));
nickjillings@2161 405 root.appendChild(aeNode);
nickjillings@2161 406 // Build the 'X' element
n@2695 407 var label;
nickjillings@2161 408 var audioObject = audioEngineContext.newTrack(element);
n@2695 409 node = buildElement.call(this, 3, audioObject);
giuliomoro@2305 410 node.box.children[0].classList.add('inactive');
nickjillings@2161 411 audioObject.bindInterface(node);
nickjillings@2161 412 this.X = node;
nickjillings@2161 413 this.boxHolders.appendChild(node.box);
nickjillings@2161 414 }
nickjillings@2161 415
nicholas@2538 416 function resizeWindow(event) {
nicholas@2538 417 document.getElementById('submit').style.left = (window.innerWidth - 250) / 2 + 'px';
nicholas@2538 418 var numObj = 3;
nicholas@2538 419 var boxW = numObj * 312;
nickjillings@2163 420 var diff = window.innerWidth - boxW;
nicholas@2538 421 while (diff < 0) {
nicholas@2538 422 numObj = Math.ceil(numObj / 2);
nicholas@2538 423 boxW = numObj * 312;
nickjillings@2163 424 diff = window.innerWidth - boxW;
nickjillings@2163 425 }
nicholas@2538 426 document.getElementById('box-holders').style.marginLeft = diff / 2 + 'px';
nicholas@2538 427 document.getElementById('box-holders').style.marginRight = diff / 2 + 'px';
nickjillings@2163 428 document.getElementById('box-holders').style.width = boxW + 'px';
nickjillings@2161 429 }
nickjillings@2161 430
nicholas@2538 431 function buttonSubmitClick() {
nicholas@2651 432 var checks = testState.currentStateMap.interfaces[0].options,
nicholas@2651 433 canContinue = true;
nickjillings@2163 434
nicholas@2538 435 for (var i = 0; i < checks.length; i++) {
n@2695 436 var checkState;
nicholas@2538 437 if (checks[i].type == 'check') {
nicholas@2538 438 switch (checks[i].name) {
nicholas@2538 439 case 'fragmentPlayed':
nicholas@2538 440 // Check if all fragments have been played
n@2695 441 checkState = interfaceContext.checkAllPlayed();
n@2695 442 if (checkState === false) {
nicholas@2538 443 canContinue = false;
nicholas@2538 444 }
nicholas@2538 445 break;
nicholas@2538 446 case 'fragmentFullPlayback':
nicholas@2538 447 // Check all fragments have been played to their full length
n@2695 448 checkState = interfaceContext.checkFragmentsFullyPlayed();
n@2695 449 if (checkState === false) {
nicholas@2538 450 canContinue = false;
nicholas@2538 451 }
nicholas@2538 452 break;
nicholas@2538 453 case 'fragmentMoved':
nicholas@2538 454 // Check all fragment sliders have been moved.
n@2695 455 checkState = interfaceContext.checkAllMoved();
n@2695 456 if (checkState === false) {
nicholas@2538 457 canContinue = false;
nicholas@2538 458 }
nicholas@2538 459 break;
nicholas@2538 460 case 'fragmentComments':
nicholas@2538 461 // Check all fragment sliders have been moved.
n@2695 462 checkState = interfaceContext.checkAllCommented();
n@2695 463 if (checkState === false) {
nicholas@2538 464 canContinue = false;
nicholas@2538 465 }
nicholas@2538 466 break;
nicholas@2538 467 case 'scalerange':
nicholas@2538 468 // Check the scale has been used effectively
n@2695 469 checkState = interfaceContext.checkScaleRange(checks[i].min, checks[i].max);
n@2695 470 if (checkState === false) {
nicholas@2538 471 canContinue = false;
nicholas@2538 472 }
nicholas@2538 473 break;
nicholas@2538 474 default:
nicholas@2538 475 console.log("WARNING - Check option " + checks[i].check + " is not supported on this interface");
nicholas@2538 476 break;
nicholas@2538 477 }
nicholas@2538 478
nicholas@2538 479 }
nicholas@2538 480 if (!canContinue) {
nicholas@2538 481 break;
nicholas@2538 482 }
nicholas@2538 483 }
nicholas@2538 484 if (canContinue) {
nicholas@2538 485 if (audioEngineContext.status == 1) {
nicholas@2538 486 var playback = document.getElementById('playback-button');
nicholas@2538 487 playback.click();
nicholas@2538 488 // 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 489 } else {
n@2695 490 if (audioEngineContext.timer.testStarted === false) {
nicholas@2538 491 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please listen to a sample to begin the test!');
nicholas@2538 492 return;
nicholas@2538 493 }
nicholas@2538 494 }
nicholas@2538 495 testState.advanceState();
nicholas@2538 496 }
nickjillings@2161 497 }
nickjillings@2161 498
nicholas@2538 499 function pageXMLSave(store, pageSpecification) {
nicholas@2538 500 // MANDATORY
nicholas@2538 501 // Saves a specific test page
nicholas@2538 502 // You can use this space to add any extra nodes to your XML <audioHolder> saves
nicholas@2538 503 // Get the current <page> information in store (remember to appendChild your data to it)
nicholas@2538 504 // pageSpecification is the current page node configuration
nicholas@2538 505 // To create new XML nodes, use storage.document.createElement();
nicholas@2538 506 }