annotate interfaces/discrete.js @ 3007:37923d45f298

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