annotate ape.js @ 1563:4730207bcae0

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