annotate ape.js @ 391:3b97ee830b48 Dev_main

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