djmoffat@1099: // Once this is loaded and parsed, begin execution djmoffat@1099: loadInterface(); djmoffat@1099: djmoffat@1099: function loadInterface() { djmoffat@1099: // Get the dimensions of the screen available to the page djmoffat@1099: var width = window.innerWidth; djmoffat@1099: var height = window.innerHeight; djmoffat@1099: interfaceContext.insertPoint.innerHTML = null; // Clear the current schema djmoffat@1099: n@1102: // Custom comparator Object n@1102: Interface.prototype.comparator = null; djmoffat@1099: djmoffat@1099: // The injection point into the HTML page djmoffat@1099: interfaceContext.insertPoint = document.getElementById("topLevelBody"); djmoffat@1099: var testContent = document.createElement('div'); djmoffat@1099: testContent.id = 'testContent'; djmoffat@1099: djmoffat@1099: // Create the top div for the Title element djmoffat@1099: var titleAttr = specification.title; djmoffat@1099: var title = document.createElement('div'); djmoffat@1099: title.className = "title"; djmoffat@1099: title.align = "center"; djmoffat@1099: var titleSpan = document.createElement('span'); djmoffat@1099: djmoffat@1099: // Set title to that defined in XML, else set to default djmoffat@1099: if (titleAttr != undefined) { djmoffat@1099: titleSpan.textContent = titleAttr; djmoffat@1099: } else { djmoffat@1099: titleSpan.textContent = 'Listening test'; djmoffat@1099: } djmoffat@1099: // Insert the titleSpan element into the title div element. djmoffat@1099: title.appendChild(titleSpan); djmoffat@1099: djmoffat@1099: var pagetitle = document.createElement('div'); djmoffat@1099: pagetitle.className = "pageTitle"; djmoffat@1099: pagetitle.align = "center"; djmoffat@1099: var titleSpan = document.createElement('span'); djmoffat@1099: titleSpan.id = "pageTitle"; djmoffat@1099: pagetitle.appendChild(titleSpan); djmoffat@1099: djmoffat@1099: // Create Interface buttons! djmoffat@1099: var interfaceButtons = document.createElement('div'); djmoffat@1099: interfaceButtons.id = 'interface-buttons'; djmoffat@1099: interfaceButtons.style.height = '25px'; djmoffat@1099: djmoffat@1099: // Create playback start/stop points djmoffat@1099: var playback = document.createElement("button"); djmoffat@1099: playback.innerHTML = 'Stop'; djmoffat@1099: playback.id = 'playback-button'; djmoffat@1099: playback.style.float = 'left'; djmoffat@1099: // onclick function. Check if it is playing or not, call the correct function in the djmoffat@1099: // audioEngine, change the button text to reflect the next state. djmoffat@1099: playback.onclick = function() { djmoffat@1099: if (audioEngineContext.status == 1) { djmoffat@1099: audioEngineContext.stop(); djmoffat@1099: this.innerHTML = 'Stop'; djmoffat@1099: var time = audioEngineContext.timer.getTestTime(); djmoffat@1099: console.log('Stopped at ' + time); // DEBUG/SAFETY djmoffat@1099: } djmoffat@1099: }; djmoffat@1099: // Append the interface buttons into the interfaceButtons object. djmoffat@1099: interfaceButtons.appendChild(playback); djmoffat@1099: djmoffat@1099: // Global parent for the comment boxes on the page djmoffat@1099: var feedbackHolder = document.createElement('div'); djmoffat@1099: feedbackHolder.id = 'feedbackHolder'; djmoffat@1099: djmoffat@1099: // Construct the AB Boxes djmoffat@1099: var boxes = document.createElement('div'); djmoffat@1099: boxes.align = "center"; djmoffat@1099: boxes.id = "box-holders"; djmoffat@1099: boxes.style.float = "left"; djmoffat@1099: djmoffat@1099: var submit = document.createElement('button'); djmoffat@1099: submit.id = "submit"; djmoffat@1099: submit.onclick = buttonSubmitClick; djmoffat@1099: submit.className = "big-button"; djmoffat@1099: submit.textContent = "submit"; djmoffat@1099: submit.style.position = "relative"; djmoffat@1099: submit.style.left = (window.innerWidth-250)/2 + 'px'; djmoffat@1099: djmoffat@1099: feedbackHolder.appendChild(boxes); djmoffat@1099: djmoffat@1099: // Inject into HTML djmoffat@1099: testContent.appendChild(title); // Insert the title djmoffat@1099: testContent.appendChild(pagetitle); djmoffat@1099: testContent.appendChild(interfaceButtons); djmoffat@1099: testContent.appendChild(feedbackHolder); djmoffat@1099: testContent.appendChild(submit); djmoffat@1099: interfaceContext.insertPoint.appendChild(testContent); djmoffat@1099: djmoffat@1099: // Load the full interface djmoffat@1099: testState.initialise(); djmoffat@1099: testState.advanceState(); djmoffat@1099: } djmoffat@1099: djmoffat@1099: function loadTest(audioHolderObject) djmoffat@1099: { djmoffat@1099: var feedbackHolder = document.getElementById('feedbackHolder'); djmoffat@1099: var interfaceObj = audioHolderObject.interfaces; djmoffat@1099: if (interfaceObj.length > 1) djmoffat@1099: { djmoffat@1099: console.log("WARNING - This interface only supports one node per page. Using first interface node"); djmoffat@1099: } djmoffat@1099: interfaceObj = interfaceObj[0]; djmoffat@1099: djmoffat@1099: if(interfaceObj.title != null) djmoffat@1099: { djmoffat@1099: document.getElementById("pageTitle").textContent = interfaceObj.title; djmoffat@1099: } djmoffat@1099: djmoffat@1099: var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options); djmoffat@1099: for (var option of interfaceOptions) djmoffat@1099: { djmoffat@1099: if (option.type == "show") djmoffat@1099: { djmoffat@1099: switch(option.name) { djmoffat@1099: case "playhead": djmoffat@1099: var playbackHolder = document.getElementById('playback-holder'); djmoffat@1099: if (playbackHolder == null) djmoffat@1099: { djmoffat@1099: playbackHolder = document.createElement('div'); djmoffat@1099: playbackHolder.style.width = "100%"; djmoffat@1099: playbackHolder.style.float = "left"; djmoffat@1099: playbackHolder.align = 'center'; djmoffat@1099: playbackHolder.appendChild(interfaceContext.playhead.object); djmoffat@1099: feedbackHolder.appendChild(playbackHolder); djmoffat@1099: } djmoffat@1099: break; djmoffat@1099: case "page-count": djmoffat@1099: var pagecountHolder = document.getElementById('page-count'); djmoffat@1099: if (pagecountHolder == null) djmoffat@1099: { djmoffat@1099: pagecountHolder = document.createElement('div'); djmoffat@1099: pagecountHolder.id = 'page-count'; djmoffat@1099: } n@1102: pagecountHolder.innerHTML = 'Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+''; djmoffat@1099: var inject = document.getElementById('interface-buttons'); djmoffat@1099: inject.appendChild(pagecountHolder); djmoffat@1099: break; djmoffat@1099: case "volume": djmoffat@1099: if (document.getElementById('master-volume-holder') == null) djmoffat@1099: { djmoffat@1099: feedbackHolder.appendChild(interfaceContext.volume.object); djmoffat@1099: } djmoffat@1099: break; djmoffat@1099: } djmoffat@1099: } djmoffat@1099: } djmoffat@1099: n@1102: // Populate the comparator object n@1102: interfaceContext.comparator = new comparator(audioHolderObject); djmoffat@1099: if (audioHolderObject.showElementComments) djmoffat@1099: { djmoffat@1099: var commentHolder = document.createElement('div'); djmoffat@1099: commentHolder.id = 'commentHolder'; djmoffat@1099: document.getElementById('testContent').appendChild(commentHolder); djmoffat@1099: // Generate one comment box per presented page djmoffat@1099: for (var element of audioEngineContext.audioObjects) djmoffat@1099: { n@1102: interfaceContext.commentBoxes.createCommentBox(element); djmoffat@1099: } n@1102: interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true); djmoffat@1099: } djmoffat@1099: resizeWindow(null); djmoffat@1099: } djmoffat@1099: n@1102: function comparator(audioHolderObject) djmoffat@1099: { n@1102: this.comparatorBox = function(audioElement,id,text) djmoffat@1099: { djmoffat@1099: this.parent = audioElement; djmoffat@1099: this.id = id; djmoffat@1099: this.value = 0; djmoffat@1099: this.disabled = true; djmoffat@1099: this.box = document.createElement('div'); n@1102: this.box.className = 'comparator-holder'; djmoffat@1099: this.box.setAttribute('track-id',audioElement.id); n@1102: this.box.id = 'comparator-'+text; djmoffat@1099: this.selector = document.createElement('div'); n@1102: this.selector.className = 'comparator-selector disabled'; djmoffat@1099: var selectorText = document.createElement('span'); djmoffat@1099: selectorText.textContent = text; djmoffat@1099: this.selector.appendChild(selectorText); djmoffat@1099: this.playback = document.createElement('button'); n@1102: this.playback.className = 'comparator-button'; djmoffat@1099: this.playback.disabled = true; djmoffat@1099: this.playback.textContent = "Listen"; djmoffat@1099: this.box.appendChild(this.selector); djmoffat@1099: this.box.appendChild(this.playback); djmoffat@1099: this.selector.onclick = function(event) djmoffat@1099: { djmoffat@1099: var time = audioEngineContext.timer.getTestTime(); djmoffat@1099: if ($(event.currentTarget).hasClass('disabled')) djmoffat@1099: { djmoffat@1099: console.log("Please wait until sample has loaded"); djmoffat@1099: return; djmoffat@1099: } djmoffat@1099: if (audioEngineContext.status == 0) djmoffat@1099: { djmoffat@1099: alert("Please listen to the samples before making a selection"); djmoffat@1099: console.log("Please listen to the samples before making a selection"); djmoffat@1099: return; n@1102: } djmoffat@1099: var id = event.currentTarget.parentElement.getAttribute('track-id'); n@1102: interfaceContext.comparator.selected = id; n@1102: if ($(event.currentTarget).hasClass("selected")) { n@1102: $(".comparator-selector").removeClass('selected'); n@1102: for (var i=0; i saves djmoffat@1099: // Get the current information in store (remember to appendChild your data to it) djmoffat@1099: // pageSpecification is the current page node configuration djmoffat@1099: // To create new XML nodes, use storage.document.createElement(); djmoffat@1099: }