nicholas@2: /** nicholas@2: * ape.js nicholas@2: * Create the APE interface nicholas@2: */ nicholas@2: nicholas@2: // Once this is loaded and parsed, begin execution nicholas@2: loadInterface(projectXML); nicholas@2: nicholas@2: function loadInterface(xmlDoc) { nicholas@2: nicholas@2: var width = window.innerWidth; nicholas@2: var height = window.innerHeight; nicholas@2: nicholas@2: // Set background to grey #ddd nicholas@2: document.getElementsByTagName('body')[0].style.backgroundColor = '#ddd'; nicholas@2: nicholas@2: // The injection point into the HTML page nicholas@2: var insertPoint = document.getElementById("topLevelBody"); nicholas@2: nicholas@2: // Decode parts of the xmlDoc that are needed nicholas@2: // xmlDoc MUST already be parsed by jQuery! nicholas@2: var xmlSetup = xmlDoc.find('setup'); nicholas@2: // Should put in an error function here incase of malprocessed or malformed XML nicholas@2: nicholas@2: // Create the top div for the Title element nicholas@2: var titleAttr = xmlSetup[0].attributes['title']; nicholas@2: var title = document.createElement('div'); nicholas@2: title.className = "title"; nicholas@2: title.align = "center"; nicholas@2: var titleSpan = document.createElement('span'); nicholas@2: nicholas@2: // Set title to that defined in XML, else set to default nicholas@2: if (titleAttr != undefined) { nicholas@2: titleSpan.innerText = titleAttr.value; nicholas@2: } else { nicholas@2: titleSpan.innerText = 'APE Tool'; nicholas@2: } nicholas@2: // Insert the titleSpan element into the title div element. nicholas@2: title.appendChild(titleSpan); nicholas@2: nicholas@2: // Now create the slider and HTML5 canvas boxes nicholas@2: nicholas@2: var sliderBox = document.createElement('div'); nicholas@2: sliderBox.className = 'sliderCanvasDiv'; nicholas@2: sliderBox.id = 'sliderCanvasHolder'; // create an id so we can easily link to it later nicholas@2: sliderBox.align = 'center'; nicholas@2: nicholas@2: var canvas = document.createElement('canvas'); nicholas@2: canvas.id = 'slider'; nicholas@2: canvas.width = width - 100; nicholas@2: canvas.height = 150; nicholas@2: canvas.style.backgroundColor = '#eee'; nicholas@2: nicholas@2: sliderBox.appendChild(canvas); nicholas@2: nicholas@3: var feedbackHolder = document.createElement('div'); nicholas@3: nicholas@3: var tracksXML = xmlDoc.find('track'); nicholas@3: tracksXML.each(function(index,element){ nicholas@3: var trackObj = document.createElement('div'); nicholas@3: var trackTitle = document.createElement('span'); nicholas@3: trackTitle.innerText = 'Comment on track '+index; nicholas@3: var trackComment = document.createElement('textarea'); nicholas@3: trackComment.rows = '4'; nicholas@3: trackComment.cols = '100'; nicholas@3: trackComment.name = 'trackComment'+index; nicholas@3: trackComment.className = 'trackComment'; nicholas@3: feedbackHolder.appendChild(trackTitle); nicholas@3: feedbackHolder.appendChild(trackComment); nicholas@3: feedbackHolder.appendChild(trackObj); nicholas@3: }) nicholas@3: nicholas@2: nicholas@2: // Inject into HTML nicholas@2: insertPoint.innerHTML = null; // Clear the current schema nicholas@2: insertPoint.appendChild(title); // Insert the title nicholas@2: insertPoint.appendChild(sliderBox); nicholas@3: insertPoint.appendChild(feedbackHolder); nicholas@2: }