annotate ape.js @ 1584:d89a030f676e

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