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