annotate interfaces/ape.js @ 2621:702b5944f782

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