n@1253: /** n@1253: * WAET Blank Template n@1253: * Use this to start building your custom interface n@1253: */ n@1253: n@1253: // Once this is loaded and parsed, begin execution n@1253: loadInterface(); n@1253: n@1253: function loadInterface() { n@1253: // Use this to do any one-time page / element construction. For instance, placing any stationary text objects, n@1253: // holding div's, or setting up any nodes which are present for the entire test sequence n@1253: n@1253: // Custom comparator Object n@1253: Interface.prototype.comparator = null; n@1253: n@1253: // The injection point into the HTML page n@1253: interfaceContext.insertPoint = document.getElementById("topLevelBody"); n@1253: var testContent = document.createElement('div'); n@1253: testContent.id = 'testContent'; n@1253: n@1253: // Create the top div for the Title element n@1253: var titleAttr = specification.title; n@1253: var title = document.createElement('div'); n@1253: title.className = "title"; n@1253: title.align = "center"; n@1253: var titleSpan = document.createElement('span'); n@1253: n@1253: // Set title to that defined in XML, else set to default n@1253: if (titleAttr != undefined) { n@1253: titleSpan.textContent = titleAttr; n@1253: } else { n@1253: titleSpan.textContent = 'Listening test'; n@1253: } n@1253: // Insert the titleSpan element into the title div element. n@1253: title.appendChild(titleSpan); n@1253: n@1253: var pagetitle = document.createElement('div'); n@1253: pagetitle.className = "pageTitle"; n@1253: pagetitle.align = "center"; n@1253: var titleSpan = document.createElement('span'); n@1253: titleSpan.id = "pageTitle"; n@1253: pagetitle.appendChild(titleSpan); n@1253: n@1253: // Create Interface buttons! n@1253: var interfaceButtons = document.createElement('div'); n@1253: interfaceButtons.id = 'interface-buttons'; n@1253: interfaceButtons.style.height = '25px'; n@1253: n@1253: // Create playback start/stop points n@1253: var playback = document.createElement("button"); n@1253: playback.innerHTML = 'Stop'; n@1253: playback.id = 'playback-button'; n@1253: playback.style.float = 'left'; n@1253: // onclick function. Check if it is playing or not, call the correct function in the n@1253: // audioEngine, change the button text to reflect the next state. n@1253: playback.onclick = function() { n@1253: if (audioEngineContext.status == 1) { n@1253: audioEngineContext.stop(); n@1253: this.innerHTML = 'Stop'; n@1253: var time = audioEngineContext.timer.getTestTime(); n@1253: console.log('Stopped at ' + time); // DEBUG/SAFETY n@1253: } n@1253: }; n@1253: // Append the interface buttons into the interfaceButtons object. n@1253: interfaceButtons.appendChild(playback); n@1253: n@1253: // Global parent for the comment boxes on the page n@1253: var feedbackHolder = document.createElement('div'); n@1253: feedbackHolder.id = 'feedbackHolder'; n@1253: n@1253: // Construct the AB Boxes n@1253: var boxes = document.createElement('div'); n@1253: boxes.align = "center"; n@1253: boxes.id = "box-holders"; n@1253: boxes.style.float = "left"; n@1253: n@1253: var submit = document.createElement('button'); n@1253: submit.id = "submit"; n@1253: submit.onclick = buttonSubmitClick; n@1253: submit.className = "big-button"; n@1253: submit.textContent = "submit"; n@1253: submit.style.position = "relative"; n@1253: submit.style.left = (window.innerWidth-250)/2 + 'px'; n@1253: n@1253: feedbackHolder.appendChild(boxes); n@1253: n@1253: // Inject into HTML n@1253: testContent.appendChild(title); // Insert the title n@1253: testContent.appendChild(pagetitle); n@1253: testContent.appendChild(interfaceButtons); n@1253: testContent.appendChild(feedbackHolder); n@1253: testContent.appendChild(submit); n@1253: interfaceContext.insertPoint.appendChild(testContent); n@1253: n@1253: // Load the full interface n@1253: testState.initialise(); n@1253: testState.advanceState(); n@1253: }; n@1253: n@1253: function loadTest(page) n@1253: { n@1253: // Called each time a new test page is to be build. The page specification node is the only item passed in n@1253: interfaceContext.comparator = new comparator(page); n@1253: } n@1253: n@1253: function comparator(page) n@1253: { n@1253: // Build prototype constructor n@1253: this.interfaceObject = function(element,label) n@1253: { n@1253: // An example node, you can make this however you want for each audioElement. n@1253: // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following n@1253: // You attach them by calling audioObject.bindInterface( ) n@1253: this.parent = element; n@1253: this.id = element.id; n@1253: this.value = 0; n@1253: this.disabled = true; n@1253: this.box = document.createElement('div'); n@1253: this.box.className = 'comparator-holder'; n@1253: this.box.setAttribute('track-id',element.id); n@1253: this.box.id = 'comparator-'+label; n@1253: this.selector = document.createElement('div'); n@1253: this.selector.className = 'comparator-selector disabled'; n@1253: var selectorText = document.createElement('span'); n@1253: selectorText.textContent = label; n@1253: this.selector.appendChild(selectorText); n@1253: this.playback = document.createElement('button'); n@1253: this.playback.className = 'comparator-button'; n@1253: this.playback.disabled = true; n@1253: this.playback.textContent = "Listen"; n@1253: this.box.appendChild(this.selector); n@1253: this.box.appendChild(this.playback); n@1253: this.selector.onclick = function(event) n@1253: { n@1253: var label = event.currentTarget.children[0].textContent; n@1253: if (label == "X" || label == "x") {return;} n@1253: var time = audioEngineContext.timer.getTestTime(); n@1253: if ($(event.currentTarget).hasClass('disabled')) n@1253: { n@1253: console.log("Please wait until sample has loaded"); n@1253: return; n@1253: } n@1253: if (audioEngineContext.status == 0) n@1253: { n@1253: alert("Please listen to the samples before making a selection"); n@1253: console.log("Please listen to the samples before making a selection"); n@1253: return; n@1253: } n@1253: var id = event.currentTarget.parentElement.getAttribute('track-id'); n@1253: interfaceContext.comparator.selected = id; n@1253: if ($(event.currentTarget).hasClass("selected")) { n@1253: $(".comparator-selector").removeClass('selected'); n@1253: for (var i=0; i node. n@1253: // If there is no value node (such as outside reference), return null n@1253: // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute n@1253: // Use storage.document.createElement('value'); to generate the XML node. n@1253: var node = storage.document.createElement('value'); n@1253: node.textContent = this.value; n@1253: return node; n@1253: n@1253: }; n@1253: this.error = function() { n@1253: // If there is an error with the audioObject, this will be called to indicate a failure n@1253: } n@1253: }; n@1253: // Ensure there are only two comparisons per page n@1253: if (page.audioElements.length != 2) { n@1253: console.error('FATAL - There must be 2 nodes on each : '+page.id); n@1253: return; n@1253: } n@1253: // Build the three audio elements n@1253: this.pair = []; n@1253: this.X = null; n@1253: this.boxHolders = document.getElementById('box-holders'); n@1253: for (var index=0; index saves n@1253: // Get the current information in store (remember to appendChild your data to it) n@1253: // pageSpecification is the current page node configuration n@1253: // To create new XML nodes, use storage.document.createElement(); n@1253: }