# HG changeset patch # User Nicholas Jillings # Date 1452703799 0 # Node ID 63461187a425cfc15f5aae70849ae211a1c702fe # Parent 5bd699bc44d2a2c0ff5b3f5b2cede502275e274d Beginning discrete / likert interfaces. diff -r 5bd699bc44d2 -r 63461187a425 core.js --- a/core.js Wed Jan 13 14:02:00 2016 +0000 +++ b/core.js Wed Jan 13 16:49:59 2016 +0000 @@ -174,6 +174,11 @@ css.href = 'interfaces/AB.css'; document.getElementsByTagName("head")[0].appendChild(css); + break; + case "Bipolar": + case "ACR": + case "DCR": + case "CCR": case "ABC": // Above enumerate to horizontal sliders interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js"); @@ -185,6 +190,20 @@ css.href = 'interfaces/horizontal-sliders.css'; document.getElementsByTagName("head")[0].appendChild(css); + break; + case "discrete": + case "likert": + // Above enumerate to horizontal discrete radios + interfaceJS.setAttribute("src","interfaces/discrete.js"); + + // horizontal-sliders comes with a css file + var css = document.createElement('link'); + css.rel = 'stylesheet'; + css.type = 'text/css'; + css.href = 'interfaces/discrete.css'; + + document.getElementsByTagName("head")[0].appendChild(css); + break; } document.getElementsByTagName("head")[0].appendChild(interfaceJS); @@ -2916,8 +2935,8 @@ this.XMLDOM = this.parent.document.createElement('page'); this.XMLDOM.setAttribute('id',specification.id); this.XMLDOM.setAttribute('presentedId',specification.presentedId); - if (specification.preTest != undefined){this.preTest = new this.surveyNode(this,this.root,this.specification.preTest);} - if (specification.postTest != undefined){this.postTest = new this.surveyNode(this,this.root,this.specification.postTest);} + if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);} + if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);} // Add any page metrics var page_metric = this.parent.document.createElement('metric'); diff -r 5bd699bc44d2 -r 63461187a425 example_eval/radio_example.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example_eval/radio_example.xml Wed Jan 13 16:49:59 2016 +0000 @@ -0,0 +1,31 @@ + + + + + testTimer + elementTimer + elementInitialPosition + elementTracker + elementFlagListenedTo + elementFlagMoved + elementListenTracker + + + + + + + + + + + + -50 + 0 + 50 + + + + + + diff -r 5bd699bc44d2 -r 63461187a425 interfaces/discrete.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interfaces/discrete.css Wed Jan 13 16:49:59 2016 +0000 @@ -0,0 +1,106 @@ +/* + * Hold any style information for MUSHRA interface. Customise if you like to make the interface your own! + * + */ +body { + /* Set the background colour (note US English spelling) to grey*/ + background-color: #ddd +} + +div.pageTitle { + width: auto; + height: 20px; + margin: 10px 0px; +} + +div.pageTitle span{ + font-size: 1.5em; +} + +div.testHalt { + /* Specify any colouring during the test halt for pre/post questions */ + background-color: rgba(0,0,0,0.5); + /* Don't mess with this bit */ + z-index: 2; + width: 100%; + height: 100%; + position: absolute; + left: 0px; + top: 0px; +} + +button { + /* Specify any button structure or style */ + min-width: 20px; + background-color: #ddd +} + +div#slider-holder { + height: inherit; + position: absolute; + left: 0px; + z-index: 3; + margin-top:25px; +} + +div#scale-holder { + height: inherit; + position: absolute; + left: 0px; + z-index: 2; +} + +div#scale-text-holder { + position:relative; + float: left; +} +div.scale-text { + position: absolute; + font-size: 1.2em; +} + +canvas#scale-canvas { + position: relative; + float: left; +} + +div.track-slider { + float: left; + height: 30px; + border: solid; + border-width: 1px; + border-color: black; + padding:2px; + margin-left: 94px; + margin-bottom: 30px; +} + +div.track-slider-range { + float: left; + height: 100%; + margin: 0px 10px; +} + +div.track-slider-title { + float: left; + padding-top: 5px; + width: 100px; +} + +button.track-slider-button { + float: left; + width: 100px; + height: 30px; +} + + +button.outside-reference { + width:120px; + height:20px; + margin-bottom:5px; + position: absolute; +} + +div.track-slider-playing { + background-color: #FFDDDD; +} \ No newline at end of file diff -r 5bd699bc44d2 -r 63461187a425 interfaces/discrete.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interfaces/discrete.js Wed Jan 13 16:49:59 2016 +0000 @@ -0,0 +1,412 @@ +// Once this is loaded and parsed, begin execution +loadInterface(); + +function loadInterface() { + // Use this to do any one-time page / element construction. For instance, placing any stationary text objects, + // holding div's, or setting up any nodes which are present for the entire test sequence + + // The injection point into the HTML page + interfaceContext.insertPoint = document.getElementById("topLevelBody"); + var testContent = document.createElement('div'); + testContent.id = 'testContent'; + + // Create the top div for the Title element + var titleAttr = specification.title; + var title = document.createElement('div'); + title.className = "title"; + title.align = "center"; + var titleSpan = document.createElement('span'); + + // Set title to that defined in XML, else set to default + if (titleAttr != undefined) { + titleSpan.textContent = titleAttr; + } else { + titleSpan.textContent = 'Listening test'; + } + // Insert the titleSpan element into the title div element. + title.appendChild(titleSpan); + + var pagetitle = document.createElement('div'); + pagetitle.className = "pageTitle"; + pagetitle.align = "center"; + var titleSpan = document.createElement('span'); + titleSpan.id = "pageTitle"; + pagetitle.appendChild(titleSpan); + + // Create Interface buttons! + var interfaceButtons = document.createElement('div'); + interfaceButtons.id = 'interface-buttons'; + interfaceButtons.style.height = '25px'; + + // Create playback start/stop points + var playback = document.createElement("button"); + playback.innerHTML = 'Stop'; + playback.id = 'playback-button'; + playback.style.float = 'left'; + // onclick function. Check if it is playing or not, call the correct function in the + // audioEngine, change the button text to reflect the next state. + playback.onclick = function() { + if (audioEngineContext.status == 1) { + audioEngineContext.stop(); + this.innerHTML = 'Stop'; + var time = audioEngineContext.timer.getTestTime(); + console.log('Stopped at ' + time); // DEBUG/SAFETY + } + }; + // Create Submit (save) button + var submit = document.createElement("button"); + submit.innerHTML = 'Submit'; + submit.onclick = buttonSubmitClick; + submit.id = 'submit-button'; + submit.style.float = 'left'; + // Append the interface buttons into the interfaceButtons object. + interfaceButtons.appendChild(playback); + interfaceButtons.appendChild(submit); + + // Create a slider box + var sliderBox = document.createElement('div'); + sliderBox.style.width = "100%"; + sliderBox.style.height = window.innerHeight - 200+12 + 'px'; + sliderBox.style.marginBottom = '10px'; + sliderBox.id = 'slider'; + var scaleHolder = document.createElement('div'); + scaleHolder.id = "scale-holder"; + scaleHolder.style.marginLeft = "107px"; + sliderBox.appendChild(scaleHolder); + var scaleText = document.createElement('div'); + scaleText.id = "scale-text-holder"; + scaleText.style.height = "25px"; + scaleText.style.width = "100%"; + scaleHolder.appendChild(scaleText); + var scaleCanvas = document.createElement('canvas'); + scaleCanvas.id = "scale-canvas"; + scaleCanvas.style.marginLeft = "100px"; + scaleHolder.appendChild(scaleCanvas); + var sliderObjectHolder = document.createElement('div'); + sliderObjectHolder.id = 'slider-holder'; + sliderObjectHolder.align = "center"; + sliderBox.appendChild(sliderObjectHolder); + + // Global parent for the comment boxes on the page + var feedbackHolder = document.createElement('div'); + feedbackHolder.id = 'feedbackHolder'; + + testContent.style.zIndex = 1; + interfaceContext.insertPoint.innerHTML = null; // Clear the current schema + + // Inject into HTML + testContent.appendChild(title); // Insert the title + testContent.appendChild(pagetitle); + testContent.appendChild(interfaceButtons); + testContent.appendChild(sliderBox); + testContent.appendChild(feedbackHolder); + interfaceContext.insertPoint.appendChild(testContent); + + // Load the full interface + testState.initialise(); + testState.advanceState(); +}; + +function loadTest(page) +{ + // Called each time a new test page is to be build. The page specification node is the only item passed in + var id = page.id; + + var feedbackHolder = document.getElementById('feedbackHolder'); + var interfaceObj = page.interfaces; + if (interfaceObj.length > 1) + { + console.log("WARNING - This interface only supports one node per page. Using first interface node"); + } + interfaceObj = interfaceObj[0]; + if(interfaceObj.title != null) + { + document.getElementById("pageTitle").textContent = interfaceObj.title; + } + + // Delete outside reference + var outsideReferenceHolder = document.getElementById('outside-reference'); + if (outsideReferenceHolder != null) { + document.getElementById('interface-buttons').removeChild(outsideReferenceHolder); + } + + var sliderBox = document.getElementById('slider-holder'); + feedbackHolder.innerHTML = null; + sliderBox.innerHTML = null; + + var commentBoxPrefix = "Comment on track"; + if (interfaceObj.commentBoxPrefix != undefined) { + commentBoxPrefix = interfaceObj.commentBoxPrefix; + } + var loopPlayback = page.loop; + + $(page.commentQuestions).each(function(index,element) { + var node = interfaceContext.createCommentQuestion(element); + feedbackHolder.appendChild(node.holder); + }); + + // Find all the audioElements from the audioHolder + var label = 0; + var numScales = testState.currentStateMap.interfaces[0].scales.length; + $(page.audioElements).each(function(index,element){ + // Find URL of track + // In this jQuery loop, variable 'this' holds the current audioElement. + + var audioObject = audioEngineContext.newTrack(element); + if (element.type == 'outside-reference') + { + // Construct outside reference; + var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons')); + audioObject.bindInterface(orNode); + } else { + var node = interfaceContext.createCommentBox(audioObject); + + // Create a slider per track + var sliderObj = new discreteObject(audioObject,label,numScales); + sliderBox.appendChild(sliderObj.holder); + audioObject.bindInterface(sliderObj); + label += 1; + } + + }); + + // Auto-align + resizeWindow(null); +} + +function discreteObject(audioObject,label,numOptions) +{ + // An example node, you can make this however you want for each audioElement. + // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following + // You attach them by calling audioObject.bindInterface( ) + if (numOptions == null || numOptions == 0) + { + console.log("WARNING: The discrete radio's are built depending on the number of scale points specified! Ensure you have some specified. Defaulting to 5 for now!"); + numOptions = 5; + } + this.parent = audioObject; + + this.holder = document.createElement('div'); + this.title = document.createElement('div'); + this.discreteHolder = document.createElement('div'); + this.discretes = []; + this.play = document.createElement('button'); + + this.holder.className = 'track-slider'; + this.holder.style.width = window.innerWidth-200 + 'px'; + this.holder.appendChild(this.title); + this.holder.appendChild(this.discreteHolder); + this.holder.appendChild(this.play); + this.holder.setAttribute('trackIndex',audioObject.id); + this.title.textContent = label; + this.title.className = 'track-slider-title'; + + this.discreteHolder.className = "track-slider-range"; + this.discreteHolder.style.width = window.innerWidth-420 + 'px'; + for (var i=0; i node. + // If there is no value node (such as outside reference), return null + // 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 + // Use storage.document.createElement('value'); to generate the XML node. + + }; +}; + +function resizeWindow(event) +{ + // Called on every window resize event, use this to scale your page properly + + var numObj = document.getElementsByClassName('track-slider').length; + var totalHeight = (numObj * 66)-30; + document.getElementById('scale-holder').style.width = window.innerWidth-220 + 'px'; + var canvas = document.getElementById('scale-canvas'); + canvas.width = window.innerWidth-420; + canvas.height = totalHeight; + for (var i in audioEngineContext.audioObjects) + { + if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference'){ + audioEngineContext.audioObjects[i].interfaceDOM.resize(event); + } + } + drawScale(); +} + +function drawScale() +{ + var interfaceObj = testState.currentStateMap.interfaces[0]; + var scales = testState.currentStateMap.interfaces[0].scales; + scales = scales.sort(function(a,b) { + return a.position - b.position; + }); + var canvas = document.getElementById('scale-canvas'); + var ctx = canvas.getContext("2d"); + var height = canvas.height; + var width = canvas.width; + var textHolder = document.getElementById('scale-text-holder'); + textHolder.innerHTML = null; + ctx.fillStyle = "#000000"; + ctx.setLineDash([1,4]); + for (var scale of scales) + { + var posPercent = scale.position / 100.0; + var posPix = Math.round(width * posPercent); + if(posPix<=0){posPix=1;} + if(posPix>=width){posPix=width-1;} + ctx.moveTo(posPix,0); + ctx.lineTo(posPix,height); + ctx.stroke(); + + var text = document.createElement('div'); + text.align = "center"; + var textC = document.createElement('span'); + textC.textContent = scale.text; + text.appendChild(textC); + text.className = "scale-text"; + textHolder.appendChild(text); + text.style.width = Math.ceil($(text).width())+'px'; + text.style.left = (posPix+100-($(text).width()/2)) +'px'; + } +} + +function buttonSubmitClick() // TODO: Only when all songs have been played! +{ + var checks = []; + checks = checks.concat(testState.currentStateMap.interfaces[0].options); + checks = checks.concat(specification.interfaces.options); + var canContinue = true; + + // Check that the anchor and reference objects are correctly placed + if (interfaceContext.checkHiddenAnchor() == false) {return;} + if (interfaceContext.checkHiddenReference() == false) {return;} + + for (var i=0; i saves + // Get the current information in store (remember to appendChild your data to it) + // pageSpecification is the current page node configuration + // To create new XML nodes, use storage.document.createElement(); +} \ No newline at end of file