nickjillings@1341: /** nickjillings@1341: * mushra.js nickjillings@1341: * Create the MUSHRA interface nickjillings@1341: */ nicholas@2701: /*globals window, interfaceContext, document, $, specification, audioEngineContext, console, testState, storage */ nickjillings@1341: // Once this is loaded and parsed, begin execution nickjillings@1341: loadInterface(); nickjillings@1341: nickjillings@1341: function loadInterface() { nicholas@2538: // Get the dimensions of the screen available to the page nicholas@2538: var width = window.innerWidth; nicholas@2538: var height = window.innerHeight; nicholas@2538: nicholas@2538: // The injection point into the HTML page nicholas@2538: interfaceContext.insertPoint = document.getElementById("topLevelBody"); nicholas@2538: var testContent = document.createElement('div'); nicholas@2538: testContent.id = 'testContent'; nicholas@2538: nicholas@2538: // Create the top div for the Title element nicholas@2538: var titleAttr = specification.title; nicholas@2538: var title = document.createElement('div'); nicholas@2538: title.className = "title"; nicholas@2538: title.align = "center"; nicholas@2538: var titleSpan = document.createElement('span'); nicholas@2470: titleSpan.id = "test-title"; nicholas@2538: nicholas@2538: // Set title to that defined in XML, else set to default nicholas@2701: if (titleAttr !== undefined) { nicholas@2538: titleSpan.textContent = titleAttr; nicholas@2538: } else { nicholas@2538: titleSpan.textContent = 'Listening test'; nicholas@2538: } nicholas@2538: // Insert the titleSpan element into the title div element. nicholas@2538: title.appendChild(titleSpan); nicholas@2538: nicholas@2538: var pagetitle = document.createElement('div'); nicholas@2538: pagetitle.className = "pageTitle"; nicholas@2538: pagetitle.align = "center"; nicholas@2701: nicholas@2701: titleSpan = document.createElement('span'); nicholas@2538: titleSpan.id = "pageTitle"; nicholas@2538: pagetitle.appendChild(titleSpan); nicholas@2538: nicholas@2538: // Create Interface buttons! nicholas@2538: var interfaceButtons = document.createElement('div'); nicholas@2538: interfaceButtons.id = 'interface-buttons'; nicholas@2538: interfaceButtons.style.height = '25px'; nicholas@2538: nicholas@2538: // Create playback start/stop points nicholas@2538: var playback = document.createElement("button"); nicholas@2538: playback.innerHTML = 'Stop'; nicholas@2538: playback.id = 'playback-button'; nicholas@2850: playback.style.display = 'inline-block'; nicholas@2538: // onclick function. Check if it is playing or not, call the correct function in the nicholas@2538: // audioEngine, change the button text to reflect the next state. nicholas@2538: playback.onclick = function () { nicholas@2538: if (audioEngineContext.status == 1) { nicholas@2538: audioEngineContext.stop(); nicholas@2538: this.innerHTML = 'Stop'; nickjillings@1341: var time = audioEngineContext.timer.getTestTime(); nickjillings@1341: console.log('Stopped at ' + time); // DEBUG/SAFETY nicholas@2538: } nicholas@2538: }; nicholas@2538: // Create Submit (save) button nicholas@2538: var submit = document.createElement("button"); nicholas@2538: submit.innerHTML = 'Next'; nicholas@2538: submit.onclick = buttonSubmitClick; nicholas@2538: submit.id = 'submit-button'; nicholas@2850: submit.style.display = 'inline-block'; n@3006: n@3006: // Create the sort button n@3006: var sort = document.createElement("button"); n@3006: sort.id = "sort-fragments"; n@3006: sort.textContent = "Sort"; n@3006: sort.style.display = "inline-block"; n@3006: sort.style.visibility = "hidden"; n@3006: sort.onclick = buttonSortFragmentClick; n@3006: nicholas@2538: // Append the interface buttons into the interfaceButtons object. nicholas@2538: interfaceButtons.appendChild(playback); nicholas@2538: interfaceButtons.appendChild(submit); n@3006: interfaceButtons.appendChild(sort); n@3006: nicholas@2538: nicholas@2395: // Create outside reference holder nicholas@2395: var outsideRef = document.createElement("div"); nicholas@2395: outsideRef.id = "outside-reference-holder"; nicholas@2538: nicholas@2538: nicholas@2538: // Create a slider box nicholas@2538: var sliderBox = document.createElement('div'); nicholas@2538: sliderBox.style.width = "100%"; nicholas@2538: sliderBox.style.height = window.innerHeight - 200 + 12 + 'px'; nicholas@2538: sliderBox.style.marginBottom = '10px'; nicholas@2538: sliderBox.id = 'slider'; nicholas@2538: var scaleHolder = document.createElement('div'); nicholas@2538: scaleHolder.id = "scale-holder"; nicholas@2538: sliderBox.appendChild(scaleHolder); nicholas@2538: var scaleText = document.createElement('div'); nicholas@2538: scaleText.id = "scale-text-holder"; nicholas@2538: scaleHolder.appendChild(scaleText); nicholas@2538: var scaleCanvas = document.createElement('canvas'); nicholas@2538: scaleCanvas.id = "scale-canvas"; nicholas@2538: scaleHolder.appendChild(scaleCanvas); nicholas@2538: var sliderObjectHolder = document.createElement('div'); nicholas@2538: sliderObjectHolder.id = 'slider-holder'; nicholas@2538: sliderObjectHolder.align = "center"; nicholas@2538: sliderBox.appendChild(sliderObjectHolder); nicholas@2538: nicholas@2538: // Global parent for the comment boxes on the page nicholas@2538: var feedbackHolder = document.createElement('div'); nicholas@2538: feedbackHolder.id = 'feedbackHolder'; nicholas@2538: nicholas@2538: testContent.style.zIndex = 1; nicholas@2538: interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema nicholas@2538: nicholas@2538: // Inject into HTML nicholas@2538: testContent.appendChild(title); // Insert the title nicholas@2538: testContent.appendChild(pagetitle); nicholas@2538: testContent.appendChild(interfaceButtons); nicholas@2395: testContent.appendChild(outsideRef); nicholas@2538: testContent.appendChild(sliderBox); nicholas@2538: testContent.appendChild(feedbackHolder); nicholas@2538: interfaceContext.insertPoint.appendChild(testContent); nickjillings@1341: nicholas@2538: // Load the full interface nicholas@2538: testState.initialise(); nicholas@2538: testState.advanceState(); nickjillings@1341: } nickjillings@1341: nicholas@2538: function loadTest(audioHolderObject) { nicholas@2538: var id = audioHolderObject.id; nicholas@2538: nicholas@2538: var feedbackHolder = document.getElementById('feedbackHolder'); nicholas@2380: feedbackHolder.innerHTML = ""; nicholas@2650: var interfaceObj = interfaceContext.getCombinedInterfaces(audioHolderObject); nicholas@2538: if (interfaceObj.length > 1) { nicholas@2538: console.log("WARNING - This interface only supports one node per page. Using first interface node"); nicholas@2538: } nicholas@2538: interfaceObj = interfaceObj[0]; nicholas@2538: nicholas@2470: // Set the page title nicholas@2470: if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) { nicholas@2701: document.getElementById("test-title").textContent = audioHolderObject.title; nicholas@2470: } nicholas@2538: nicholas@2701: if (interfaceObj.title !== null) { nicholas@2538: document.getElementById("pageTitle").textContent = interfaceObj.title; nicholas@2538: } nicholas@2538: n@2793: if (interfaceObj.image !== undefined || audioHolderObject.audioElements.some(function (elem) { n@2793: return elem.image !== undefined; n@2793: })) { nicholas@2781: document.getElementById("testContent").insertBefore(interfaceContext.imageHolder.root, document.getElementById("slider")); nicholas@2781: interfaceContext.imageHolder.setImage(interfaceObj.image); nicholas@2781: } nicholas@2781: nicholas@2538: // Delete outside reference nicholas@2538: var outsideReferenceHolder = document.getElementById("outside-reference-holder"); nicholas@2395: outsideReferenceHolder.innerHTML = ""; nicholas@2538: nicholas@2538: var sliderBox = document.getElementById('slider-holder'); nicholas@2538: sliderBox.innerHTML = ""; nicholas@2538: nicholas@2538: var commentBoxPrefix = "Comment on track"; nicholas@2701: if (interfaceObj.commentBoxPrefix !== undefined) { nicholas@2538: commentBoxPrefix = interfaceObj.commentBoxPrefix; nicholas@2538: } nicholas@2538: var loopPlayback = audioHolderObject.loop; nicholas@2538: nicholas@2701: var currentTestHolder = document.createElement('audioHolder'); nicholas@2538: currentTestHolder.id = audioHolderObject.id; nicholas@2538: currentTestHolder.repeatCount = audioHolderObject.repeatCount; nicholas@2538: nicholas@2538: // Find all the audioElements from the audioHolder nicholas@2538: var index = 0; nicholas@2607: var interfaceScales = testState.currentStateMap.interfaces[0].scales; nicholas@2623: var labelType = audioHolderObject.label; nicholas@2607: if (labelType == "default") { nicholas@2607: labelType = "number"; nicholas@2607: } nicholas@2607: $(audioHolderObject.audioElements).each(function (pageIndex, element) { nicholas@2538: // Find URL of track nicholas@2538: // In this jQuery loop, variable 'this' holds the current audioElement. nicholas@2538: nicholas@2538: var audioObject = audioEngineContext.newTrack(element); nicholas@2538: if (element.type == 'outside-reference') { nicholas@2538: // Construct outside reference; nicholas@2538: var orNode = new interfaceContext.outsideReferenceDOM(audioObject, index, outsideReferenceHolder); nicholas@2538: audioObject.bindInterface(orNode); nicholas@2538: } else { nicholas@2538: // Create a slider per track n@2909: var label = element.label || interfaceContext.getLabel(labelType, index, audioHolderObject.labelStart); nicholas@2538: var sliderObj = new sliderObject(audioObject, label); nicholas@2538: nicholas@2538: if (typeof audioHolderObject.initialPosition === "number") { nicholas@2538: // Set the values nicholas@2538: sliderObj.slider.value = audioHolderObject.initalPosition; nicholas@2538: } else { nicholas@2538: // Distribute it randomnly nicholas@2538: sliderObj.slider.value = Math.random(); nicholas@2538: } nicholas@2538: sliderBox.appendChild(sliderObj.holder); nicholas@2538: audioObject.bindInterface(sliderObj); nickjillings@2117: interfaceContext.commentBoxes.createCommentBox(audioObject); nicholas@2538: index += 1; nicholas@2538: } nicholas@2538: nicholas@2538: }); nicholas@2538: nicholas@2623: if (testState.currentStateMap.restrictMovement) { nicholas@2623: $(".track-slider-range").addClass("track-slider-range-disabled"); nicholas@2623: $(".track-slider-range").each(function (i, e) { nicholas@2701: e.disabled = true; nicholas@2623: }); nicholas@2623: } nicholas@2623: nicholas@2538: nicholas@2650: var interfaceOptions = interfaceObj.options; n@3006: var sortButton = document.getElementById("sort-fragments"); n@3006: sortButton.style.visibility = "hidden"; nicholas@2701: interfaceOptions.forEach(function (option) { nicholas@2538: if (option.type == "show") { nicholas@2538: switch (option.name) { n@2407: case "playhead": n@2407: var playbackHolder = document.getElementById('playback-holder'); nicholas@2701: if (playbackHolder === null) { n@2407: playbackHolder = document.createElement('div'); n@2407: playbackHolder.style.width = "100%"; n@2407: playbackHolder.align = 'center'; n@2407: playbackHolder.appendChild(interfaceContext.playhead.object); nicholas@2650: feedbackHolder.insertBefore(playbackHolder, feedbackHolder.firstElementChild); n@2407: } n@2407: break; n@2407: case "page-count": n@2407: var pagecountHolder = document.getElementById('page-count'); nicholas@2701: if (pagecountHolder === null) { n@2407: pagecountHolder = document.createElement('div'); n@2407: pagecountHolder.id = 'page-count'; nicholas@2850: pagecountHolder.style.display = 'inline-block'; n@2407: } nicholas@2538: pagecountHolder.innerHTML = 'Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + ''; n@2407: var inject = document.getElementById('interface-buttons'); n@2407: inject.appendChild(pagecountHolder); n@2407: break; n@2407: case "volume": nicholas@2701: if (document.getElementById('master-volume-holder') === null) { n@2407: feedbackHolder.appendChild(interfaceContext.volume.object); n@2407: } n@2407: break; n@2407: case "comments": nicholas@2538: interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true); n@2407: break; nicholas@2850: case "fragmentSort": n@3006: var button = document.getElementById('sort-fragments'); n@3006: button.style.visibility = "visible"; nicholas@2850: break; n@2407: } n@2407: } nicholas@2701: }); nicholas@2538: nicholas@2538: $(audioHolderObject.commentQuestions).each(function (index, element) { nicholas@2538: var node = interfaceContext.createCommentQuestion(element); nicholas@2538: feedbackHolder.appendChild(node.holder); nicholas@2538: }); nicholas@2538: nicholas@2538: // Auto-align nicholas@2538: resizeWindow(null); nickjillings@1341: } nickjillings@1341: nicholas@2538: function sliderObject(audioObject, label) { nicholas@2538: // Constructs the slider object. We use the HTML5 slider object nicholas@2623: var page = testState.currentStateMap; nicholas@2538: this.parent = audioObject; nicholas@2538: this.holder = document.createElement('div'); nicholas@2538: this.title = document.createElement('span'); nicholas@2538: this.slider = document.createElement('input'); nicholas@2538: this.play = document.createElement('button'); nicholas@2538: nicholas@2538: this.holder.className = 'track-slider'; nicholas@2538: this.holder.style.height = window.innerHeight - 200 + 'px'; nicholas@2538: this.holder.appendChild(this.title); nicholas@2538: this.holder.appendChild(this.slider); nicholas@2538: this.holder.appendChild(this.play); nicholas@2538: this.holder.align = "center"; nicholas@2701: if (label === 0) { nicholas@2538: this.holder.style.marginLeft = '0px'; nicholas@2538: } nicholas@2538: this.holder.setAttribute('trackIndex', audioObject.id); nicholas@2538: nicholas@2538: this.title.textContent = label; nicholas@2538: this.title.style.width = "100%"; nicholas@2538: this.title.style.float = "left"; nicholas@2538: nicholas@2538: this.slider.type = "range"; nicholas@2538: this.slider.className = "track-slider-range track-slider-not-moved"; nicholas@2538: this.slider.min = "0"; nicholas@2538: this.slider.max = "1"; nicholas@2538: this.slider.step = "0.01"; nicholas@2538: this.slider.setAttribute('orient', 'vertical'); nicholas@2538: this.slider.style.height = window.innerHeight - 250 + 'px'; nicholas@2538: this.slider.onchange = function () { nicholas@2538: var time = audioEngineContext.timer.getTestTime(); nicholas@2538: var id = Number(this.parentNode.getAttribute('trackIndex')); nicholas@2538: audioEngineContext.audioObjects[id].metric.moved(time, this.value); nicholas@2538: console.log('slider ' + id + ' moved to ' + this.value + ' (' + time + ')'); nicholas@2538: $(this).removeClass('track-slider-not-moved'); nicholas@2538: }; nicholas@2538: nicholas@2538: this.play.textContent = "Loading..."; nicholas@2538: this.play.value = audioObject.id; nicholas@2538: this.play.style.float = "left"; nicholas@2538: this.play.style.width = "100%"; nicholas@2538: this.play.disabled = true; nicholas@2538: this.play.setAttribute("playstate", "ready"); nicholas@2538: this.play.onclick = function (event) { nicholas@2538: var id = Number(event.currentTarget.value); nicholas@2538: //audioEngineContext.metric.sliderPlayed(id); nicholas@2538: if (event.currentTarget.getAttribute("playstate") == "ready") { nicholas@2538: audioEngineContext.play(id); nicholas@2538: } else if (event.currentTarget.getAttribute("playstate") == "playing") { nicholas@2538: audioEngineContext.stop(); nicholas@2538: } nicholas@2538: }; nicholas@2538: nicholas@2538: this.enable = function () { nicholas@2538: this.play.disabled = false; nicholas@2538: this.play.textContent = "Play"; nicholas@2538: $(this.slider).removeClass('track-slider-disabled'); nicholas@2538: }; nicholas@2538: nicholas@2538: this.exportXMLDOM = function (audioObject) { nicholas@2538: // Called by the audioObject holding this element. Must be present nicholas@2538: var node = storage.document.createElement('value'); nicholas@2538: node.textContent = this.slider.value; n@2921: var iname = testState.getCurrentTestPage().interfaces[0].name; n@2921: if (typeof iname == "string") { n@2921: node.setAttribute("interface-name", iname); n@2921: } nicholas@2538: return node; nicholas@2538: }; nicholas@2538: this.startPlayback = function () { nicholas@2623: var self = this; nickjillings@1360: // Called when playback has begun nicholas@2538: this.play.setAttribute("playstate", "playing"); nickjillings@1360: $(".track-slider").removeClass('track-slider-playing'); nicholas@2538: $(this.holder).addClass('track-slider-playing'); nicholas@2726: interfaceContext.commentBoxes.highlightById(audioObject.id); nicholas@2538: var outsideReference = document.getElementById('outside-reference'); nicholas@2701: if (outsideReference !== null) { nicholas@2538: $(outsideReference).removeClass('track-slider-playing'); nicholas@2538: } nickjillings@1383: this.play.textContent = "Stop"; nicholas@2623: if (page.restrictMovement) { nicholas@2623: if (page.loop) { nicholas@2623: $(this.slider).removeClass("track-slider-range-disabled"); nicholas@2623: this.slider.removeAttribute("disabled"); nicholas@2623: } else { nicholas@2623: $(".track-slider-range").addClass("track-slider-range-disabled"); nicholas@2623: $(this.slider).removeClass("track-slider-range-disabled"); nicholas@2623: $(".track-slider-range").each(function (i, m) { nicholas@2623: if (m == self.slider) { nicholas@2623: m.removeAttribute("disabled"); nicholas@2623: } else { nicholas@2623: m.setAttribute("disabled", "true"); nicholas@2623: } nicholas@2623: }); nicholas@2623: } nicholas@2623: } n@2793: if (audioObject.specification.image !== undefined) { n@2793: interfaceContext.imageHolder.setImage(audioObject.specification.image); n@2793: } nickjillings@1360: }; nicholas@2538: this.stopPlayback = function () { nickjillings@1360: // Called when playback has stopped. This gets called even if playback never started! nicholas@2538: this.play.setAttribute("playstate", "ready"); nickjillings@1360: $(this.holder).removeClass('track-slider-playing'); nickjillings@1383: this.play.textContent = "Play"; nicholas@2623: if (page.restrictMovement && page.loop) { nicholas@2623: $(this.slider).addClass("track-slider-range-disabled"); nicholas@2623: this.slider.setAttribute("disabled", "true"); nicholas@2623: } nicholas@2726: var box = interfaceContext.commentBoxes.boxes.find(function (a) { nicholas@2726: return a.id === audioObject.id; nicholas@2726: }); nicholas@2726: if (box) { nicholas@2726: box.highlight(false); nicholas@2726: } n@2793: if (audioObject.specification.parent.interfaces[0].image !== undefined) { n@2793: interfaceContext.imageHolder.setImage(audioObject.specification.parent.interfaces[0].image); n@2793: } else { n@2793: interfaceContext.imageHolder.setImage(""); n@2793: } nickjillings@1360: }; nicholas@2538: this.getValue = function () { nicholas@2538: return this.slider.value; nicholas@2538: }; nicholas@2538: nicholas@2881: this.resize = function (event, height) { nicholas@2881: this.holder.style.height = height - 20 + 'px'; nicholas@2881: this.slider.style.height = height - 70 + 'px'; nicholas@2538: }; nicholas@2538: this.updateLoading = function (progress) { nicholas@2538: progress = String(progress); nicholas@2538: progress = progress.substr(0, 5); nicholas@2538: this.play.textContent = "Loading: " + progress + "%"; nicholas@2538: }; nicholas@2538: nicholas@2538: if (this.parent.state == 1) { nicholas@2538: this.enable(); nicholas@2538: } nicholas@2538: this.getPresentedId = function () { nicholas@2538: return this.title.textContent; nicholas@2538: }; nicholas@2538: this.canMove = function () { nicholas@2538: return true; nicholas@2538: }; nicholas@2538: this.error = function () { nicholas@2538: // audioObject has an error!! nickjillings@2113: this.playback.textContent = "Error"; nickjillings@2113: $(this.playback).addClass("error-colour"); nicholas@2701: }; nickjillings@1341: } nickjillings@1341: nicholas@2538: function resizeWindow(event) { nicholas@2538: // Function called when the window has been resized. nicholas@2538: // MANDATORY FUNCTION nicholas@2538: nicholas@2781: var outsideRef = document.getElementById('outside-reference'), nicholas@2881: imageHeight = 0, nicholas@2881: minHeight = Math.max(Math.floor(window.screen.height * 0.33), 200), nicholas@2881: maxHeight = Math.floor(window.screen.height * 0.5); nicholas@2781: if (document.getElementById("imageController")) { n@2791: imageHeight = $(interfaceContext.imageHolder.root).height(); nicholas@2781: } nicholas@2701: if (outsideRef !== null) { nicholas@2538: outsideRef.style.left = (window.innerWidth - 120) / 2 + 'px'; nicholas@2538: } nicholas@2538: nicholas@2538: // Auto-align nicholas@2538: var numObj = document.getElementsByClassName('track-slider').length; nicholas@2538: var totalWidth = (numObj - 1) * 150 + 100; nicholas@2538: var diff = (window.innerWidth - totalWidth) / 2; nicholas@2881: var height = window.innerHeight - 180 - imageHeight; nicholas@2881: height = Math.min(height, maxHeight); nicholas@2881: height = Math.max(height, minHeight); nicholas@2881: document.getElementById('slider').style.height = height + 'px'; nicholas@2538: if (diff <= 0) { nicholas@2538: diff = 0; nicholas@2538: } nicholas@2538: document.getElementById('slider-holder').style.marginLeft = diff + 'px'; nicholas@2538: for (var i in audioEngineContext.audioObjects) { nicholas@2538: if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference') { nicholas@2881: audioEngineContext.audioObjects[i].interfaceDOM.resize(event, height); nicholas@2538: } nicholas@2538: } nicholas@2538: document.getElementById('scale-holder').style.marginLeft = (diff - 100) + 'px'; nicholas@2881: document.getElementById('scale-text-holder').style.height = height - 14 + 'px'; nicholas@2380: // Cheers edge for making me delete a canvas every resize. nicholas@2538: var canvas = document.getElementById('scale-canvas'); nicholas@2380: var new_canvas = document.createElement("canvas"); nicholas@2380: new_canvas.id = 'scale-canvas'; nicholas@2380: canvas.parentElement.appendChild(new_canvas); nicholas@2380: canvas.parentElement.removeChild(canvas); nicholas@2538: new_canvas.width = totalWidth; nicholas@2881: new_canvas.height = height - 14; nicholas@2538: drawScale(); nickjillings@1341: } nickjillings@1341: nicholas@2538: function drawScale() { nicholas@2538: var interfaceObj = testState.currentStateMap.interfaces[0]; nicholas@2538: var scales = testState.currentStateMap.interfaces[0].scales; nicholas@3037: var ticks = specification.interfaces.options.concat(interfaceObj.options).find(function (a) { nicholas@3037: return (a.type == "show" && a.name == "ticks"); nicholas@3037: }); nicholas@3037: if (ticks !== undefined) { nicholas@3037: ticks = true; nicholas@3037: } else { nicholas@3037: ticks = false; nicholas@3037: } nicholas@2538: scales = scales.sort(function (a, b) { nicholas@2538: return a.position - b.position; nicholas@2538: }); nicholas@2538: var canvas = document.getElementById('scale-canvas'); nicholas@2538: var ctx = canvas.getContext("2d"); nicholas@2538: var height = canvas.height; nicholas@2538: var width = canvas.width; nicholas@2538: ctx.clearRect(0, 0, canvas.width, canvas.height); nicholas@2538: var draw_heights = [24, height - 34]; nicholas@2538: var textHolder = document.getElementById('scale-text-holder'); nicholas@2538: textHolder.innerHTML = ""; nicholas@2538: var lastHeight = 0; nicholas@2701: scales.forEach(function (scale) { nicholas@2538: var posPercent = scale.position / 100.0; nicholas@2538: var posPix = (1 - posPercent) * (draw_heights[1] - draw_heights[0]) + draw_heights[0]; nicholas@3037: if (ticks) { nicholas@3037: ctx.fillStyle = "#000000"; nicholas@3037: ctx.setLineDash([1, 2]); nicholas@3037: ctx.moveTo(0, posPix); nicholas@3037: ctx.lineTo(width, posPix); nicholas@3037: ctx.stroke(); nicholas@3037: } nicholas@2538: var text = document.createElement('div'); nicholas@2538: text.align = "right"; nicholas@2538: var textC = document.createElement('span'); nicholas@2538: textC.textContent = scale.text; nicholas@2538: text.appendChild(textC); nicholas@2538: text.className = "scale-text"; nicholas@2538: textHolder.appendChild(text); nicholas@2538: text.style.top = (posPix - 9) + 'px'; nicholas@2538: lastHeight = posPix; nicholas@2701: }); nickjillings@1341: } nickjillings@1341: n@3006: function buttonSortFragmentClick() { n@3006: var sortIndex = interfaceContext.sortFragmentsByScore(); n@3006: var sliderBox = document.getElementById("slider-holder"); n@3006: var nodes = audioEngineContext.audioObjects.filter(function (ao) { n@3006: return ao.specification.type !== "outside-reference"; n@3006: }); n@3006: var i; n@3006: nodes.forEach(function (ao) { n@3006: sliderBox.removeChild(ao.interfaceDOM.holder); n@3006: }); n@3006: for (i = 0; i < nodes.length; i++) { n@3006: var j = sortIndex[i]; n@3006: sliderBox.appendChild(nodes[j].interfaceDOM.holder); n@3006: } n@3006: } n@3006: nickjillings@1341: function buttonSubmitClick() // TODO: Only when all songs have been played! nickjillings@1341: { nicholas@2650: var checks = testState.currentStateMap.interfaces[0].options, nicholas@2650: canContinue = true; nickjillings@1341: nicholas@2538: // Check that the anchor and reference objects are correctly placed nicholas@2701: if (interfaceContext.checkHiddenAnchor() === false) { nicholas@2538: return; nicholas@2538: } nicholas@2701: if (interfaceContext.checkHiddenReference() === false) { nicholas@2538: return; nicholas@2538: } nicholas@2825: if (interfaceContext.checkFragmentMinPlays() === false) { nicholas@2825: return; nicholas@2825: } nicholas@3035: if (interfaceContext.checkCommentQuestions() === false) { nicholas@3035: return; nicholas@3035: } nicholas@2538: nicholas@2538: for (var i = 0; i < checks.length; i++) { nicholas@2701: var checkState = true; nicholas@2538: if (checks[i].type == 'check') { nicholas@2538: switch (checks[i].name) { nicholas@2538: case 'fragmentPlayed': nicholas@2538: // Check if all fragments have been played n@2790: checkState = interfaceContext.checkAllPlayed(checks[i].errorMessage); nicholas@2538: break; nicholas@2538: case 'fragmentFullPlayback': nicholas@2538: // Check all fragments have been played to their full length n@2790: checkState = interfaceContext.checkAllPlayed(checks[i].errorMessage); nicholas@2538: console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead'); nicholas@2538: break; nicholas@2538: case 'fragmentMoved': nicholas@2538: // Check all fragment sliders have been moved. n@2790: checkState = interfaceContext.checkAllMoved(checks[i].errorMessage); nicholas@2538: break; nicholas@2538: case 'fragmentComments': nicholas@2538: // Check all fragment sliders have been moved. n@2790: checkState = interfaceContext.checkAllCommented(checks[i].errorMessage); nicholas@2538: break; nicholas@2538: case 'scalerange': nicholas@2538: // Check the scale has been used effectively n@2790: checkState = interfaceContext.checkScaleRange(checks[i].errorMessage); nicholas@2538: break; nicholas@2538: default: nicholas@2538: console.log("WARNING - Check option " + checks[i].check + " is not supported on this interface"); nicholas@2538: break; nicholas@2538: } nicholas@2538: nicholas@2538: } nicholas@2701: if (checkState === false) { nicholas@2701: canContinue = false; nicholas@2538: break; nicholas@2538: } nicholas@2538: } nicholas@2538: nickjillings@1341: if (canContinue) { nicholas@2538: if (audioEngineContext.status == 1) { nicholas@2538: var playback = document.getElementById('playback-button'); nicholas@2538: playback.click(); nicholas@2538: // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options nicholas@2538: } else { nicholas@2701: if (audioEngineContext.timer.testStarted === false) { nicholas@2538: interfaceContext.lightbox.post("Message", 'You have not started the test! Please press start to begin the test!'); nicholas@2538: return; nicholas@2538: } nicholas@2538: } nicholas@2538: testState.advanceState(); nicholas@2538: } nickjillings@1341: } nickjillings@1341: nicholas@2538: function pageXMLSave(store, pageSpecification) { nicholas@2538: // MANDATORY nicholas@2538: // Saves a specific test page nicholas@2538: // You can use this space to add any extra nodes to your XML saves nicholas@2538: // Get the current information in store (remember to appendChild your data to it) nicholas@2538: // pageSpecification is the current page node configuration nicholas@2538: // To create new XML nodes, use storage.document.createElement(); nickjillings@1341: }