annotate ape.js @ 1582:d4b626a4bc76

Comment Boxes handled by Interface object.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 04 Jun 2015 16:48:04 +0100
parents 284251e3a6a3
children 62e755ce8d34
rev   line source
nickjillings@1575 1 /**
nickjillings@1575 2 * ape.js
nickjillings@1575 3 * Create the APE interface
nickjillings@1575 4 */
nickjillings@1575 5
nickjillings@1575 6 // preTest - In preTest state
nickjillings@1575 7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
nickjillings@1575 8 // testRunPost-ID - Post test of test ID
nickjillings@1575 9 // testRunPre-ID - Pre-test of test ID
nickjillings@1575 10 // postTest - End of test, final submission!
nickjillings@1575 11
nickjillings@1575 12
nickjillings@1575 13 // Once this is loaded and parsed, begin execution
nickjillings@1581 14 loadInterface();
nickjillings@1575 15
nickjillings@1581 16 function loadInterface() {
nickjillings@1575 17
nickjillings@1575 18 // Get the dimensions of the screen available to the page
nickjillings@1575 19 var width = window.innerWidth;
nickjillings@1575 20 var height = window.innerHeight;
nickjillings@1575 21
nickjillings@1575 22 // The injection point into the HTML page
nickjillings@1582 23 interfaceContext.insertPoint = document.getElementById("topLevelBody");
nickjillings@1575 24 var testContent = document.createElement('div');
nickjillings@1575 25
nickjillings@1575 26 testContent.id = 'testContent';
nickjillings@1576 27
nickjillings@1575 28
nickjillings@1575 29 // Create APE specific metric functions
nickjillings@1575 30 audioEngineContext.metric.initialiseTest = function()
nickjillings@1575 31 {
nickjillings@1575 32 };
nickjillings@1575 33
nickjillings@1575 34 audioEngineContext.metric.sliderMoveStart = function(id)
nickjillings@1575 35 {
nickjillings@1575 36 if (this.data == -1)
nickjillings@1575 37 {
nickjillings@1575 38 this.data = id;
nickjillings@1575 39 } else {
nickjillings@1575 40 console.log('ERROR: Metric tracker detecting two moves!');
nickjillings@1575 41 this.data = -1;
nickjillings@1575 42 }
nickjillings@1575 43 };
nickjillings@1575 44 audioEngineContext.metric.sliderMoved = function()
nickjillings@1575 45 {
nickjillings@1575 46 var time = audioEngineContext.timer.getTestTime();
nickjillings@1575 47 var id = this.data;
nickjillings@1575 48 this.data = -1;
nickjillings@1575 49 var position = convSliderPosToRate(id);
nickjillings@1575 50 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
nickjillings@1575 51 if (audioEngineContext.timer.testStarted)
nickjillings@1575 52 {
nickjillings@1575 53 audioEngineContext.audioObjects[id].metric.moved(time,position);
nickjillings@1575 54 }
nickjillings@1575 55 };
nickjillings@1575 56
nickjillings@1575 57 audioEngineContext.metric.sliderPlayed = function(id)
nickjillings@1575 58 {
nickjillings@1575 59 var time = audioEngineContext.timer.getTestTime();
nickjillings@1575 60 if (audioEngineContext.timer.testStarted)
nickjillings@1575 61 {
nickjillings@1575 62 if (this.lastClicked >= 0)
nickjillings@1575 63 {
nickjillings@1575 64 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
nickjillings@1575 65 }
nickjillings@1575 66 this.lastClicked = id;
nickjillings@1575 67 audioEngineContext.audioObjects[id].metric.listening(time);
nickjillings@1575 68 }
nickjillings@1575 69 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
nickjillings@1575 70 };
nickjillings@1575 71
nickjillings@1577 72 // Bindings for audioObjects
nickjillings@1577 73
nickjillings@1575 74 // Create the top div for the Title element
nickjillings@1581 75 var titleAttr = specification.title;
nickjillings@1575 76 var title = document.createElement('div');
nickjillings@1575 77 title.className = "title";
nickjillings@1575 78 title.align = "center";
nickjillings@1575 79 var titleSpan = document.createElement('span');
nickjillings@1575 80
nickjillings@1575 81 // Set title to that defined in XML, else set to default
nickjillings@1575 82 if (titleAttr != undefined) {
nickjillings@1581 83 titleSpan.textContent = titleAttr;
nickjillings@1575 84 } else {
nickjillings@1581 85 titleSpan.textContent = 'Listening test';
nickjillings@1575 86 }
nickjillings@1575 87 // Insert the titleSpan element into the title div element.
nickjillings@1575 88 title.appendChild(titleSpan);
nickjillings@1575 89
nickjillings@1575 90 var pagetitle = document.createElement('div');
nickjillings@1575 91 pagetitle.className = "pageTitle";
nickjillings@1575 92 pagetitle.align = "center";
nickjillings@1575 93 var titleSpan = document.createElement('span');
nickjillings@1575 94 titleSpan.id = "pageTitle";
nickjillings@1575 95 pagetitle.appendChild(titleSpan);
nickjillings@1575 96
nickjillings@1575 97 // Create Interface buttons!
nickjillings@1575 98 var interfaceButtons = document.createElement('div');
nickjillings@1575 99 interfaceButtons.id = 'interface-buttons';
nickjillings@1575 100
nickjillings@1575 101 // Create playback start/stop points
nickjillings@1575 102 var playback = document.createElement("button");
nickjillings@1575 103 playback.innerHTML = 'Stop';
nickjillings@1575 104 playback.id = 'playback-button';
nickjillings@1575 105 // onclick function. Check if it is playing or not, call the correct function in the
nickjillings@1575 106 // audioEngine, change the button text to reflect the next state.
nickjillings@1575 107 playback.onclick = function() {
nickjillings@1575 108 if (audioEngineContext.status == 1) {
nickjillings@1575 109 audioEngineContext.stop();
nickjillings@1575 110 this.innerHTML = 'Stop';
nickjillings@1575 111 var time = audioEngineContext.timer.getTestTime();
nickjillings@1575 112 console.log('Stopped at ' + time); // DEBUG/SAFETY
nickjillings@1575 113 }
nickjillings@1575 114 };
nickjillings@1575 115 // Create Submit (save) button
nickjillings@1575 116 var submit = document.createElement("button");
nickjillings@1575 117 submit.innerHTML = 'Submit';
nickjillings@1575 118 submit.onclick = buttonSubmitClick;
nickjillings@1575 119 submit.id = 'submit-button';
nickjillings@1575 120 // Append the interface buttons into the interfaceButtons object.
nickjillings@1575 121 interfaceButtons.appendChild(playback);
nickjillings@1575 122 interfaceButtons.appendChild(submit);
nickjillings@1575 123
nickjillings@1575 124 // Now create the slider and HTML5 canvas boxes
nickjillings@1575 125
nickjillings@1575 126 // Create the div box to center align
nickjillings@1575 127 var sliderBox = document.createElement('div');
nickjillings@1575 128 sliderBox.className = 'sliderCanvasDiv';
nickjillings@1575 129 sliderBox.id = 'sliderCanvasHolder';
nickjillings@1575 130
nickjillings@1575 131 // Create the slider box to hold the slider elements
nickjillings@1575 132 var canvas = document.createElement('div');
nickjillings@1575 133 canvas.id = 'slider';
nickjillings@1575 134 canvas.align = "left";
nickjillings@1575 135 canvas.addEventListener('dragover',function(event){
nickjillings@1575 136 event.preventDefault();
nickjillings@1575 137 return false;
nickjillings@1575 138 },false);
nickjillings@1575 139 var sliderMargin = document.createAttribute('marginsize');
nickjillings@1575 140 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
nickjillings@1575 141 // Must have a known EXACT width, as this is used later to determine the ratings
nickjillings@1575 142 var w = (Number(sliderMargin.nodeValue)+8)*2;
nickjillings@1575 143 canvas.style.width = width - w +"px";
nickjillings@1575 144 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
nickjillings@1575 145 canvas.setAttributeNode(sliderMargin);
nickjillings@1575 146 sliderBox.appendChild(canvas);
nickjillings@1575 147
nickjillings@1575 148 // Create the div to hold any scale objects
nickjillings@1575 149 var scale = document.createElement('div');
nickjillings@1575 150 scale.className = 'sliderScale';
nickjillings@1575 151 scale.id = 'sliderScaleHolder';
nickjillings@1575 152 scale.align = 'left';
nickjillings@1575 153 sliderBox.appendChild(scale);
nickjillings@1575 154
nickjillings@1575 155 // Global parent for the comment boxes on the page
nickjillings@1575 156 var feedbackHolder = document.createElement('div');
nickjillings@1575 157 feedbackHolder.id = 'feedbackHolder';
nickjillings@1575 158
nickjillings@1575 159 testContent.style.zIndex = 1;
nickjillings@1582 160 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
nickjillings@1575 161
nickjillings@1575 162 // Inject into HTML
nickjillings@1575 163 testContent.appendChild(title); // Insert the title
nickjillings@1575 164 testContent.appendChild(pagetitle);
nickjillings@1575 165 testContent.appendChild(interfaceButtons);
nickjillings@1575 166 testContent.appendChild(sliderBox);
nickjillings@1575 167 testContent.appendChild(feedbackHolder);
nickjillings@1582 168 interfaceContext.insertPoint.appendChild(testContent);
nickjillings@1575 169
nickjillings@1575 170 // Load the full interface
nickjillings@1575 171 testState.initialise();
nickjillings@1575 172 testState.advanceState();
nickjillings@1575 173
nickjillings@1575 174 }
nickjillings@1575 175
nickjillings@1581 176 function loadTest(audioHolderObject)
nickjillings@1575 177 {
nickjillings@1575 178
nickjillings@1575 179 // Reset audioEngineContext.Metric globals for new test
nickjillings@1575 180 audioEngineContext.newTestPage();
nickjillings@1575 181
nickjillings@1581 182 var id = audioHolderObject.id;
nickjillings@1575 183
nickjillings@1575 184 var feedbackHolder = document.getElementById('feedbackHolder');
nickjillings@1575 185 var canvas = document.getElementById('slider');
nickjillings@1575 186 feedbackHolder.innerHTML = null;
nickjillings@1575 187 canvas.innerHTML = null;
nickjillings@1575 188
nickjillings@1575 189 // Setup question title
nickjillings@1581 190 var interfaceObj = $(audioHolderObject).find('interface');
nickjillings@1575 191 var titleNode = interfaceObj.find('title');
nickjillings@1575 192 if (titleNode[0] != undefined)
nickjillings@1575 193 {
nickjillings@1575 194 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
nickjillings@1575 195 }
nickjillings@1575 196 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
nickjillings@1575 197 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
nickjillings@1575 198 var scale = document.getElementById('sliderScaleHolder');
nickjillings@1575 199 scale.innerHTML = null;
nickjillings@1575 200 interfaceObj.find('scale').each(function(index,scaleObj){
nickjillings@1575 201 var value = document.createAttribute('value');
nickjillings@1575 202 var position = Number(scaleObj.attributes['position'].value)*0.01;
nickjillings@1575 203 value.nodeValue = position;
nickjillings@1575 204 var pixelPosition = (position*positionScale)+offset;
nickjillings@1575 205 var scaleDOM = document.createElement('span');
nickjillings@1575 206 scaleDOM.textContent = scaleObj.textContent;
nickjillings@1575 207 scale.appendChild(scaleDOM);
nickjillings@1575 208 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
nickjillings@1575 209 scaleDOM.setAttributeNode(value);
nickjillings@1575 210 });
nickjillings@1575 211
nickjillings@1575 212 var commentBoxPrefix = interfaceObj.find('commentBoxPrefix');
nickjillings@1575 213 if (commentBoxPrefix.length != 0) {
nickjillings@1575 214 commentBoxPrefix = commentBoxPrefix[0].textContent;
nickjillings@1575 215 } else {
nickjillings@1575 216 commentBoxPrefix = "Comment on track";
nickjillings@1575 217 }
nickjillings@1575 218
nickjillings@1575 219 /// CHECK FOR SAMPLE RATE COMPATIBILITY
nickjillings@1581 220 if (audioHolderObject.sampleRate != undefined) {
nickjillings@1581 221 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
nickjillings@1575 222 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
nickjillings@1575 223 alert(errStr);
nickjillings@1575 224 return;
nickjillings@1575 225 }
nickjillings@1575 226 }
nickjillings@1575 227
nickjillings@1581 228 var commentShow = audioHolderObject.elementComments;
nickjillings@1575 229
nickjillings@1581 230 var loopPlayback = audioHolderObject.loop;
nickjillings@1581 231
nickjillings@1575 232 audioEngineContext.loopPlayback = loopPlayback;
nickjillings@1575 233 // Create AudioEngine bindings for playback
nickjillings@1575 234 if (loopPlayback) {
nickjillings@1575 235 audioEngineContext.selectedTrack = function(id) {
nickjillings@1575 236 for (var i=0; i<this.audioObjects.length; i++)
nickjillings@1575 237 {
nickjillings@1575 238 if (id == i) {
nickjillings@1575 239 this.audioObjects[i].loopStart();
nickjillings@1575 240 } else {
nickjillings@1575 241 this.audioObjects[i].loopStop();
nickjillings@1575 242 }
nickjillings@1575 243 }
nickjillings@1575 244 };
nickjillings@1575 245 } else {
nickjillings@1575 246 audioEngineContext.selectedTrack = function(id) {
nickjillings@1575 247 for (var i=0; i<this.audioObjects.length; i++)
nickjillings@1575 248 {
nickjillings@1575 249 this.audioObjects[i].outputGain.gain.value = 0.0;
nickjillings@1575 250 this.audioObjects[i].stop();
nickjillings@1575 251 }
nickjillings@1575 252 if (this.status == 1) {
nickjillings@1575 253 this.audioObjects[id].outputGain.gain.value = 1.0;
nickjillings@1575 254 this.audioObjects[id].play(audioContext.currentTime+0.01);
nickjillings@1575 255 }
nickjillings@1575 256 };
nickjillings@1575 257 }
nickjillings@1575 258
nickjillings@1575 259 currentTestHolder = document.createElement('audioHolder');
nickjillings@1581 260 currentTestHolder.id = audioHolderObject.id;
nickjillings@1581 261 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
nickjillings@1575 262
nickjillings@1581 263 var randomise = audioHolderObject.randomiseOrder;
nickjillings@1575 264
nickjillings@1581 265 var audioElements = audioHolderObject.audioElements;
nickjillings@1575 266 currentTrackOrder = [];
nickjillings@1575 267 if (randomise) {
nickjillings@1581 268 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
nickjillings@1575 269 }
nickjillings@1575 270
nickjillings@1575 271 // Delete any previous audioObjects associated with the audioEngine
nickjillings@1575 272 audioEngineContext.audioObjects = [];
nickjillings@1575 273
nickjillings@1575 274 // Find all the audioElements from the audioHolder
nickjillings@1581 275 $(audioHolderObject.audioElements).each(function(index,element){
nickjillings@1575 276 // Find URL of track
nickjillings@1575 277 // In this jQuery loop, variable 'this' holds the current audioElement.
nickjillings@1575 278
nickjillings@1575 279 // Now load each audio sample. First create the new track by passing the full URL
nickjillings@1581 280 var trackURL = audioHolderObject.hostURL + element.url;
nickjillings@1582 281 var audioObject = audioEngineContext.newTrack(element);
nickjillings@1575 282
nickjillings@1575 283 if (commentShow) {
nickjillings@1582 284 var node = interfaceContext.createCommentBox(audioObject);
nickjillings@1575 285 }
nickjillings@1575 286
nickjillings@1575 287 // Create a slider per track
nickjillings@1575 288
nickjillings@1575 289 var trackSliderObj = document.createElement('div');
nickjillings@1575 290 trackSliderObj.className = 'track-slider';
nickjillings@1575 291 trackSliderObj.id = 'track-slider-'+index;
nickjillings@1575 292
nickjillings@1575 293 var trackSliderAOIndex = document.createAttribute('trackIndex');
nickjillings@1575 294 trackSliderAOIndex.nodeValue = index;
nickjillings@1575 295 trackSliderObj.setAttributeNode(trackSliderAOIndex);
nickjillings@1575 296
nickjillings@1575 297 // Distribute it randomnly
nickjillings@1575 298 var w = window.innerWidth - (offset+8)*2;
nickjillings@1575 299 w = Math.random()*w;
nickjillings@1575 300 w = Math.floor(w+(offset+8));
nickjillings@1575 301 trackSliderObj.style.left = w+'px';
nickjillings@1575 302 trackSliderObj.innerHTML = '<span>'+index+'</span>';
nickjillings@1575 303 trackSliderObj.draggable = true;
nickjillings@1575 304 trackSliderObj.ondragend = dragEnd;
nickjillings@1575 305 trackSliderObj.ondragstart = function()
nickjillings@1575 306 {
nickjillings@1575 307 var id = Number(event.srcElement.attributes['trackIndex'].value);
nickjillings@1575 308 audioEngineContext.metric.sliderMoveStart(id);
nickjillings@1575 309 };
nickjillings@1575 310
nickjillings@1575 311 // Onclick, switch playback to that track
nickjillings@1575 312 trackSliderObj.onclick = function() {
nickjillings@1575 313 // Start the test on first click, that way timings are more accurate.
nickjillings@1575 314 audioEngineContext.play();
nickjillings@1575 315 if (audioEngineContext.audioObjectsReady) {
nickjillings@1575 316 // Cannot continue to issue play command until audioObjects reported as ready!
nickjillings@1575 317 // Get the track ID from the object ID
nickjillings@1575 318 var id = Number(event.srcElement.attributes['trackIndex'].value);
nickjillings@1575 319 //audioEngineContext.metric.sliderPlayed(id);
nickjillings@1575 320 audioEngineContext.selectedTrack(id);
nickjillings@1575 321 // Currently playing track red, rest green
nickjillings@1575 322
nickjillings@1575 323 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
nickjillings@1575 324 $('.track-slider').removeClass('track-slider-playing');
nickjillings@1575 325 $(event.srcElement).addClass('track-slider-playing');
nickjillings@1575 326 $('.comment-div').removeClass('comment-box-playing');
nickjillings@1575 327 $('#comment-div-'+id).addClass('comment-box-playing');
nickjillings@1575 328 }
nickjillings@1575 329 };
nickjillings@1575 330
nickjillings@1577 331 // Attach binding
nickjillings@1579 332 audioObject.sliderDOM = trackSliderObj;
nickjillings@1577 333
nickjillings@1575 334 canvas.appendChild(trackSliderObj);
nickjillings@1579 335 audioObject.metric.initialised(convSliderPosToRate(index));
nickjillings@1575 336
nickjillings@1575 337 });
nickjillings@1582 338 if (commentShow) {
nickjillings@1582 339 interfaceContext.showCommentBoxes(feedbackHolder,true);
nickjillings@1582 340 }
nickjillings@1575 341
nickjillings@1575 342 // Append any commentQuestion boxes
nickjillings@1581 343 $(audioHolderObject.commentQuestions).each(function(index,element) {
nickjillings@1575 344 // Create document objects to hold the comment boxes
nickjillings@1575 345 var trackComment = document.createElement('div');
nickjillings@1575 346 trackComment.className = 'comment-div commentQuestion';
nickjillings@1581 347 trackComment.id = element.id;
nickjillings@1575 348 // Create a string next to each comment asking for a comment
nickjillings@1575 349 var trackString = document.createElement('span');
nickjillings@1581 350 trackString.innerHTML = element.question;
nickjillings@1575 351 // Create the HTML5 comment box 'textarea'
nickjillings@1575 352 var trackCommentBox = document.createElement('textarea');
nickjillings@1575 353 trackCommentBox.rows = '4';
nickjillings@1575 354 trackCommentBox.cols = '100';
nickjillings@1575 355 trackCommentBox.name = 'commentQuestion'+index;
nickjillings@1575 356 trackCommentBox.className = 'trackComment';
nickjillings@1575 357 var br = document.createElement('br');
nickjillings@1575 358 // Add to the holder.
nickjillings@1575 359 trackComment.appendChild(trackString);
nickjillings@1575 360 trackComment.appendChild(br);
nickjillings@1575 361 trackComment.appendChild(trackCommentBox);
nickjillings@1575 362 feedbackHolder.appendChild(trackComment);
nickjillings@1575 363 });
nickjillings@1575 364
nickjillings@1575 365
nickjillings@1575 366 testWaitIndicator();
nickjillings@1575 367 }
nickjillings@1575 368
nickjillings@1575 369
nickjillings@1575 370 function dragEnd(ev) {
nickjillings@1575 371 // Function call when a div has been dropped
nickjillings@1575 372 var slider = document.getElementById('slider');
nickjillings@1575 373 var marginSize = Number(slider.attributes['marginsize'].value);
nickjillings@1575 374 var w = slider.style.width;
nickjillings@1575 375 w = Number(w.substr(0,w.length-2));
nickjillings@1575 376 var x = ev.x;
nickjillings@1575 377 if (x >= marginSize && x < w+marginSize) {
nickjillings@1575 378 this.style.left = (x)+'px';
nickjillings@1575 379 } else {
nickjillings@1575 380 if (x<marginSize) {
nickjillings@1575 381 this.style.left = marginSize+'px';
nickjillings@1575 382 } else {
nickjillings@1575 383 this.style.left = (w+marginSize) + 'px';
nickjillings@1575 384 }
nickjillings@1575 385 }
nickjillings@1575 386 audioEngineContext.metric.sliderMoved();
nickjillings@1575 387 }
nickjillings@1575 388
nickjillings@1575 389 function buttonSubmitClick() // TODO: Only when all songs have been played!
nickjillings@1575 390 {
nickjillings@1575 391 hasBeenPlayed = audioEngineContext.checkAllPlayed();
nickjillings@1575 392 if (hasBeenPlayed.length == 0) {
nickjillings@1575 393 if (audioEngineContext.status == 1) {
nickjillings@1575 394 var playback = document.getElementById('playback-button');
nickjillings@1575 395 playback.click();
nickjillings@1575 396 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
nickjillings@1575 397 } else
nickjillings@1575 398 {
nickjillings@1575 399 if (audioEngineContext.timer.testStarted == false)
nickjillings@1575 400 {
nickjillings@1575 401 alert('You have not started the test! Please press start to begin the test!');
nickjillings@1575 402 return;
nickjillings@1575 403 }
nickjillings@1575 404 }
nickjillings@1575 405 testState.advanceState();
nickjillings@1575 406 } else // if a fragment has not been played yet
nickjillings@1575 407 {
nickjillings@1575 408 str = "";
nickjillings@1575 409 if (hasBeenPlayed.length > 1) {
nickjillings@1575 410 for (var i=0; i<hasBeenPlayed.length; i++) {
nickjillings@1575 411 str = str + hasBeenPlayed[i];
nickjillings@1575 412 if (i < hasBeenPlayed.length-2){
nickjillings@1575 413 str += ", ";
nickjillings@1575 414 } else if (i == hasBeenPlayed.length-2) {
nickjillings@1575 415 str += " or ";
nickjillings@1575 416 }
nickjillings@1575 417 }
nickjillings@1575 418 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
nickjillings@1575 419 } else {
nickjillings@1575 420 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
nickjillings@1575 421 }
nickjillings@1575 422 return;
nickjillings@1575 423 }
nickjillings@1575 424 }
nickjillings@1575 425
nickjillings@1575 426 function convSliderPosToRate(id)
nickjillings@1575 427 {
nickjillings@1575 428 var w = document.getElementById('slider').style.width;
nickjillings@1575 429 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
nickjillings@1575 430 var maxPix = w.substr(0,w.length-2);
nickjillings@1575 431 var slider = document.getElementsByClassName('track-slider')[id];
nickjillings@1575 432 var pix = slider.style.left;
nickjillings@1575 433 pix = pix.substr(0,pix.length-2);
nickjillings@1575 434 var rate = (pix-marginsize)/maxPix;
nickjillings@1575 435 return rate;
nickjillings@1575 436 }
nickjillings@1575 437
nickjillings@1575 438 function resizeWindow(event){
nickjillings@1575 439 // Function called when the window has been resized.
nickjillings@1575 440 // MANDATORY FUNCTION
nickjillings@1575 441
nickjillings@1575 442 // Store the slider marker values
nickjillings@1575 443 var holdValues = [];
nickjillings@1575 444 $(".track-slider").each(function(index,sliderObj){
nickjillings@1575 445 holdValues.push(convSliderPosToRate(index));
nickjillings@1575 446 });
nickjillings@1575 447
nickjillings@1575 448 var width = event.target.innerWidth;
nickjillings@1575 449 var canvas = document.getElementById('sliderCanvasHolder');
nickjillings@1575 450 var sliderDiv = canvas.children[0];
nickjillings@1575 451 var sliderScaleDiv = canvas.children[1];
nickjillings@1575 452 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
nickjillings@1575 453 var w = (marginsize+8)*2;
nickjillings@1575 454 sliderDiv.style.width = width - w + 'px';
nickjillings@1575 455 var width = width - w;
nickjillings@1575 456 // Move sliders into new position
nickjillings@1575 457 $(".track-slider").each(function(index,sliderObj){
nickjillings@1575 458 var pos = holdValues[index];
nickjillings@1575 459 var pix = pos * width;
nickjillings@1575 460 sliderObj.style.left = pix+marginsize+'px';
nickjillings@1575 461 });
nickjillings@1575 462
nickjillings@1575 463 // Move scale labels
nickjillings@1575 464 $(sliderScaleDiv.children).each(function(index,scaleObj){
nickjillings@1575 465 var position = Number(scaleObj.attributes['value'].value);
nickjillings@1575 466 var pixelPosition = (position*width)+marginsize;
nickjillings@1575 467 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
nickjillings@1575 468 });
nickjillings@1575 469 }
nickjillings@1575 470
nickjillings@1581 471 function pageXMLSave(store, testXML)
nickjillings@1575 472 {
nickjillings@1575 473 // Saves a specific test page
nickjillings@1575 474 var xmlDoc = store;
nickjillings@1575 475 // Check if any session wide metrics are enabled
nickjillings@1575 476
nickjillings@1581 477 var commentShow = testXML.elementComments;
nickjillings@1575 478
nickjillings@1575 479 var metric = document.createElement('metric');
nickjillings@1575 480 if (audioEngineContext.metric.enableTestTimer)
nickjillings@1575 481 {
nickjillings@1575 482 var testTime = document.createElement('metricResult');
nickjillings@1575 483 testTime.id = 'testTime';
nickjillings@1575 484 testTime.textContent = audioEngineContext.timer.testDuration;
nickjillings@1575 485 metric.appendChild(testTime);
nickjillings@1575 486 }
nickjillings@1575 487 xmlDoc.appendChild(metric);
nickjillings@1578 488 var audioObjects = audioEngineContext.audioObjects;
nickjillings@1578 489 for (var i=0; i<audioObjects.length; i++)
nickjillings@1575 490 {
nickjillings@1575 491 var audioElement = document.createElement('audioElement');
nickjillings@1578 492 audioElement.id = audioObjects[i].id;
nickjillings@1578 493 audioElement.setAttribute('url',audioObjects[i].url);
nickjillings@1575 494 var value = document.createElement('value');
nickjillings@1575 495 value.innerHTML = convSliderPosToRate(i);
nickjillings@1575 496 if (commentShow) {
nickjillings@1575 497 var comment = document.createElement("comment");
nickjillings@1575 498 var question = document.createElement("question");
nickjillings@1575 499 var response = document.createElement("response");
nickjillings@1578 500 question.textContent = audioObjects[i].commentDOM.children[0].textContent;
nickjillings@1578 501 response.textContent = audioObjects[i].commentDOM.children[2].value;
nickjillings@1578 502 console.log('Comment ' + i + ': ' + response.textContent); // DEBUG/SAFETY
nickjillings@1575 503 comment.appendChild(question);
nickjillings@1575 504 comment.appendChild(response);
nickjillings@1575 505 audioElement.appendChild(comment);
nickjillings@1575 506 }
nickjillings@1575 507 audioElement.appendChild(value);
nickjillings@1575 508 // Check for any per element metrics
nickjillings@1577 509
nickjillings@1578 510 audioElement.appendChild(audioObjects[i].metric.exportXMLDOM());
nickjillings@1575 511 xmlDoc.appendChild(audioElement);
nickjillings@1575 512 }
nickjillings@1575 513 var commentQuestion = document.getElementsByClassName('commentQuestion');
nickjillings@1575 514 for (var i=0; i<commentQuestion.length; i++)
nickjillings@1575 515 {
nickjillings@1575 516 var cqHolder = document.createElement('CommentQuestion');
nickjillings@1575 517 var comment = document.createElement('comment');
nickjillings@1575 518 var question = document.createElement('question');
nickjillings@1575 519 cqHolder.id = commentQuestion[i].id;
nickjillings@1575 520 comment.textContent = commentQuestion[i].children[2].value;
nickjillings@1575 521 question.textContent = commentQuestion[i].children[0].textContent;
nickjillings@1575 522 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY
nickjillings@1575 523 cqHolder.appendChild(question);
nickjillings@1575 524 cqHolder.appendChild(comment);
nickjillings@1575 525 xmlDoc.appendChild(cqHolder);
nickjillings@1575 526 }
nickjillings@1575 527 store = xmlDoc;
nickjillings@1575 528 }