annotate ape.js @ 399:fc97a9e519ac Dev_main

Bug #1486 fix. APE scale check tells the user which axis has not met the user axis criteria.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 11 Dec 2015 16:24:44 +0000
parents b127506a3f49
children 502f22d1dbc3
rev   line source
nicholas@2 1 /**
nicholas@2 2 * ape.js
nicholas@2 3 * Create the APE interface
nicholas@2 4 */
nicholas@2 5
n@32 6
nicholas@2 7 // Once this is loaded and parsed, begin execution
n@181 8 loadInterface();
nicholas@2 9
n@181 10 function loadInterface() {
nicholas@2 11
n@16 12 // Get the dimensions of the screen available to the page
nicholas@2 13 var width = window.innerWidth;
nicholas@2 14 var height = window.innerHeight;
nicholas@2 15
nicholas@2 16 // The injection point into the HTML page
n@182 17 interfaceContext.insertPoint = document.getElementById("topLevelBody");
n@22 18 var testContent = document.createElement('div');
nicholas@135 19
n@22 20 testContent.id = 'testContent';
n@52 21
nicholas@214 22 // Bindings for interfaceContext
nicholas@214 23 Interface.prototype.checkAllPlayed = function()
nicholas@214 24 {
nicholas@214 25 hasBeenPlayed = audioEngineContext.checkAllPlayed();
nicholas@214 26 if (hasBeenPlayed.length > 0) // if a fragment has not been played yet
nicholas@214 27 {
nicholas@214 28 str = "";
nicholas@214 29 if (hasBeenPlayed.length > 1) {
nicholas@214 30 for (var i=0; i<hasBeenPlayed.length; i++) {
nicholas@214 31 str = str + hasBeenPlayed[i];
nicholas@214 32 if (i < hasBeenPlayed.length-2){
nicholas@214 33 str += ", ";
nicholas@214 34 } else if (i == hasBeenPlayed.length-2) {
nicholas@214 35 str += " or ";
nicholas@214 36 }
nicholas@214 37 }
nicholas@214 38 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
nicholas@214 39 } else {
nicholas@214 40 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
nicholas@214 41 }
nicholas@214 42 return false;
nicholas@214 43 }
nicholas@214 44 return true;
nicholas@219 45 };
nicholas@214 46
nicholas@214 47 Interface.prototype.checkAllMoved = function() {
nicholas@214 48 var state = true;
n@398 49 var str = 'You have not moved the following sliders. ';
n@398 50 for (var i=0; i<this.interfaceSliders.length; i++)
nicholas@214 51 {
n@398 52 var interfaceTID = [];
n@398 53 for (var j=0; j<this.interfaceSliders[i].metrics.length; j++)
n@398 54 {
n@398 55 if (this.interfaceSliders[i].metrics[j].wasMoved == false)
n@398 56 {
n@398 57 state = false;
n@398 58 interfaceTID.push(j);
n@398 59 }
n@398 60 }
n@398 61 if (interfaceTID.length != 0)
n@398 62 {
n@398 63 str += 'On axis "'+this.interfaceSliders[i].interfaceObject.title+'" you must move ';
n@398 64 if (interfaceTID.length == 1)
n@398 65 {
n@398 66 str += 'slider +'+interfaceTID[0]+'. ';
n@398 67 }
n@398 68 else {
n@398 69 str += 'sliders ';
n@398 70 for (var k=0; k<interfaceTID.length-1; k++)
n@398 71 {
n@398 72 str += interfaceTID[k]+', ';
n@398 73 }
n@398 74 str += interfaceTID[interfaceTID.length-1] +'. ';
n@398 75 }
nicholas@214 76 }
nicholas@214 77 }
n@398 78 if (state != true)
n@398 79 {
n@398 80 alert(str);
n@398 81 console.log(str);
nicholas@214 82 }
nicholas@214 83 return state;
nicholas@219 84 };
nicholas@214 85
nicholas@214 86 Interface.prototype.checkAllCommented = function() {
nicholas@214 87 var audioObjs = audioEngineContext.audioObjects;
nicholas@214 88 var audioHolder = testState.stateMap[testState.stateIndex];
nicholas@214 89 var state = true;
nicholas@214 90 if (audioHolder.elementComments) {
nicholas@214 91 var strNums = [];
nicholas@214 92 for (var i=0; i<audioObjs.length; i++)
nicholas@214 93 {
nicholas@214 94 if (audioObjs[i].commentDOM.trackCommentBox.value.length == 0) {
nicholas@214 95 state = false;
nicholas@214 96 strNums.push(i);
nicholas@214 97 }
nicholas@214 98 }
nicholas@214 99 if (state == false) {
nicholas@214 100 if (strNums.length > 1) {
nicholas@214 101 var str = "";
nicholas@214 102 for (var i=0; i<strNums.length; i++) {
nicholas@214 103 str = str + strNums[i];
nicholas@214 104 if (i < strNums.length-2){
nicholas@214 105 str += ", ";
nicholas@214 106 } else if (i == strNums.length-2) {
nicholas@214 107 str += " or ";
nicholas@214 108 }
nicholas@214 109 }
nicholas@214 110 alert('You have not commented on fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
nicholas@214 111 } else {
nicholas@214 112 alert('You have not commented on fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
nicholas@214 113 }
nicholas@214 114 }
nicholas@214 115 }
nicholas@214 116 return state;
nicholas@219 117 };
nicholas@214 118
nicholas@231 119 Interface.prototype.checkScaleRange = function()
nicholas@231 120 {
nicholas@231 121 var audioObjs = audioEngineContext.audioObjects;
nicholas@231 122 var audioHolder = testState.stateMap[testState.stateIndex];
n@399 123 var state = true;
n@399 124 var str = '';
n@399 125 for (var i=0; i<this.interfaceSliders.length; i++)
nicholas@231 126 {
n@383 127 var minScale;
n@383 128 var maxScale;
n@399 129 var interfaceObject = interfaceContext.interfaceSliders[0].interfaceObject;
n@399 130 for (var j=0; j<interfaceObject.options.length; j++)
n@383 131 {
n@399 132 if (interfaceObject.options[j].check == "scalerange") {
n@399 133 minScale = interfaceObject.options[j].min;
n@399 134 maxScale = interfaceObject.options[j].max;
n@383 135 break;
n@383 136 }
n@383 137 }
n@399 138 var minRanking = convSliderPosToRate(this.interfaceSliders[i].sliders[0]);
n@399 139 var maxRanking = minRanking;
n@399 140 for (var j=1; j<this.interfaceSliders[i].sliders.length; j++)
n@399 141 {
n@399 142 var ranking = convSliderPosToRate(this.interfaceSliders[i].sliders[j]);
n@399 143 if (ranking < minRanking)
n@399 144 {
n@399 145 minRanking = ranking;
n@399 146 } else if (ranking > maxRanking)
n@399 147 {
n@399 148 maxRanking = ranking;
n@383 149 }
n@383 150 }
n@399 151 if (minRanking > minScale || maxRanking < maxScale)
n@399 152 {
n@399 153 state = false;
n@399 154 str += 'On axis "'+this.interfaceSliders[i].interfaceObject.title+'" you have not used the full width of the scale. ';
nicholas@231 155 }
nicholas@231 156 }
n@399 157 if (state != true)
n@399 158 {
n@399 159 alert(str);
n@399 160 console.log(str);
n@399 161 }
n@399 162 return state;
nicholas@231 163 };
nicholas@231 164
n@360 165 Interface.prototype.objectSelected = null;
n@360 166 Interface.prototype.objectMoved = false;
n@360 167 Interface.prototype.selectObject = function(object)
n@360 168 {
n@360 169 if (this.objectSelected == null)
n@360 170 {
n@360 171 this.objectSelected = object;
n@360 172 this.objectMoved = false;
n@360 173 }
n@360 174 };
n@360 175 Interface.prototype.moveObject = function()
n@360 176 {
n@360 177 if (this.objectMoved == false)
n@360 178 {
n@360 179 this.objectMoved = true;
n@360 180 }
n@360 181 };
n@360 182 Interface.prototype.releaseObject = function()
n@360 183 {
n@360 184 this.objectSelected = null;
n@360 185 this.objectMoved = false;
n@360 186 };
n@360 187 Interface.prototype.getSelectedObject = function()
n@360 188 {
n@360 189 return this.objectSelected;
n@360 190 };
n@360 191 Interface.prototype.hasSelectedObjectMoved = function()
n@360 192 {
n@360 193 return this.objectMoved;
n@360 194 };
n@360 195
nicholas@391 196 // Bindings for slider interfaces
nicholas@391 197 Interface.prototype.interfaceSliders = [];
nicholas@391 198
n@177 199 // Bindings for audioObjects
n@177 200
nicholas@2 201 // Create the top div for the Title element
n@181 202 var titleAttr = specification.title;
nicholas@2 203 var title = document.createElement('div');
nicholas@2 204 title.className = "title";
nicholas@2 205 title.align = "center";
nicholas@2 206 var titleSpan = document.createElement('span');
nicholas@2 207
nicholas@2 208 // Set title to that defined in XML, else set to default
nicholas@2 209 if (titleAttr != undefined) {
n@181 210 titleSpan.textContent = titleAttr;
nicholas@2 211 } else {
n@181 212 titleSpan.textContent = 'Listening test';
nicholas@2 213 }
nicholas@2 214 // Insert the titleSpan element into the title div element.
nicholas@2 215 title.appendChild(titleSpan);
nicholas@2 216
nicholas@7 217 // Create Interface buttons!
nicholas@7 218 var interfaceButtons = document.createElement('div');
nicholas@7 219 interfaceButtons.id = 'interface-buttons';
nicholas@7 220
nicholas@7 221 // Create playback start/stop points
nicholas@7 222 var playback = document.createElement("button");
b@101 223 playback.innerHTML = 'Stop';
n@49 224 playback.id = 'playback-button';
n@16 225 // onclick function. Check if it is playing or not, call the correct function in the
n@16 226 // audioEngine, change the button text to reflect the next state.
nicholas@7 227 playback.onclick = function() {
b@101 228 if (audioEngineContext.status == 1) {
b@101 229 audioEngineContext.stop();
n@25 230 this.innerHTML = 'Stop';
b@115 231 var time = audioEngineContext.timer.getTestTime();
b@115 232 console.log('Stopped at ' + time); // DEBUG/SAFETY
nicholas@7 233 }
n@16 234 };
nicholas@7 235 // Create Submit (save) button
nicholas@7 236 var submit = document.createElement("button");
n@25 237 submit.innerHTML = 'Submit';
n@43 238 submit.onclick = buttonSubmitClick;
n@49 239 submit.id = 'submit-button';
n@16 240 // Append the interface buttons into the interfaceButtons object.
nicholas@7 241 interfaceButtons.appendChild(playback);
nicholas@7 242 interfaceButtons.appendChild(submit);
nicholas@7 243
n@383 244 var sliderHolder = document.createElement("div");
n@383 245 sliderHolder.id = "slider-holder";
nicholas@2 246
n@47 247
n@16 248 // Global parent for the comment boxes on the page
nicholas@3 249 var feedbackHolder = document.createElement('div');
n@34 250 feedbackHolder.id = 'feedbackHolder';
nicholas@2 251
n@38 252 testContent.style.zIndex = 1;
n@182 253 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
n@38 254
n@38 255 // Inject into HTML
n@38 256 testContent.appendChild(title); // Insert the title
n@38 257 testContent.appendChild(interfaceButtons);
n@383 258 testContent.appendChild(sliderHolder);
n@38 259 testContent.appendChild(feedbackHolder);
n@182 260 interfaceContext.insertPoint.appendChild(testContent);
n@22 261
n@36 262 // Load the full interface
nicholas@129 263 testState.initialise();
nicholas@129 264 testState.advanceState();
nicholas@135 265
nicholas@2 266 }
nicholas@5 267
n@181 268 function loadTest(audioHolderObject)
n@34 269 {
n@383 270 var width = window.innerWidth;
n@383 271 var height = window.innerHeight;
n@181 272 var id = audioHolderObject.id;
n@34 273
nicholas@391 274 interfaceContext.interfaceSliders = [];
nicholas@391 275
n@34 276 var feedbackHolder = document.getElementById('feedbackHolder');
n@383 277 var sliderHolder = document.getElementById('slider-holder');
n@34 278 feedbackHolder.innerHTML = null;
n@383 279 sliderHolder.innerHTML = null;
n@47 280
nicholas@256 281 var interfaceObj = audioHolderObject.interfaces;
nicholas@256 282 for (var k=0; k<interfaceObj.length; k++) {
n@383 283 // Create the div box to center align
nicholas@391 284 interfaceContext.interfaceSliders.push(new interfaceSliderHolder(interfaceObj[k]));
nicholas@256 285 for (var i=0; i<interfaceObj[k].options.length; i++)
nicholas@256 286 {
nicholas@256 287 if (interfaceObj[k].options[i].type == 'option' && interfaceObj[k].options[i].name == 'playhead')
nicholas@256 288 {
nicholas@256 289 var playbackHolder = document.getElementById('playback-holder');
nicholas@256 290 if (playbackHolder == null)
nicholas@256 291 {
nicholas@256 292 playbackHolder = document.createElement('div');
nicholas@256 293 playbackHolder.style.width = "100%";
nicholas@256 294 playbackHolder.align = 'center';
nicholas@256 295 playbackHolder.appendChild(interfaceContext.playhead.object);
nicholas@256 296 feedbackHolder.appendChild(playbackHolder);
nicholas@256 297 }
nicholas@274 298 } else if (interfaceObj[k].options[i].type == 'option' && interfaceObj[k].options[i].name == 'page-count')
nicholas@274 299 {
nicholas@274 300 var pagecountHolder = document.getElementById('page-count');
nicholas@274 301 if (pagecountHolder == null)
nicholas@274 302 {
nicholas@274 303 pagecountHolder = document.createElement('div');
nicholas@274 304 pagecountHolder.id = 'page-count';
nicholas@274 305 }
nicholas@274 306 pagecountHolder.innerHTML = '<span>Test '+(audioHolderObject.presentedId+1)+' of '+specification.audioHolders.length+'</span>';
nicholas@274 307 var inject = document.getElementById('interface-buttons');
nicholas@274 308 inject.appendChild(pagecountHolder);
nicholas@256 309 }
nicholas@256 310 }
nicholas@256 311 }
nicholas@256 312
n@184 313 var commentBoxPrefix = "Comment on track";
n@45 314
n@181 315 var commentShow = audioHolderObject.elementComments;
nicholas@66 316
n@181 317 var loopPlayback = audioHolderObject.loop;
n@181 318
n@46 319 currentTestHolder = document.createElement('audioHolder');
n@181 320 currentTestHolder.id = audioHolderObject.id;
n@181 321 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
n@46 322
n@45 323 // Find all the audioElements from the audioHolder
n@181 324 $(audioHolderObject.audioElements).each(function(index,element){
n@34 325 // Find URL of track
n@34 326 // In this jQuery loop, variable 'this' holds the current audioElement.
n@34 327
n@34 328 // Now load each audio sample. First create the new track by passing the full URL
n@181 329 var trackURL = audioHolderObject.hostURL + element.url;
n@182 330 var audioObject = audioEngineContext.newTrack(element);
nicholas@66 331
n@205 332 var node = interfaceContext.createCommentBox(audioObject);
n@34 333
n@34 334 // Create a slider per track
n@383 335 audioObject.interfaceDOM = new sliderObject(audioObject,interfaceObj);
n@396 336 audioObject.metric.initialPosition = convSliderPosToRate(audioObject.interfaceDOM.trackSliderObjects[0]);
n@379 337 if (audioObject.state == 1)
n@379 338 {
n@379 339 audioObject.interfaceDOM.enable();
n@379 340 }
b@102 341
n@34 342 });
n@358 343
n@359 344 $('.track-slider').mousedown(function(event) {
n@360 345 interfaceContext.selectObject($(this)[0]);
n@358 346 });
n@358 347
n@359 348 $('.track-slider').mousemove(function(event) {
n@359 349 event.preventDefault();
n@359 350 });
n@359 351
n@383 352 $('.slider').mousemove(function(event) {
n@358 353 event.preventDefault();
n@360 354 var obj = interfaceContext.getSelectedObject();
n@360 355 if (obj == null) {return;}
n@360 356 $(obj).css("left",event.clientX + "px");
n@360 357 interfaceContext.moveObject();
n@360 358 });
n@360 359
n@360 360 $(document).mouseup(function(event){
n@360 361 event.preventDefault();
n@360 362 var obj = interfaceContext.getSelectedObject();
n@360 363 if (obj == null) {return;}
nicholas@392 364 var interfaceID = obj.parentElement.getAttribute("interfaceid");
nicholas@392 365 var trackID = obj.getAttribute("trackindex");
n@360 366 if (interfaceContext.hasSelectedObjectMoved() == true)
n@358 367 {
n@360 368 var l = $(obj).css("left");
n@360 369 var id = obj.getAttribute('trackIndex');
n@360 370 var time = audioEngineContext.timer.getTestTime();
n@360 371 var rate = convSliderPosToRate(obj);
n@360 372 audioEngineContext.audioObjects[id].metric.moved(time,rate);
nicholas@392 373 interfaceContext.interfaceSliders[interfaceID].metrics[trackID].moved(time,rate);
n@360 374 console.log("slider "+id+" moved to "+rate+' ('+time+')');
n@360 375 } else {
n@360 376 var id = Number(obj.attributes['trackIndex'].value);
n@360 377 //audioEngineContext.metric.sliderPlayed(id);
n@360 378 audioEngineContext.play(id);
n@360 379 // Currently playing track red, rest green
n@360 380
n@360 381 $('.track-slider').removeClass('track-slider-playing');
n@383 382 var name = ".track-slider-"+obj.getAttribute("trackindex");
n@383 383 $(name).addClass('track-slider-playing');
n@360 384 $('.comment-div').removeClass('comment-box-playing');
n@360 385 $('#comment-div-'+id).addClass('comment-box-playing');
n@360 386 var outsideReference = document.getElementById('outside-reference');
n@360 387 if (outsideReference != undefined)
n@360 388 $(outsideReference).removeClass('track-slider-playing');
n@358 389 }
n@360 390 interfaceContext.releaseObject();
n@358 391 });
n@358 392
n@358 393
n@182 394 if (commentShow) {
n@182 395 interfaceContext.showCommentBoxes(feedbackHolder,true);
n@182 396 }
n@39 397
n@181 398 $(audioHolderObject.commentQuestions).each(function(index,element) {
n@193 399 var node = interfaceContext.createCommentQuestion(element);
n@193 400 feedbackHolder.appendChild(node.holder);
nicholas@65 401 });
n@153 402
nicholas@236 403 // Construct outside reference;
nicholas@236 404 if (audioHolderObject.outsideReference != null) {
nicholas@236 405 var outsideReferenceHolder = document.createElement('div');
nicholas@236 406 outsideReferenceHolder.id = 'outside-reference';
n@394 407 outsideReferenceHolder.className = 'outside-reference';
nicholas@236 408 outsideReferenceHolderspan = document.createElement('span');
nicholas@236 409 outsideReferenceHolderspan.textContent = 'Reference';
nicholas@236 410 outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
nicholas@236 411
nicholas@236 412 var audioObject = audioEngineContext.newTrack(audioHolderObject.outsideReference);
nicholas@236 413
n@299 414 outsideReferenceHolder.onclick = function(event)
nicholas@236 415 {
nicholas@236 416 audioEngineContext.play(audioEngineContext.audioObjects.length-1);
nicholas@236 417 $('.track-slider').removeClass('track-slider-playing');
nicholas@236 418 $('.comment-div').removeClass('comment-box-playing');
n@299 419 if (event.currentTarget.nodeName == 'DIV') {
n@299 420 $(event.currentTarget).addClass('track-slider-playing');
nicholas@236 421 } else {
n@299 422 $(event.currentTarget.parentElement).addClass('track-slider-playing');
nicholas@236 423 }
nicholas@236 424 };
nicholas@236 425
nicholas@236 426 document.getElementById('interface-buttons').appendChild(outsideReferenceHolder);
nicholas@236 427 }
nicholas@236 428
n@153 429
nicholas@271 430 //testWaitIndicator();
n@39 431 }
n@39 432
nicholas@391 433 function interfaceSliderHolder(interfaceObject)
nicholas@391 434 {
nicholas@391 435 this.sliders = [];
nicholas@392 436 this.metrics = [];
nicholas@391 437 this.id = document.getElementsByClassName("sliderCanvasDiv").length;
nicholas@391 438 this.name = interfaceObject.name;
nicholas@391 439 this.interfaceObject = interfaceObject;
nicholas@391 440 this.sliderDOM = document.createElement('div');
nicholas@391 441 this.sliderDOM.className = 'sliderCanvasDiv';
nicholas@391 442 this.sliderDOM.id = 'sliderCanvasHolder-'+this.id;
nicholas@391 443
nicholas@391 444 var pagetitle = document.createElement('div');
nicholas@391 445 pagetitle.className = "pageTitle";
nicholas@391 446 pagetitle.align = "center";
nicholas@391 447 var titleSpan = document.createElement('span');
nicholas@391 448 titleSpan.id = "pageTitle-"+this.id;
nicholas@391 449 if (interfaceObject.title != undefined && typeof interfaceObject.title == "string")
nicholas@391 450 {
nicholas@391 451 titleSpan.textContent = interfaceObject.title;
nicholas@391 452 }
nicholas@391 453 pagetitle.appendChild(titleSpan);
nicholas@391 454 this.sliderDOM.appendChild(pagetitle);
nicholas@391 455
nicholas@391 456 // Create the slider box to hold the slider elements
nicholas@391 457 this.canvas = document.createElement('div');
nicholas@391 458 if (this.name != undefined)
nicholas@391 459 this.canvas.id = 'slider-'+this.name;
nicholas@391 460 else
nicholas@391 461 this.canvas.id = 'slider-'+this.id;
nicholas@392 462 this.canvas.setAttribute("interfaceid",this.id);
nicholas@391 463 this.canvas.className = 'slider';
nicholas@391 464 this.canvas.align = "left";
nicholas@391 465 this.canvas.addEventListener('dragover',function(event){
nicholas@391 466 event.preventDefault();
nicholas@391 467 event.dataTransfer.effectAllowed = 'none';
nicholas@391 468 event.dataTransfer.dropEffect = 'copy';
nicholas@391 469 return false;
nicholas@391 470 },false);
nicholas@391 471 var sliderMargin = document.createAttribute('marginsize');
nicholas@391 472 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
nicholas@391 473 // Must have a known EXACT width, as this is used later to determine the ratings
nicholas@391 474 var w = (Number(sliderMargin.nodeValue)+8)*2;
nicholas@391 475 this.canvas.style.width = window.innerWidth - w +"px";
nicholas@391 476 this.canvas.style.marginLeft = sliderMargin.nodeValue +'px';
nicholas@391 477 this.canvas.setAttributeNode(sliderMargin);
nicholas@391 478 this.sliderDOM.appendChild(this.canvas);
nicholas@391 479
nicholas@391 480 // Create the div to hold any scale objects
nicholas@391 481 this.scale = document.createElement('div');
nicholas@391 482 this.scale.className = 'sliderScale';
nicholas@391 483 this.scale.id = 'sliderScaleHolder-'+this.id;
nicholas@391 484 this.scale.align = 'left';
nicholas@391 485 this.sliderDOM.appendChild(this.scale);
nicholas@391 486 var positionScale = this.canvas.style.width.substr(0,this.canvas.style.width.length-2);
nicholas@391 487 var offset = Number(this.canvas.attributes['marginsize'].value);
nicholas@391 488 for (var index=0; index<interfaceObject.scale.length; index++)
nicholas@391 489 {
nicholas@391 490 var scaleObj = interfaceObject.scale[index];
nicholas@391 491 var value = document.createAttribute('value');
nicholas@391 492 var position = Number(scaleObj[0])*0.01;
nicholas@391 493 value.nodeValue = position;
nicholas@391 494 var pixelPosition = (position*positionScale)+offset;
nicholas@391 495 var scaleDOM = document.createElement('span');
nicholas@391 496 scaleDOM.textContent = scaleObj[1];
nicholas@391 497 this.scale.appendChild(scaleDOM);
nicholas@391 498 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
nicholas@391 499 scaleDOM.setAttributeNode(value);
nicholas@391 500 }
nicholas@391 501
nicholas@391 502 var dest = document.getElementById("slider-holder");
nicholas@391 503 dest.appendChild(this.sliderDOM);
nicholas@391 504
nicholas@391 505 this.createSliderObject = function(audioObject)
n@383 506 {
n@383 507 var trackObj = document.createElement('div');
n@383 508 trackObj.className = 'track-slider track-slider-disabled track-slider-'+audioObject.id;
nicholas@391 509 trackObj.id = 'track-slider-'+this.id+'-'+audioObject.id;
n@383 510 trackObj.setAttribute('trackIndex',audioObject.id);
n@383 511 trackObj.innerHTML = '<span>'+audioObject.id+'</span>';
nicholas@391 512 if (this.name != undefined) {
nicholas@391 513 trackObj.setAttribute('interface-name',this.name);
n@383 514 } else {
nicholas@391 515 trackObj.setAttribute('interface-name',this.id);
n@383 516 }
nicholas@391 517 var offset = Number(this.canvas.attributes['marginsize'].value);
n@383 518 // Distribute it randomnly
n@383 519 var w = window.innerWidth - (offset+8)*2;
n@383 520 w = Math.random()*w;
n@383 521 w = Math.floor(w+(offset+8));
n@383 522 trackObj.style.left = w+'px';
nicholas@391 523 this.canvas.appendChild(trackObj);
nicholas@391 524 this.sliders.push(trackObj);
nicholas@392 525 this.metrics.push(new metricTracker(this));
nicholas@392 526 this.metrics[this.metrics.length-1].initialPosition = convSliderPosToRate(trackObj);
nicholas@391 527 return trackObj;
nicholas@391 528 };
nicholas@391 529
nicholas@391 530 this.resize = function(event)
nicholas@391 531 {
nicholas@391 532 var holdValues = [];
nicholas@391 533 for (var index = 0; index < this.sliders.length; index++)
nicholas@391 534 {
nicholas@391 535 holdValues.push(convSliderPosToRate(this.sliders[index]));
nicholas@391 536 }
nicholas@391 537 var width = event.target.innerWidth;
nicholas@391 538 var sliderDiv = this.canvas;
nicholas@391 539 var sliderScaleDiv = this.scale;
nicholas@391 540 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
nicholas@391 541 var w = (marginsize+8)*2;
nicholas@391 542 sliderDiv.style.width = width - w + 'px';
nicholas@391 543 var width = width - w;
nicholas@391 544 // Move sliders into new position
nicholas@391 545 for (var index = 0; index < this.sliders.length; index++)
nicholas@391 546 {
nicholas@391 547 var pos = holdValues[index];
nicholas@391 548 var pix = pos * width;
nicholas@391 549 this.sliders[index].style.left = pix+marginsize+'px';
nicholas@391 550 }
nicholas@391 551
nicholas@391 552 // Move scale labels
nicholas@391 553 for (var index = 0; index < this.scale.children.length; index++)
nicholas@391 554 {
nicholas@391 555 var scaleObj = this.scale.children[index];
nicholas@391 556 var position = Number(scaleObj.attributes['value'].value);
nicholas@391 557 var pixelPosition = (position*width)+marginsize;
nicholas@391 558 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
nicholas@391 559 }
n@394 560 };
nicholas@391 561 }
nicholas@391 562
nicholas@391 563 function sliderObject(audioObject,interfaceObjects) {
nicholas@391 564 // Create a new slider object;
nicholas@391 565 this.parent = audioObject;
nicholas@391 566 this.trackSliderObjects = [];
nicholas@391 567 for (var i=0; i<interfaceContext.interfaceSliders.length; i++)
nicholas@391 568 {
nicholas@391 569 var trackObj = interfaceContext.interfaceSliders[i].createSliderObject(audioObject);
nicholas@391 570 this.trackSliderObjects.push(trackObj);
n@383 571 }
n@183 572
n@183 573 // Onclick, switch playback to that track
n@183 574
nicholas@271 575 this.enable = function() {
nicholas@271 576 if (this.parent.state == 1)
nicholas@271 577 {
n@383 578 $(this.trackSliderObjects).each(function(i,trackObj){
n@383 579 $(trackObj).removeClass('track-slider-disabled');
n@383 580 });
nicholas@271 581 }
nicholas@271 582 };
nicholas@271 583
nicholas@219 584 this.exportXMLDOM = function(audioObject) {
n@183 585 // Called by the audioObject holding this element. Must be present
n@383 586 var obj = [];
n@383 587 $(this.trackSliderObjects).each(function(i,trackObj){
n@383 588 var node = document.createElement('value');
n@397 589 node.setAttribute("inteerface-name",trackObj.getAttribute("interface-name"));
n@383 590 node.textContent = convSliderPosToRate(trackObj);
n@383 591 obj.push(node);
n@383 592 });
n@383 593
n@383 594 return obj;
n@183 595 };
nicholas@219 596 this.getValue = function() {
nicholas@219 597 return convSliderPosToRate(this.trackSliderObj);
nicholas@220 598 };
n@183 599 }
nicholas@119 600
n@296 601 function buttonSubmitClick()
n@40 602 {
nicholas@232 603 var checks = testState.currentStateMap[testState.currentIndex].interfaces[0].options;
nicholas@214 604 var canContinue = true;
nicholas@219 605
nicholas@219 606 // Check that the anchor and reference objects are correctly placed
nicholas@235 607 if (interfaceContext.checkHiddenAnchor() == false) {return;}
nicholas@235 608 if (interfaceContext.checkHiddenReference() == false) {return;}
nicholas@219 609
nicholas@214 610 for (var i=0; i<checks.length; i++) {
nicholas@214 611 if (checks[i].type == 'check')
nicholas@214 612 {
nicholas@214 613 switch(checks[i].check) {
nicholas@214 614 case 'fragmentPlayed':
nicholas@214 615 // Check if all fragments have been played
nicholas@214 616 var checkState = interfaceContext.checkAllPlayed();
nicholas@214 617 if (checkState == false) {canContinue = false;}
nicholas@214 618 break;
nicholas@214 619 case 'fragmentFullPlayback':
nicholas@214 620 // Check all fragments have been played to their full length
n@366 621 var checkState = interfaceContext.checkFragmentsFullyPlayed();
nicholas@214 622 if (checkState == false) {canContinue = false;}
nicholas@214 623 break;
nicholas@214 624 case 'fragmentMoved':
nicholas@214 625 // Check all fragment sliders have been moved.
nicholas@214 626 var checkState = interfaceContext.checkAllMoved();
nicholas@214 627 if (checkState == false) {canContinue = false;}
nicholas@214 628 break;
nicholas@214 629 case 'fragmentComments':
nicholas@214 630 // Check all fragment sliders have been moved.
nicholas@214 631 var checkState = interfaceContext.checkAllCommented();
nicholas@214 632 if (checkState == false) {canContinue = false;}
nicholas@214 633 break;
nicholas@231 634 case 'scalerange':
nicholas@231 635 // Check the scale is used to its full width outlined by the node
nicholas@231 636 var checkState = interfaceContext.checkScaleRange();
nicholas@231 637 if (checkState == false) {canContinue = false;}
nicholas@231 638 break;
nicholas@214 639 }
nicholas@214 640
nicholas@214 641 }
nicholas@231 642 if (!canContinue) {break;}
nicholas@214 643 }
nicholas@214 644
nicholas@214 645 if (canContinue) {
nicholas@107 646 if (audioEngineContext.status == 1) {
nicholas@107 647 var playback = document.getElementById('playback-button');
nicholas@107 648 playback.click();
nicholas@107 649 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
nicholas@107 650 } else
nicholas@107 651 {
nicholas@107 652 if (audioEngineContext.timer.testStarted == false)
nicholas@107 653 {
b@344 654 alert('You have not started the test! Please click a fragment to begin the test!');
nicholas@107 655 return;
nicholas@107 656 }
nicholas@107 657 }
nicholas@129 658 testState.advanceState();
nicholas@214 659 }
n@40 660 }
n@40 661
n@383 662 function convSliderPosToRate(trackSlider)
n@51 663 {
n@383 664 var slider = trackSlider.parentElement;
n@383 665 var w = slider.style.width;
n@383 666 var marginsize = Number(slider.attributes['marginsize'].value);
n@51 667 var maxPix = w.substr(0,w.length-2);
n@383 668 var pix = trackSlider.style.left;
n@51 669 pix = pix.substr(0,pix.length-2);
n@127 670 var rate = (pix-marginsize)/maxPix;
n@51 671 return rate;
n@51 672 }
n@51 673
n@127 674 function resizeWindow(event){
n@127 675 // Function called when the window has been resized.
n@127 676 // MANDATORY FUNCTION
n@127 677
nicholas@392 678 // Resize the slider objects
nicholas@391 679 for (var i=0; i<interfaceContext.interfaceSliders.length; i++)
nicholas@391 680 {
nicholas@391 681 interfaceContext.interfaceSliders[i].resize(event);
nicholas@391 682 }
n@127 683 }
n@127 684
n@181 685 function pageXMLSave(store, testXML)
n@44 686 {
n@381 687 // MANDATORY
n@44 688 // Saves a specific test page
nicholas@392 689 // You can use this space to add any extra nodes to your XML <audioHolder> saves
nicholas@392 690 // Get the current <audioHolder> information in store (remember to appendChild your data to it)
n@396 691 if (interfaceContext.interfaceSliders.length == 1)
n@396 692 {
n@396 693 // If there is only one axis, there only needs to be one metric return
n@396 694 return;
n@396 695 }
nicholas@392 696 var audioelements = store.getElementsByTagName("audioelement");
nicholas@392 697 for (var i=0; i<audioelements.length; i++)
nicholas@392 698 {
nicholas@392 699 // Have to append the metric specific nodes
n@396 700 if (testXML.outsideReference == null || testXML.outsideReference.id != audioelements[i].id)
nicholas@392 701 {
n@397 702 var inject = audioelements[i].getElementsByTagName("metric");
n@397 703 if (inject.length == 0)
n@397 704 {
n@397 705 inject = document.createElement("metric");
n@397 706 } else {
n@397 707 inject = inject[0];
n@397 708 }
n@396 709 for (var k=0; k<interfaceContext.interfaceSliders.length; k++)
n@396 710 {
n@396 711 var node = interfaceContext.interfaceSliders[k].metrics[i].exportXMLDOM();
n@397 712 var mrnodes = node.getElementsByTagName("metricresult");
n@397 713 for (var j=0; j<mrnodes.length; j++)
n@397 714 {
n@397 715 var name = mrnodes[j].getAttribute("name");
n@397 716 if (name == "elementTracker" || name == "elementTrackerFull" || name == "elementInitialPosition" || name == "elementFlagMoved")
n@397 717 {
n@397 718 mrnodes[j].setAttribute("interface-name",interfaceContext.interfaceSliders[k].name);
n@397 719 mrnodes[j].setAttribute("interface-id",k);
n@397 720 inject.appendChild(mrnodes[j]);
n@397 721 }
n@397 722 }
n@396 723 }
nicholas@392 724 }
nicholas@392 725 }
nicholas@67 726 }