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