nickjillings@1341: // Once this is loaded and parsed, begin execution nickjillings@1341: loadInterface(); nickjillings@1341: nickjillings@1341: function loadInterface() { nickjillings@1341: // Get the dimensions of the screen available to the page nickjillings@1341: var width = window.innerWidth; nickjillings@1341: var height = window.innerHeight; nicholas@2381: interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema nickjillings@1341: nickjillings@2110: // Custom comparator Object nickjillings@2110: Interface.prototype.comparator = null; nicholas@2359: nicholas@2359: Interface.prototype.checkScaleRange = function(min, max) { nicholas@2359: var page = testState.getCurrentTestPage(); nicholas@2359: var audioObjects = audioEngineContext.audioObjects; nicholas@2359: var state = true; nicholas@2359: var str = "Please keep listening. "; nicholas@2359: var minRanking = Infinity; nicholas@2359: var maxRanking = -Infinity; nicholas@2359: for (var ao of audioObjects) { nicholas@2359: var rank = ao.interfaceDOM.getValue(); nicholas@2359: if (rank < minRanking) {minRanking = rank;} nicholas@2359: if (rank > maxRanking) {maxRanking = rank;} nicholas@2359: } nicholas@2359: if (maxRanking*100 < max) { nicholas@2359: str += "At least one fragment must be selected." nicholas@2359: state = false; nicholas@2359: } nicholas@2359: if (!state) { nicholas@2359: console.log(str); nicholas@2359: this.storeErrorNode(str); nicholas@2362: interfaceContext.lightbox.post("Message",str); nicholas@2359: } nicholas@2359: return state; nicholas@2359: } nickjillings@1341: nickjillings@1341: // The injection point into the HTML page nickjillings@1341: interfaceContext.insertPoint = document.getElementById("topLevelBody"); nickjillings@1341: var testContent = document.createElement('div'); nickjillings@1341: testContent.id = 'testContent'; nickjillings@1341: nickjillings@1341: // Create the top div for the Title element nickjillings@1341: var titleAttr = specification.title; nickjillings@1341: var title = document.createElement('div'); nickjillings@1341: title.className = "title"; nickjillings@1341: title.align = "center"; nickjillings@1341: var titleSpan = document.createElement('span'); nickjillings@1341: nickjillings@1341: // Set title to that defined in XML, else set to default nickjillings@1341: if (titleAttr != undefined) { nickjillings@1341: titleSpan.textContent = titleAttr; nickjillings@1341: } else { nickjillings@1341: titleSpan.textContent = 'Listening test'; nickjillings@1341: } nickjillings@1341: // Insert the titleSpan element into the title div element. nickjillings@1341: title.appendChild(titleSpan); nickjillings@1341: nickjillings@1341: var pagetitle = document.createElement('div'); nickjillings@1341: pagetitle.className = "pageTitle"; nickjillings@1341: pagetitle.align = "center"; nickjillings@1341: var titleSpan = document.createElement('span'); nickjillings@1341: titleSpan.id = "pageTitle"; nickjillings@1341: pagetitle.appendChild(titleSpan); nickjillings@1341: nickjillings@1341: // Create Interface buttons! nickjillings@1341: var interfaceButtons = document.createElement('div'); nickjillings@1341: interfaceButtons.id = 'interface-buttons'; nickjillings@1341: interfaceButtons.style.height = '25px'; nickjillings@1341: nickjillings@1341: // Create playback start/stop points nickjillings@1341: var playback = document.createElement("button"); nickjillings@1341: playback.innerHTML = 'Stop'; nickjillings@1341: playback.id = 'playback-button'; nickjillings@1341: playback.style.float = 'left'; nickjillings@1341: // onclick function. Check if it is playing or not, call the correct function in the nickjillings@1341: // audioEngine, change the button text to reflect the next state. nickjillings@1341: playback.onclick = function() { nickjillings@1341: if (audioEngineContext.status == 1) { nickjillings@1341: audioEngineContext.stop(); nickjillings@1341: this.innerHTML = 'Stop'; nickjillings@1341: var time = audioEngineContext.timer.getTestTime(); nickjillings@1341: console.log('Stopped at ' + time); // DEBUG/SAFETY nickjillings@1341: } nickjillings@1341: }; nickjillings@1341: // Append the interface buttons into the interfaceButtons object. nickjillings@1341: interfaceButtons.appendChild(playback); nickjillings@1341: nickjillings@1341: // Global parent for the comment boxes on the page nickjillings@1341: var feedbackHolder = document.createElement('div'); nickjillings@1341: feedbackHolder.id = 'feedbackHolder'; nickjillings@1341: nickjillings@1341: // Construct the AB Boxes nickjillings@1341: var boxes = document.createElement('div'); nickjillings@1341: boxes.align = "center"; nickjillings@1341: boxes.id = "box-holders"; nickjillings@1341: boxes.style.float = "left"; nickjillings@1341: nickjillings@1341: var submit = document.createElement('button'); nickjillings@1341: submit.id = "submit"; nickjillings@1341: submit.onclick = buttonSubmitClick; nickjillings@1341: submit.className = "big-button"; nickjillings@1341: submit.textContent = "submit"; nickjillings@1341: submit.style.position = "relative"; nickjillings@1341: submit.style.left = (window.innerWidth-250)/2 + 'px'; nickjillings@1341: nickjillings@1341: feedbackHolder.appendChild(boxes); nickjillings@1341: nickjillings@1341: // Inject into HTML nickjillings@1341: testContent.appendChild(title); // Insert the title nickjillings@1341: testContent.appendChild(pagetitle); nickjillings@1341: testContent.appendChild(interfaceButtons); nickjillings@1341: testContent.appendChild(feedbackHolder); nickjillings@1341: testContent.appendChild(submit); nickjillings@1341: interfaceContext.insertPoint.appendChild(testContent); nickjillings@1341: nickjillings@1341: // Load the full interface nickjillings@1341: testState.initialise(); nickjillings@1341: testState.advanceState(); nickjillings@1341: } nickjillings@1341: nickjillings@1341: function loadTest(audioHolderObject) nickjillings@1341: { nickjillings@1341: var feedbackHolder = document.getElementById('feedbackHolder'); nickjillings@1341: var interfaceObj = audioHolderObject.interfaces; nickjillings@1341: if (interfaceObj.length > 1) nickjillings@1341: { nickjillings@1341: console.log("WARNING - This interface only supports one node per page. Using first interface node"); nickjillings@1341: } nickjillings@1341: interfaceObj = interfaceObj[0]; nicholas@2392: nicholas@2392: // Clear any outside references nicholas@2392: var outsideReferences = document.getElementsByName("outside-reference"); nicholas@2392: for (var i=0; i'; nickjillings@1356: break; nickjillings@1356: case "volume": nicholas@2394: if (document.getElementById('master-volume-holder-float') == null) nickjillings@1356: { nickjillings@1356: feedbackHolder.appendChild(interfaceContext.volume.object); nickjillings@1356: } nickjillings@1356: break; nickjillings@1356: } nickjillings@1356: } nickjillings@1356: } nickjillings@1341: nickjillings@2110: // Populate the comparator object nickjillings@2110: interfaceContext.comparator = new comparator(audioHolderObject); nickjillings@1316: if (audioHolderObject.showElementComments) nickjillings@1316: { nickjillings@1316: var commentHolder = document.createElement('div'); nickjillings@1316: commentHolder.id = 'commentHolder'; nickjillings@1316: document.getElementById('testContent').appendChild(commentHolder); nickjillings@1316: // Generate one comment box per presented page nickjillings@1316: for (var element of audioEngineContext.audioObjects) nickjillings@1316: { nickjillings@2117: interfaceContext.commentBoxes.createCommentBox(element); nickjillings@1316: } nickjillings@2117: interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true); nickjillings@1316: } nickjillings@1341: resizeWindow(null); nicholas@2356: nicholas@2356: $(audioHolderObject.commentQuestions).each(function(index,element) { nicholas@2356: var node = interfaceContext.createCommentQuestion(element); nicholas@2356: commentHolder.appendChild(node.holder); nicholas@2356: }); nickjillings@1341: } nickjillings@1341: nickjillings@2110: function comparator(audioHolderObject) nickjillings@1341: { nickjillings@2110: this.comparatorBox = function(audioElement,id,text) nickjillings@1341: { nickjillings@1341: this.parent = audioElement; nickjillings@1341: this.id = id; nickjillings@1341: this.value = 0; nickjillings@1341: this.disabled = true; nickjillings@1341: this.box = document.createElement('div'); nickjillings@2110: this.box.className = 'comparator-holder'; nickjillings@1341: this.box.setAttribute('track-id',audioElement.id); nickjillings@2110: this.box.id = 'comparator-'+text; nickjillings@1341: this.selector = document.createElement('div'); nickjillings@2110: this.selector.className = 'comparator-selector disabled'; nickjillings@1341: var selectorText = document.createElement('span'); nickjillings@1341: selectorText.textContent = text; nickjillings@1341: this.selector.appendChild(selectorText); nickjillings@1341: this.playback = document.createElement('button'); nickjillings@2110: this.playback.className = 'comparator-button'; nickjillings@1341: this.playback.disabled = true; nickjillings@1341: this.playback.textContent = "Listen"; nickjillings@1341: this.box.appendChild(this.selector); nickjillings@1341: this.box.appendChild(this.playback); nickjillings@1349: this.selector.onclick = function(event) nickjillings@1341: { nickjillings@1341: var time = audioEngineContext.timer.getTestTime(); nickjillings@1341: if ($(event.currentTarget).hasClass('disabled')) nickjillings@1341: { nickjillings@1341: console.log("Please wait until sample has loaded"); nickjillings@1341: return; nickjillings@1341: } nickjillings@1341: if (audioEngineContext.status == 0) nickjillings@1341: { nicholas@2362: interfaceContext.lightbox.post("Message","Please listen to the samples before making a selection"); nickjillings@1341: console.log("Please listen to the samples before making a selection"); nickjillings@1341: return; nickjillings@2112: } nickjillings@1341: var id = event.currentTarget.parentElement.getAttribute('track-id'); nickjillings@2110: interfaceContext.comparator.selected = id; nickjillings@2112: if ($(event.currentTarget).hasClass("selected")) { nickjillings@2112: $(".comparator-selector").removeClass('selected'); nickjillings@2112: for (var i=0; i saves nickjillings@1341: // Get the current information in store (remember to appendChild your data to it) nickjillings@1341: // pageSpecification is the current page node configuration nickjillings@1341: // To create new XML nodes, use storage.document.createElement(); nickjillings@1341: }