# HG changeset patch # User Nicholas Jillings # Date 1478171066 0 # Node ID b1ba05ef1e7a1db3fdafd4e56630b745232f5a6c # Parent 2b02df54211ed350e3fa43cb977705dc7dcd21b2# Parent dab27ff8cbfa7f62d603455c7bb9459279bfbc46 Merge branch 'master' into Dev_main diff -r dab27ff8cbfa -r b1ba05ef1e7a css/core.css --- a/css/core.css Thu Nov 03 11:02:56 2016 +0000 +++ b/css/core.css Thu Nov 03 11:04:26 2016 +0000 @@ -3,60 +3,53 @@ */ div.title { - width: 100%; - height: 50px; - margin-bottom: 10px; - font-size: 2em; + width: 100%; + height: 50px; + margin-bottom: 10px; + font-size: 2em; } - div.indicator-box { - position: absolute; - left: 150px; - top: 10px; - width: 300px; - height: 60px; - padding: 20px; - border-radius: 10px; - background-color: rgb(100,200,200); + position: absolute; + left: 150px; + top: 10px; + width: 300px; + height: 60px; + padding: 20px; + border-radius: 10px; + background-color: rgb(100, 200, 200); } - div.comment-div { - border:1px solid #444444; - max-width: 600px; - min-width: 400px; - float: left; - margin: 5px 10px 5px 5px; - height: 90px; + border: 1px solid #444444; + max-width: 600px; + min-width: 400px; + float: left; + margin: 5px 10px 5px 5px; + height: 90px; border-radius: 10px; } - div.comment-div span { - margin-left: 15px; + margin-left: 15px; } - div.popupHolder { - width: 500px; - min-height: 250px; - max-height: 400px; - background-color: #fff; - border-radius: 10px; - box-shadow: 0px 0px 50px #000; - z-index: 10; - position: fixed; + width: 500px; + min-height: 250px; + max-height: 400px; + background-color: #fff; + border-radius: 10px; + box-shadow: 0px 0px 50px #000; + z-index: 10; + position: fixed; } - div#popupContent { margin-top: 20px; margin-bottom: 35px; overflow: auto; } - div#popupContent iframe { width: 100%; border: 0px none; height: 290px; } - div#popupTitleHolder { width: inherit; min-height: 25px; @@ -66,11 +59,9 @@ padding: 8px; text-align: center; } - #popupTitle { white-space: pre-line; } - div#popupResponse { width: inherit; min-height: 50px; @@ -78,20 +69,18 @@ overflow: auto; position: relative; } - button.popupButton { - /* Button for popup window + /* Button for popup window */ - width: 50px; - height: 25px; - position: absolute; - border-radius: 5px; - border: #444; - border-width: 1px; - border-style: solid; - background-color: #fff; + width: 50px; + height: 25px; + position: absolute; + border-radius: 5px; + border: #444; + border-width: 1px; + border-style: solid; + background-color: #fff; } - div.popup-option-checbox { /* Popup window checkbox */ padding: 5px; @@ -99,46 +88,44 @@ width: -moz-fit-content; width: -webkit-fit-content; } - -div.popup-option-checbox input{ +div.popup-option-checbox input { /* Popup window checkbox */ margin-right: 15px; } - table.popup-option-list { margin: auto; } - table.popup-option-list tr { padding: 5px; } - table.popup-option-list tr td { padding: 5px; } - +div.survey-slider-text-holder { + display: flex; + flex-direction: row; + justify-content: space-between; + padding: 0px 15px; +} button#popup-proceed { bottom: 10px; right: 10px; } - button#popup-previous { bottom: 10px; left: 10px; } - 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: 9; - width: 100%; - height: 100%; - position: fixed; - left: 0px; - top: 0px; + /* 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: 9; + width: 100%; + height: 100%; + position: fixed; + left: 0px; + top: 0px; } - div#lightbox-root { visibility: hidden; z-index: 20; @@ -146,80 +133,69 @@ min-height: 50px; max-height: 250px; } - div.lightbox-error { margin: 25px; margin-bottom: 50px; padding: 5px; border-radius: 5px; - background-color: rgb(255,220,220); - border: 2px rgb(200,0,0) solid; + background-color: rgb(255, 220, 220); + border: 2px rgb(200, 0, 0) solid; } - div.lightbox-warning { margin: 25px; margin-bottom: 50px; padding: 5px; border-radius: 5px; - background-color: rgb(255,255,220); - border: 2px rgb(255,250,0) solid; + background-color: rgb(255, 255, 220); + border: 2px rgb(255, 250, 0) solid; } - div.lightbox-message { margin: 25px; margin-bottom: 50px; padding: 5px; border-radius: 5px; - background-color: rgb(200,220,255); - border: 2px rgb(50,100,250) solid; + background-color: rgb(200, 220, 255); + border: 2px rgb(50, 100, 250) solid; } - div#lightbox-blanker { visibility: hidden; z-index: 19; } - button.outside-reference { - width:120px; - height:20px; - margin-bottom:5px; - position: absolute; + width: 120px; + height: 20px; + margin-bottom: 5px; + position: absolute; } - textarea.trackComment { - max-width: 594px; - min-width: 350px; - max-height: 60px; + max-width: 594px; + min-width: 350px; + max-height: 60px; resize: none; } - div.playhead { - width: 500px; - height: 50px; - background-color: #eee; - border-radius: 10px; - padding: 10px; + width: 500px; + height: 50px; + background-color: #eee; + border-radius: 10px; + padding: 10px; } - div.playhead-scrub-track { - width: 100%; - height: 10px; - border-style: solid; - border-width: 1px; + width: 100%; + height: 10px; + border-style: solid; + border-width: 1px; } - div#playhead-scrubber { - width: 10px; - height: 10px; - position: relative; - background-color: #000; + width: 10px; + height: 10px; + position: relative; + background-color: #000; } - div.master-volume-holder-inline { width: 100%; padding: 5px; } - div.master-volume-holder-float { position: absolute; top: 20px; @@ -227,15 +203,13 @@ width: 250px%; padding: 5px; } - div#master-volume-root { - margin:auto; + margin: auto; border: black 1px solid; border-radius: 5px; width: 250px; height: 40px; } - input#master-volume-control { width: 200px; height: 25px; @@ -243,14 +217,12 @@ margin: 0px; padding: 0px; } - span#master-volume-feedback { width: 45px; height: 25px; margin-left: 5px; float: left; } - div.error-colour { background-color: #FF8F8F; } @@ -258,13 +230,11 @@ background-color: #FF8F8F; color: black; } - div.calibration-holder { text-align: center; align-content: center; height: auto; } - div.calibration-slider { width: 50px; margin: 2px; @@ -272,12 +242,23 @@ align-content: center; float: left; } - -div.calibration-slider input[type=range][orient=vertical] -{ - writing-mode: bt-lr; /* IE */ - -webkit-appearance: slider-vertical; /* WebKit */ +div.calibration-slider input[type=range][orient=vertical] { + writing-mode: bt-lr; + /* IE */ + -webkit-appearance: slider-vertical; + /* WebKit */ width: 8px; padding: 0 5px; height: 290px; } + +/* Comment Boxes */ + +div.comment-slider-text-holder { + display: flex; + flex-direction: row; + justify-content: space-between; +} +div.comment-slider-text-holder span { + margin: 0px 5px; +} diff -r dab27ff8cbfa -r b1ba05ef1e7a interfaces/AB.js --- a/interfaces/AB.js Thu Nov 03 11:02:56 2016 +0000 +++ b/interfaces/AB.js Thu Nov 03 11:04:26 2016 +0000 @@ -2,15 +2,15 @@ loadInterface(); function loadInterface() { - // Get the dimensions of the screen available to the page - var width = window.innerWidth; - var height = window.innerHeight; - interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema - - // Custom comparator Object - Interface.prototype.comparator = null; - - Interface.prototype.checkScaleRange = function(min, max) { + // Get the dimensions of the screen available to the page + var width = window.innerWidth; + var height = window.innerHeight; + interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema + + // Custom comparator Object + Interface.prototype.comparator = null; + + Interface.prototype.checkScaleRange = function (min, max) { var page = testState.getCurrentTestPage(); var audioObjects = audioEngineContext.audioObjects; var state = true; @@ -19,166 +19,170 @@ var maxRanking = -Infinity; for (var ao of audioObjects) { var rank = ao.interfaceDOM.getValue(); - if (rank < minRanking) {minRanking = rank;} - if (rank > maxRanking) {maxRanking = rank;} + if (rank < minRanking) { + minRanking = rank; + } + if (rank > maxRanking) { + maxRanking = rank; + } } - if (maxRanking*100 < max) { + if (maxRanking * 100 < max) { str += "At least one fragment must be selected." state = false; } if (!state) { console.log(str); this.storeErrorNode(str); - interfaceContext.lightbox.post("Message",str); + interfaceContext.lightbox.post("Message", str); } return state; } - - // 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'); + + // 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'); titleSpan.id = "test-title"; - - // 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'; + + // 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 - } - }; - // Append the interface buttons into the interfaceButtons object. - interfaceButtons.appendChild(playback); - - // Global parent for the comment boxes on the page - var feedbackHolder = document.createElement('div'); - feedbackHolder.id = 'feedbackHolder'; - + } + }; + // Append the interface buttons into the interfaceButtons object. + interfaceButtons.appendChild(playback); + + // Global parent for the comment boxes on the page + var feedbackHolder = document.createElement('div'); + feedbackHolder.id = 'feedbackHolder'; + // Create outside reference holder var outsideRef = document.createElement("div"); outsideRef.id = "outside-reference-holder"; - - // Construct the AB Boxes - var boxes = document.createElement('div'); - boxes.align = "center"; - boxes.id = "box-holders"; + + // Construct the AB Boxes + var boxes = document.createElement('div'); + boxes.align = "center"; + boxes.id = "box-holders"; boxes.style.float = "left"; - - var submit = document.createElement('button'); - submit.id = "submit"; - submit.onclick = buttonSubmitClick; - submit.className = "big-button"; - submit.textContent = "submit"; - submit.style.position = "relative"; - submit.style.left = (window.innerWidth-250)/2 + 'px'; - - feedbackHolder.appendChild(boxes); - + + var submit = document.createElement('button'); + submit.id = "submit"; + submit.onclick = buttonSubmitClick; + submit.className = "big-button"; + submit.textContent = "submit"; + submit.style.position = "relative"; + submit.style.left = (window.innerWidth - 250) / 2 + 'px'; + + feedbackHolder.appendChild(boxes); + // Create holder for comment boxes var comments = document.createElement("div"); comments.id = "comment-box-holder"; - - // Inject into HTML - testContent.appendChild(title); // Insert the title - testContent.appendChild(pagetitle); - testContent.appendChild(interfaceButtons); + + // Inject into HTML + testContent.appendChild(title); // Insert the title + testContent.appendChild(pagetitle); + testContent.appendChild(interfaceButtons); testContent.appendChild(outsideRef); - testContent.appendChild(feedbackHolder); - testContent.appendChild(submit); + testContent.appendChild(feedbackHolder); + testContent.appendChild(submit); testContent.appendChild(comments); - interfaceContext.insertPoint.appendChild(testContent); + interfaceContext.insertPoint.appendChild(testContent); - // Load the full interface - testState.initialise(); - testState.advanceState(); + // Load the full interface + testState.initialise(); + testState.advanceState(); } -function loadTest(audioHolderObject) -{ - var feedbackHolder = document.getElementById('feedbackHolder'); - var interfaceObj = audioHolderObject.interfaces; - if (interfaceObj.length > 1) - { - console.log("WARNING - This interface only supports one node per page. Using first interface node"); - } - interfaceObj = interfaceObj[0]; - +function loadTest(audioHolderObject) { + var feedbackHolder = document.getElementById('feedbackHolder'); + var interfaceObj = audioHolderObject.interfaces; + if (interfaceObj.length > 1) { + console.log("WARNING - This interface only supports one node per page. Using first interface node"); + } + interfaceObj = interfaceObj[0]; + var commentHolder = document.getElementById('comment-box-holder'); commentHolder.innerHTML = ""; - + // Delete outside reference - var outsideReferenceHolder = document.getElementById("outside-reference-holder"); + var outsideReferenceHolder = document.getElementById("outside-reference-holder"); outsideReferenceHolder.innerHTML = ""; - + // Set the page title if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) { document.getElementById("test-title").textContent = audioHolderObject.title } - - if(interfaceObj.title != null) - { - document.getElementById("pageTitle").textContent = interfaceObj.title; - } - + + if (interfaceObj.title != null) { + document.getElementById("pageTitle").textContent = interfaceObj.title; + } + var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options); // Clear the interfaceElements { var node = document.getElementById('playback-holder'); - if (node){feedbackHolder.removeChild(node);} + if (node) { + feedbackHolder.removeChild(node); + } node = document.getElementById('page-count'); - if (node){document.getElementById('interface-buttons').removeChild(node);} + if (node) { + document.getElementById('interface-buttons').removeChild(node); + } node = document.getElementById('master-volume-holder-float'); - if (node){feedbackHolder.removeChild(node);} + if (node) { + feedbackHolder.removeChild(node); + } } - + // Populate the comparator object - interfaceContext.comparator = new comparator(audioHolderObject); - - for (var option of interfaceOptions) - { - if (option.type == "show") - { - switch(option.name) { + interfaceContext.comparator = new comparator(audioHolderObject); + + for (var option of interfaceOptions) { + if (option.type == "show") { + switch (option.name) { case "playhead": var playbackHolder = document.getElementById('playback-holder'); - if (playbackHolder == null) - { + if (playbackHolder == null) { playbackHolder = document.createElement('div'); playbackHolder.id = 'playback-holder'; playbackHolder.style.width = "100%"; @@ -190,309 +194,329 @@ break; case "page-count": var pagecountHolder = document.getElementById('page-count'); - if (pagecountHolder == null) - { + if (pagecountHolder == null) { pagecountHolder = document.createElement('div'); pagecountHolder.id = 'page-count'; document.getElementById('interface-buttons').appendChild(pagecountHolder); } - pagecountHolder.innerHTML = 'Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+''; + pagecountHolder.innerHTML = 'Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + ''; break; case "volume": - if (document.getElementById('master-volume-holder-float') == null) - { + if (document.getElementById('master-volume-holder-float') == null) { feedbackHolder.appendChild(interfaceContext.volume.object); } break; case "comments": // Generate one comment box per presented page - for (var element of audioEngineContext.audioObjects) - { + for (var element of audioEngineContext.audioObjects) { interfaceContext.commentBoxes.createCommentBox(element); } - interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true); + interfaceContext.commentBoxes.showCommentBoxes(commentHolder, true); break; } } } - - $(audioHolderObject.commentQuestions).each(function(index,element) { - var node = interfaceContext.createCommentQuestion(element); - commentHolder.appendChild(node.holder); - }); - - resizeWindow(null); + + $(audioHolderObject.commentQuestions).each(function (index, element) { + var node = interfaceContext.createCommentQuestion(element); + commentHolder.appendChild(node.holder); + }); + + resizeWindow(null); } -function comparator(audioHolderObject) -{ - this.comparatorBox = function(audioElement,id,text) - { - this.parent = audioElement; - this.id = id; - this.value = 0; - this.disabled = true; - this.box = document.createElement('div'); - this.box.className = 'comparator-holder'; - this.box.setAttribute('track-id',audioElement.id); - this.box.id = 'comparator-'+text; - this.selector = document.createElement('div'); - this.selector.className = 'comparator-selector disabled'; - var selectorText = document.createElement('span'); - selectorText.textContent = text; - this.selector.appendChild(selectorText); - this.playback = document.createElement('button'); - this.playback.className = 'comparator-button'; - this.playback.disabled = true; - this.playback.textContent = "Listen"; - this.box.appendChild(this.selector); - this.box.appendChild(this.playback); - this.selector.onclick = function(event) - { - var time = audioEngineContext.timer.getTestTime(); - if ($(event.currentTarget).hasClass('disabled')) - { - console.log("Please wait until sample has loaded"); - return; - } - if (audioEngineContext.status == 0) - { - interfaceContext.lightbox.post("Message","Please listen to the samples before making a selection"); - console.log("Please listen to the samples before making a selection"); - return; +function comparator(audioHolderObject) { + this.comparatorBox = function (audioElement, id, text) { + this.parent = audioElement; + this.id = id; + this.value = 0; + this.disabled = true; + this.box = document.createElement('div'); + this.box.className = 'comparator-holder'; + this.box.setAttribute('track-id', audioElement.id); + this.box.id = 'comparator-' + text; + this.selector = document.createElement('div'); + this.selector.className = 'comparator-selector disabled'; + var selectorText = document.createElement('span'); + selectorText.textContent = text; + this.selector.appendChild(selectorText); + this.playback = document.createElement('button'); + this.playback.className = 'comparator-button'; + this.playback.disabled = true; + this.playback.textContent = "Listen"; + this.box.appendChild(this.selector); + this.box.appendChild(this.playback); + this.selector.onclick = function (event) { + var time = audioEngineContext.timer.getTestTime(); + if ($(event.currentTarget).hasClass('disabled')) { + console.log("Please wait until sample has loaded"); + return; } - var id = event.currentTarget.parentElement.getAttribute('track-id'); - interfaceContext.comparator.selected = id; + if (audioEngineContext.status == 0) { + interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection"); + console.log("Please listen to the samples before making a selection"); + return; + } + var id = event.currentTarget.parentElement.getAttribute('track-id'); + interfaceContext.comparator.selected = id; if ($(event.currentTarget).hasClass("selected")) { $(".comparator-selector").removeClass('selected'); - for (var i=0; i 122) { + label = "a"; + } + break; + case "none": + label = ""; + break; + case "capital": + default: + if (label.charCodeAt(0) < 65 || label.charCodeAt(0) > 90) { + label = "A"; + } + break; + } + } + for (var index = 0; index < audioHolderObject.audioElements.length; index++) { + var element = audioHolderObject.audioElements[index]; var audioObject = audioEngineContext.newTrack(element); - if (index == audioHolderObject.outsideReference || element.type == 'outside-reference') - { - var orNode = new interfaceContext.outsideReferenceDOM(audioObject,index,document.getElementById("outside-reference-holder")); - audioObject.bindInterface(orNode); + if (index == audioHolderObject.outsideReference || element.type == 'outside-reference') { + var orNode = new interfaceContext.outsideReferenceDOM(audioObject, index, document.getElementById("outside-reference-holder")); + audioObject.bindInterface(orNode); } else { - var label; - switch(audioObject.specification.parent.label) { + var node = new this.comparatorBox(audioObject, index, label); + switch (audioHolderObject.label) { case "none": label = ""; break; case "number": - label = ""+index; + label = (Number(label) + 1).toString(10); break; case "letter": - label = String.fromCharCode(97 + index); + label = String.fromCharCode((label.charCodeAt(0) - 96) % 26 + 97); break; + case "capital": default: - label = String.fromCharCode(65 + index); + label = String.fromCharCode((label.charCodeAt(0) - 64) % 26 + 65); break; } - var node = new this.comparatorBox(audioObject,index,label); audioObject.bindInterface(node); this.comparators.push(node); this.boxHolders.appendChild(node.box); } - } - return this; + } + return this; } -function resizeWindow(event) -{ - document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px'; - var numObj = interfaceContext.comparator.comparators.length; - var boxW = numObj*312; +function resizeWindow(event) { + document.getElementById('submit').style.left = (window.innerWidth - 250) / 2 + 'px'; + var numObj = interfaceContext.comparator.comparators.length; + var boxW = numObj * 312; var diff = window.innerWidth - boxW; - while (diff < 0) - { - numObj = Math.ceil(numObj/2); - boxW = numObj*312; + while (diff < 0) { + numObj = Math.ceil(numObj / 2); + boxW = numObj * 312; diff = window.innerWidth - boxW; } - document.getElementById('box-holders').style.marginLeft = diff/2 + 'px'; - document.getElementById('box-holders').style.marginRight = diff/2 + 'px'; + document.getElementById('box-holders').style.marginLeft = diff / 2 + 'px'; + document.getElementById('box-holders').style.marginRight = diff / 2 + 'px'; document.getElementById('box-holders').style.width = boxW + 'px'; - + var outsideRef = document.getElementById('outside-reference'); - if(outsideRef != null) - { - outsideRef.style.left = (window.innerWidth-120)/2 + 'px'; - } + if (outsideRef != null) { + outsideRef.style.left = (window.innerWidth - 120) / 2 + 'px'; + } } -function buttonSubmitClick() -{ - var checks = []; - checks = checks.concat(testState.currentStateMap.interfaces[0].options); - checks = checks.concat(specification.interfaces.options); - var canContinue = true; - - 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 +function pageXMLSave(store, pageSpecification) { + // MANDATORY + // Saves a specific test page + // You can use this space to add any extra nodes to your XML 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(); +} diff -r dab27ff8cbfa -r b1ba05ef1e7a interfaces/timeline.js --- a/interfaces/timeline.js Thu Nov 03 11:02:56 2016 +0000 +++ b/interfaces/timeline.js Thu Nov 03 11:04:26 2016 +0000 @@ -506,7 +506,7 @@ break; } if (checkState == false) { - canContinue == false; + canContinue = false; } } if (!canContinue) { diff -r dab27ff8cbfa -r b1ba05ef1e7a js/core.js --- a/js/core.js Thu Nov 03 11:02:56 2016 +0000 +++ b/js/core.js Thu Nov 03 11:04:26 2016 +0000 @@ -799,13 +799,13 @@ } else if (node.specification.type == 'number') { var input = document.createElement('input'); input.type = 'textarea'; - if (node.min != null) { + if (node.specification.min != null) { input.min = node.specification.min; } - if (node.max != null) { + if (node.specification.max != null) { input.max = node.specification.max; } - if (node.step != null) { + if (node.specification.step != null) { input.step = node.specification.step; } if (node.response != undefined) { @@ -823,6 +823,30 @@ iframe.className = "youtube"; iframe.src = node.specification.url; this.popupResponse.appendChild(iframe); + } else if (node.specification.type == "slider") { + var hold = document.createElement('div'); + var input = document.createElement('input'); + input.type = 'range'; + input.style.width = "90%"; + if (node.specification.min != null) { + input.min = node.specification.min; + } + if (node.specification.max != null) { + input.max = node.specification.max; + } + if (node.response != undefined) { + input.value = node.response; + } + hold.className = "survey-slider-text-holder"; + var minText = document.createElement('span'); + var maxText = document.createElement('span'); + minText.textContent = node.specification.leftText; + maxText.textContent = node.specification.rightText; + hold.appendChild(minText); + hold.appendChild(maxText); + this.popupResponse.appendChild(input); + this.popupResponse.appendChild(hold); + this.popupResponse.style.textAlign = "center"; } if (this.currentIndex + 1 == this.popupOptions.length) { if (this.node.location == "pre") { @@ -922,6 +946,33 @@ console.log("Checkbox: " + node.specification.statement); var inputs = this.popupResponse.getElementsByTagName('input'); node.response = []; + var numChecked = 0; + for (var i = 0; i < node.specification.options.length; i++) { + if (inputs[i].checked) { + numChecked++; + } + } + if (node.specification.min != undefined) { + if (node.specification.max == undefined) { + if (numChecked < node.specification.min) { + var msg = "You must select at least " + node.specification.min + " option"; + if (node.specification.min > 1) { + msg += "s"; + } + interfaceContext.lightbox.post("Error", msg); + return; + } + } else { + if (numChecked < node.specification.min || numChecked > node.specification.max) { + if (node.specification.min == node.specification.max) { + interfaceContext.lightbox.post("Error", "You must only select " + node.specification.min); + } else { + interfaceContext.lightbox.post("Error", "You must select between " + node.specification.min + " and " + node.specification.max); + } + return; + } + } + } for (var i = 0; i < node.specification.options.length; i++) { node.response.push({ name: node.specification.options[i].name, @@ -1080,6 +1131,49 @@ break; } } + } else if (node.specification.type == 'slider') { + var input = this.popupContent.getElementsByTagName('input')[0]; + node.response = input.value; + for (var condition of node.specification.conditions) { + var pass = false; + switch (condition.check) { + case "contains": + console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING"); + break; + case "greaterThan": + if (node.response > Number(condition.value)) { + pass = true; + } + break; + case "lessThan": + if (node.response < Number(condition.value)) { + pass = true; + } + break; + case "equals": + if (node.response == condition.value) { + pass = true; + } + break; + } + var jumpID; + if (pass) { + jumpID = condition.jumpToOnPass; + } else { + jumpID = condition.jumpToOnFail; + } + if (jumpID != undefined) { + var index = this.popupOptions.findIndex(function (item, index, element) { + if (item.specification.id == jumpID) { + return true; + } else { + return false; + } + }, this); + this.currentIndex = index - 1; + break; + } + } } this.currentIndex++; if (this.currentIndex < this.popupOptions.length) { @@ -1695,21 +1789,20 @@ }; this.setSynchronousLoop = function () { - // Pads the signals so they are all exactly the same length - // Get the length of the longest signal. - var length = 0; + // Pads the signals so they are all exactly the same duration + // Get the duration of the longest signal. + var duration = 0; var maxId; for (var i = 0; i < this.audioObjects.length; i++) { - if (length < this.audioObjects[i].buffer.buffer.length) { - length = this.audioObjects[i].buffer.buffer.length; + if (duration < this.audioObjects[i].buffer.buffer.duration) { + duration = this.audioObjects[i].buffer.buffer.duration; maxId = i; } } // Extract the audio and zero-pad for (var ao of this.audioObjects) { - var lengthDiff = length - ao.buffer.buffer.length; - if (lengthDiff > 0) { - ao.buffer.buffer = ao.buffer.copyBuffer(0, samplesToSeconds(lengthDiff, ao.buffer.buffer.sampleRate)); + if (ao.buffer.buffer.duration !== duration) { + ao.buffer.buffer = ao.buffer.copyBuffer(0, duration - ao.buffer.buffer.duration); } } }; @@ -2604,6 +2697,63 @@ this.resize(); }; + this.sliderBox = function (commentQuestion) { + this.specification = commentQuestion; + this.holder = document.createElement("div"); + this.holder.className = 'comment-div'; + this.string = document.createElement("span"); + this.string.innerHTML = commentQuestion.statement; + this.slider = document.createElement("input"); + this.slider.type = "range"; + this.slider.min = commentQuestion.min; + this.slider.max = commentQuestion.max; + this.slider.step = commentQuestion.step; + this.slider.value = commentQuestion.value; + var br = document.createElement('br'); + + var textHolder = document.createElement("div"); + textHolder.className = "comment-slider-text-holder"; + + this.leftText = document.createElement("span"); + this.leftText.textContent = commentQuestion.leftText; + this.rightText = document.createElement("span"); + this.rightText.textContent = commentQuestion.rightText; + textHolder.appendChild(this.leftText); + textHolder.appendChild(this.rightText); + + this.holder.appendChild(this.string); + this.holder.appendChild(br); + this.holder.appendChild(this.slider); + this.holder.appendChild(textHolder); + + this.exportXMLDOM = function (storePoint) { + var root = storePoint.parent.document.createElement('comment'); + root.id = this.specification.id; + root.setAttribute('type', this.specification.type); + console.log("Question: " + this.string.textContent); + console.log("Response: " + this.slider.value); + var question = storePoint.parent.document.createElement('question'); + question.textContent = this.string.textContent; + var response = storePoint.parent.document.createElement('response'); + response.textContent = this.slider.value; + root.appendChild(question); + root.appendChild(response); + storePoint.XMLDOM.appendChild(root); + return root; + }; + this.resize = function () { + var boxwidth = (window.innerWidth - 100) / 2; + if (boxwidth >= 600) { + boxwidth = 600; + } else if (boxwidth < 400) { + boxwidth = 400; + } + this.holder.style.width = boxwidth + "px"; + this.slider.style.width = boxwidth - 24 + "px"; + }; + this.resize(); + }; + this.createCommentQuestion = function (element) { var node; if (element.type == 'question') { @@ -2612,6 +2762,8 @@ node = new this.radioBox(element); } else if (element.type == 'checkbox') { node = new this.checkboxBox(element); + } else if (element.type == 'slider') { + node = new this.sliderBox(element); } this.commentQuestions.push(node); return node; @@ -3242,14 +3394,17 @@ switch (node.specification.type) { case "number": case "question": + case "slider": var child = this.parent.document.createElement('response'); child.textContent = node.response; surveyresult.appendChild(child); break; case "radio": var child = this.parent.document.createElement('response'); - child.setAttribute('name', node.response.name); - child.textContent = node.response.text; + if (node.response !== null) { + child.setAttribute('name', node.response.name); + child.textContent = node.response.text; + } surveyresult.appendChild(child); break; case "checkbox": diff -r dab27ff8cbfa -r b1ba05ef1e7a js/specification.js --- a/js/specification.js Thu Nov 03 11:02:56 2016 +0000 +++ b/js/specification.js Thu Nov 03 11:04:26 2016 +0000 @@ -1,12 +1,12 @@ function Specification() { - // Handles the decoding of the project specification XML into a simple JavaScript Object. - + // Handles the decoding of the project specification XML into a simple JavaScript Object. + // attributes - this.interface = null; - this.projectReturn = null; + this.interface = null; + this.projectReturn = null; this.returnURL = null; - this.randomiseOrder = null; - this.poolSize = null; + this.randomiseOrder = null; + this.poolSize = null; this.loudness = null; this.sampleRate = null; this.calibration = null; @@ -14,32 +14,31 @@ this.preSilence = null; this.postSilence = null; this.playOne = null; - + // nodes this.metrics = null; this.preTest = undefined; this.postTest = undefined; - this.pages = []; - this.interfaces = null; - this.errors = []; - this.schema = null; + this.pages = []; + this.interfaces = null; + this.errors = []; + this.schema = null; this.exitText = "Thank you."; - - this.processAttribute = function(attribute,schema,schemaRoot) - { - // attribute is the string returned from getAttribute on the XML - // schema is the node - if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) - { - schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0]; - } - var defaultOpt = schema.getAttribute('default'); - if (attribute == null) { - attribute = defaultOpt; - } - var dataType = schema.getAttribute('type'); - if (typeof dataType == "string") { dataType = dataType.substr(3);} - else { + + this.processAttribute = function (attribute, schema, schemaRoot) { + // attribute is the string returned from getAttribute on the XML + // schema is the node + if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) { + schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0]; + } + var defaultOpt = schema.getAttribute('default'); + if (attribute == null) { + attribute = defaultOpt; + } + var dataType = schema.getAttribute('type'); + if (typeof dataType == "string") { + dataType = dataType.substr(3); + } else { var rest = schema.getAllElementsByTagName("xs:restriction").concat(schema.getAllElementsByTagName("xs:enumeration")); if (rest.length > 0) { dataType = rest[0].getAttribute("base"); @@ -52,129 +51,122 @@ dataType = "string"; } } - if (attribute == null) - { - return attribute; - } - switch(dataType) - { - case "boolean": - if (attribute == 'true'){attribute = true;}else{attribute=false;} - break; - case "negativeInteger": - case "positiveInteger": - case "nonNegativeInteger": - case "nonPositiveInteger": - case "integer": - case "decimal": - case "short": - attribute = Number(attribute); - break; - case "string": - default: - attribute = String(attribute); - break; - } - return attribute; - }; - - this.decode = function(projectXML) { - this.errors = []; - // projectXML - DOM Parsed document - this.projectXML = projectXML.childNodes[0]; - var setupNode = projectXML.getElementsByTagName('setup')[0]; - var schemaSetup = this.schema.getAllElementsByName('setup')[0]; - // First decode the attributes - var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); - for (var i=0; i 1) - { - this.errors.push("Only one node in the node allowed! Others except first ingnored!"); - } - this.interfaces = new this.interfaceNode(this); - if (interfaceNode.length != 0) - { - interfaceNode = interfaceNode[0]; - this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); - } - - // Page tags - var pageTags = projectXML.getElementsByTagName('page'); - var pageSchema = this.schema.getAllElementsByName('page')[0]; - for (var i=0; i 1) { + this.errors.push("Only one node in the node allowed! Others except first ingnored!"); + } + this.interfaces = new this.interfaceNode(this); + if (interfaceNode.length != 0) { + interfaceNode = interfaceNode[0]; + this.interfaces.decode(this, interfaceNode, this.schema.getAllElementsByName('interface')[1]); + } + + // Page tags + var pageTags = projectXML.getElementsByTagName('page'); + var pageSchema = this.schema.getAllElementsByName('page')[0]; + for (var i = 0; i < pageTags.length; i++) { + var node = new this.page(this); + node.decode(this, pageTags[i], pageSchema); + this.pages.push(node); + } + }; + + this.encode = function () { + var RootDocument = document.implementation.createDocument(null, "waet"); + var root = RootDocument.firstChild; + root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + root.setAttribute("xsi:noNamespaceSchemaLocation", "test-schema.xsd"); + // Build setup node var setup = RootDocument.createElement("setup"); var schemaSetup = this.schema.getAllElementsByName('setup')[0]; // First decode the attributes var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); - for (var i=0; i is now deprecated. Whilst these will still work, newer nodes and tighter error checking will not be enforced"); + console.log("Please use the newer, type specifc nodes"); + if (!this.type) { + throw ("Type not specified"); + } + } else { + this.type = child.nodeName.split('survey')[1]; + } + this.statement = child.getElementsByTagName('statement')[0].textContent; + if (this.type == "checkbox" || this.type == "radio") { + var children = child.getElementsByTagName('option'); + if (children.length == null) { + console.log('Malformed' + child.nodeName + 'entry'); + this.statement = 'Malformed' + child.nodeName + 'entry'; + this.type = 'statement'; + } else { + this.options = []; + for (var i = 0; i < children.length; i++) { + this.options.push({ + name: children[i].getAttribute('name'), + text: children[i].textContent + }); + } + } + } else if (this.type == "slider") { + this.leftText = ""; + this.rightText = ""; + var minText = child.getElementsByTagName("minText"); + var maxText = child.getElementsByTagName("maxText"); + if (minText.length > 0) { + this.leftText = minText[0].textContent; + } + if (maxText.length > 0) { + this.rightText = maxText[0].textContent; + } + } var conditionElements = child.getElementsByTagName("conditional"); - for (var i=0; i var commentboxprefix = root.createElement("commentboxprefix"); commentboxprefix.textContent = this.commentBoxPrefix; AHNode.appendChild(commentboxprefix); - - for (var i=0; i - for (var i=0; i + for (var i = 0; i < this.commentQuestions.length; i++) { + AHNode.appendChild(this.commentQuestions[i].encode(root)); + } + + AHNode.appendChild(this.preTest.encode(root)); AHNode.appendChild(this.postTest.encode(root)); - return AHNode; - }; - - this.commentQuestionNode = function(specification) { - this.id = null; + return AHNode; + }; + + this.commentQuestionNode = function (specification) { + this.id = null; this.name = undefined; - this.type = undefined; - this.options = []; - this.statement = undefined; - this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; - this.decode = function(parent,xml) - { - this.id = xml.id; + this.type = undefined; + this.statement = undefined; + this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; + this.decode = function (parent, xml) { + this.id = xml.id; this.name = xml.getAttribute('name'); - this.type = xml.getAttribute('type'); - this.statement = xml.getElementsByTagName('statement')[0].textContent; - var optNodes = xml.getElementsByTagName('option'); - for (var i=0; i 0) { + this.leftText = this.leftText[0].textContent; + } else { + this.leftText = ""; + } + this.rightText = xml.getElementsByTagName("maxText"); + if (this.rightText && this.rightText.length > 0) { + this.rightText = this.rightText[0].textContent; + } else { + this.rightText = ""; + } + } + }; + + this.encode = function (root) { + var node; + switch (this.type) { + case "radio": + node = root.createElement("commentradio"); + break; + case "checkbox": + node = root.createElement("commentcheckbox"); + break; + case "slider": + node = root.createElement("commentslider"); + break; + case "question": + default: + node = root.createElement("commentquestion"); + break; + } node.id = this.id; - node.setAttribute("type",this.type); - if (this.name != undefined){node.setAttribute("name",this.name);} + node.setAttribute("type", this.type); + if (this.name != undefined) { + node.setAttribute("name", this.name); + } var statement = root.createElement("statement"); statement.textContent = this.statement; node.appendChild(statement); - for (var option of this.options) - { - var child = root.createElement("option"); - child.setAttribute("name",option.name); - child.textContent = option.text; - node.appendChild(child); + if (this.type == "radio" || this.type == "checkbox") { + for (var option of this.options) { + var child = root.createElement("option"); + child.setAttribute("name", option.name); + child.textContent = option.text; + node.appendChild(child); + } + } + if (this.type == "slider") { + node.setAttribute("min", this.min); + node.setAttribute("max", this.max); + if (this.step !== 1) { + node.setAttribute("step", this.step); + } + if (this.value !== this.min) { + node.setAttribute("value", this.value); + } + if (this.leftText.length > 0) { + var leftText = root.createElement("minText"); + leftText.textContent = this.leftText; + node.appendChild(leftText); + } + if (this.rightText.length > 0) { + var rightText = root.createElement("maxText"); + rightText.textContent = this.rightText; + node.appendChild(rightText); + } } return node; - }; - }; - - this.audioElementNode = function(specification) { - this.url = null; - this.id = null; + }; + }; + + this.audioElementNode = function (specification) { + this.url = null; + this.id = null; this.name = null; - this.parent = null; - this.type = null; - this.marker = null; - this.enforce = false; - this.gain = 0.0; + this.parent = null; + this.type = null; + this.marker = null; + this.enforce = false; + this.gain = 0.0; this.label = null; this.startTime = undefined; this.stopTime = undefined; - this.schema = specification.schema.getAllElementsByName('audioelement')[0];; - this.parent = null; - this.decode = function(parent,xml) - { - this.parent = parent; - var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); - for (var i=0; i= 0) { + this.parent.parent.children.splice(index,1); + } + index = this.parent.parent.specification.conditions.findIndex(function(element){ + if (this == element) {return true;} return false; + },this.parent.specification); + if (index >= 0) { + this.parent.parent.specification.conditions.splice(index); + } + } + } + this.deleteNode.root.textContent = "Delete"; + this.deleteNode.root.addEventListener("click",this.deleteNode); + + this.buttonDOM.appendChild(this.deleteNode.root); + } + + this.addConditional = { + root: document.createElement("button"), + parent: this, + handleEvent: function(event) { + var spec = { + check: null, + value: null, + jumpToOnPass: null, + jumpToOnFail: null + }; + this.parent.specification.conditions.push(spec); + var condition = new Conditional(this.parent,spec); + this.parent.children.push(condition); + this.parent.childrenDOM.appendChild(condition.rootDOM); + } + } + this.addConditional.root.addEventListener("click",this.addConditional); + this.addConditional.root.textContent = "Add Condition"; + this.buttonDOM.appendChild(this.addConditional.root); + this.editNode = { root: document.createElement("button"), parent: this, @@ -2017,6 +2192,12 @@ this.moveButtons.root_down.textContent = "Move Down"; this.buttonDOM.appendChild(this.moveButtons.root_up); this.buttonDOM.appendChild(this.moveButtons.root_down); + + for (var condition of this.specification.conditions) { + var newNode = new Conditional(this,condition); + this.children.push(newNode); + this.childrenDOM.appendChild(newNode.rootDOM); + } } this.addNode = { root: document.createElement("button"), diff -r dab27ff8cbfa -r b1ba05ef1e7a tests/examples/AB_example.xml --- a/tests/examples/AB_example.xml Thu Nov 03 11:02:56 2016 +0000 +++ b/tests/examples/AB_example.xml Thu Nov 03 11:04:26 2016 +0000 @@ -1,97 +1,109 @@ - - - - - Please enter your name. - - - Please select with which activities you have any experience (example checkbox question) - - - - - - - - This is an example of an 'AB'-style test, with two pages, using the test stimuli in 'example_eval/'. - - - - - Please enter your location. (example mandatory text question) - - - Please enter your age (example non-mandatory number question) - - - Please rate this interface (example radio button question) - - - - - - - Thank you for taking this listening test. Please click 'submit' and your results will appear in the 'saves/' folder. - - - - testTimer - elementTimer - elementInitialPosition - elementTracker - elementFlagListenedTo - elementFlagMoved - elementListenTracker - - - - - - - - - - - - Comment on fragment - - Depth - - - - - - A two way comparison using randomised element order, automatic loudness and synchronised looping. - - - - - Please enter the genre. - - - - - Comment on fragment - - Depth - - - - - - - - - - - A 7 way comparison using randomised element order and synchronised looping. - - - - - Please enter the genre. - - - - \ No newline at end of file + + + + + Sliders!! + Lefty + Righty + + + Please enter your name. + + + Please select with which activities you have any experience (example checkbox question) + + + + + + + + This is an example of an 'AB'-style test, with two pages, using the test stimuli in 'example_eval/'. + + + + + Please enter your location. (example mandatory text question) + + + Please enter your age (example non-mandatory number question) + + + Please rate this interface (example radio button question) + + + + + + + Thank you for taking this listening test. Please click 'submit' and your results will appear in the 'saves/' folder. + + + + testTimer + elementTimer + elementInitialPosition + elementTracker + elementFlagListenedTo + elementFlagMoved + elementListenTracker + + + + + + + + + + + + Comment on fragment + + Depth + + + + + + Test + Left + Right + + + + + A two way comparison using randomised element order, automatic loudness and synchronised looping. + + + + + Please enter the genre. + + + + + Comment on fragment + + Depth + + + + + + + + + + + A 7 way comparison using randomised element order and synchronised looping. + + + + + Please enter the genre. + + + + diff -r dab27ff8cbfa -r b1ba05ef1e7a tests/examples/mushra_example.xml --- a/tests/examples/mushra_example.xml Thu Nov 03 11:02:56 2016 +0000 +++ b/tests/examples/mushra_example.xml Thu Nov 03 11:04:26 2016 +0000 @@ -101,24 +101,26 @@ - - What is your general experience with numbers? - - - Please enter your overall preference - - - - - - - - Please describe the overall character - - - - - + + + What is your general experience with numbers? + + + Please enter your overall preference + + + + + + + + Please describe the overall character + + + + + + Example of a 'MUSHRA' style interface with hidden anchor 'zero' (which needs to be below 20%), looping of the samples, randomisation of marker labels, mandatory moving of every sample, and a forced scale usage of at least 25%-75%. diff -r dab27ff8cbfa -r b1ba05ef1e7a tests/examples/project.xml --- a/tests/examples/project.xml Thu Nov 03 11:02:56 2016 +0000 +++ b/tests/examples/project.xml Thu Nov 03 11:04:26 2016 +0000 @@ -6,7 +6,7 @@ Please enter your name. - + Please select with which activities you have any experience (example checkbox question) @@ -111,24 +111,26 @@ - - What is your general experience with numbers? - - - Please enter your overall preference - - - - - - - - Please describe the overall character - - - - - + + + What is your general experience with numbers? + + + Please enter your overall preference + + + + + + + + Please describe the overall character + + + + + + Example of an 'APE' style interface with hidden anchor 'zero' (which needs to be below 20%), looping of the samples, randomisation of marker labels, mandatory moving of every sample, and a forced scale usage of at least 25%-75%. diff -r dab27ff8cbfa -r b1ba05ef1e7a xml/test-schema.xsd --- a/xml/test-schema.xsd Thu Nov 03 11:02:56 2016 +0000 +++ b/xml/test-schema.xsd Thu Nov 03 11:04:26 2016 +0000 @@ -26,8 +26,8 @@ - - + + @@ -75,7 +75,7 @@ - + @@ -96,6 +96,7 @@ + @@ -205,10 +206,21 @@ - + + + + + + + + + + + + - + @@ -221,22 +233,202 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -249,23 +441,6 @@ - - - - - - - - - - - - - - - - - @@ -295,10 +470,18 @@ - + - + + + + + + + + +