annotate ape.js @ 3:1b01b7443a46

ape.js now creates text boxes for user feedback per channel.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Sun, 08 Mar 2015 19:53:47 +0000
parents 955d229b8a02
children 4766f485a1b0
rev   line source
nicholas@2 1 /**
nicholas@2 2 * ape.js
nicholas@2 3 * Create the APE interface
nicholas@2 4 */
nicholas@2 5
nicholas@2 6 // Once this is loaded and parsed, begin execution
nicholas@2 7 loadInterface(projectXML);
nicholas@2 8
nicholas@2 9 function loadInterface(xmlDoc) {
nicholas@2 10
nicholas@2 11 var width = window.innerWidth;
nicholas@2 12 var height = window.innerHeight;
nicholas@2 13
nicholas@2 14 // Set background to grey #ddd
nicholas@2 15 document.getElementsByTagName('body')[0].style.backgroundColor = '#ddd';
nicholas@2 16
nicholas@2 17 // The injection point into the HTML page
nicholas@2 18 var insertPoint = document.getElementById("topLevelBody");
nicholas@2 19
nicholas@2 20 // Decode parts of the xmlDoc that are needed
nicholas@2 21 // xmlDoc MUST already be parsed by jQuery!
nicholas@2 22 var xmlSetup = xmlDoc.find('setup');
nicholas@2 23 // Should put in an error function here incase of malprocessed or malformed XML
nicholas@2 24
nicholas@2 25 // Create the top div for the Title element
nicholas@2 26 var titleAttr = xmlSetup[0].attributes['title'];
nicholas@2 27 var title = document.createElement('div');
nicholas@2 28 title.className = "title";
nicholas@2 29 title.align = "center";
nicholas@2 30 var titleSpan = document.createElement('span');
nicholas@2 31
nicholas@2 32 // Set title to that defined in XML, else set to default
nicholas@2 33 if (titleAttr != undefined) {
nicholas@2 34 titleSpan.innerText = titleAttr.value;
nicholas@2 35 } else {
nicholas@2 36 titleSpan.innerText = 'APE Tool';
nicholas@2 37 }
nicholas@2 38 // Insert the titleSpan element into the title div element.
nicholas@2 39 title.appendChild(titleSpan);
nicholas@2 40
nicholas@2 41 // Now create the slider and HTML5 canvas boxes
nicholas@2 42
nicholas@2 43 var sliderBox = document.createElement('div');
nicholas@2 44 sliderBox.className = 'sliderCanvasDiv';
nicholas@2 45 sliderBox.id = 'sliderCanvasHolder'; // create an id so we can easily link to it later
nicholas@2 46 sliderBox.align = 'center';
nicholas@2 47
nicholas@2 48 var canvas = document.createElement('canvas');
nicholas@2 49 canvas.id = 'slider';
nicholas@2 50 canvas.width = width - 100;
nicholas@2 51 canvas.height = 150;
nicholas@2 52 canvas.style.backgroundColor = '#eee';
nicholas@2 53
nicholas@2 54 sliderBox.appendChild(canvas);
nicholas@2 55
nicholas@3 56 var feedbackHolder = document.createElement('div');
nicholas@3 57
nicholas@3 58 var tracksXML = xmlDoc.find('track');
nicholas@3 59 tracksXML.each(function(index,element){
nicholas@3 60 var trackObj = document.createElement('div');
nicholas@3 61 var trackTitle = document.createElement('span');
nicholas@3 62 trackTitle.innerText = 'Comment on track '+index;
nicholas@3 63 var trackComment = document.createElement('textarea');
nicholas@3 64 trackComment.rows = '4';
nicholas@3 65 trackComment.cols = '100';
nicholas@3 66 trackComment.name = 'trackComment'+index;
nicholas@3 67 trackComment.className = 'trackComment';
nicholas@3 68 feedbackHolder.appendChild(trackTitle);
nicholas@3 69 feedbackHolder.appendChild(trackComment);
nicholas@3 70 feedbackHolder.appendChild(trackObj);
nicholas@3 71 })
nicholas@3 72
nicholas@2 73
nicholas@2 74 // Inject into HTML
nicholas@2 75 insertPoint.innerHTML = null; // Clear the current schema
nicholas@2 76 insertPoint.appendChild(title); // Insert the title
nicholas@2 77 insertPoint.appendChild(sliderBox);
nicholas@3 78 insertPoint.appendChild(feedbackHolder);
nicholas@2 79 }