Mercurial > hg > webaudioevaluationtool
changeset 2680:470bbfd78a96
Merge branch 'vnext' into Dev_main
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Wed, 01 Mar 2017 11:56:08 +0000 |
parents | 628f447a021b (diff) 7ebeb0bffc5a (current diff) |
children | 95f614a82762 |
files | docs/Instructions/Instructions.bib docs/Instructions/Instructions.pdf docs/Instructions/Instructions.tex js/core.js |
diffstat | 1 files changed, 610 insertions(+), 574 deletions(-) [+] |
line wrap: on
line diff
--- a/js/core.js Wed Mar 01 11:53:20 2017 +0000 +++ b/js/core.js Wed Mar 01 11:56:08 2017 +0000 @@ -48,13 +48,13 @@ name = String(name); var selected = this.documentElement.getAllElementsByName(name); return selected; -} +}; Element.prototype.getAllElementsByName = function (name) { name = String(name); var selected = []; var node = this.firstElementChild; - while (node != null) { + while (node !== null) { if (node.getAttribute('name') == name) { selected.push(node); } @@ -64,19 +64,19 @@ node = node.nextElementSibling; } return selected; -} +}; XMLDocument.prototype.getAllElementsByTagName = function (name) { name = String(name); var selected = this.documentElement.getAllElementsByTagName(name); return selected; -} +}; Element.prototype.getAllElementsByTagName = function (name) { name = String(name); var selected = []; var node = this.firstElementChild; - while (node != null) { + while (node !== null) { if (node.nodeName == name) { selected.push(node); } @@ -86,7 +86,7 @@ node = node.nextElementSibling; } return selected; -} +}; // Firefox does not have an XMLDocument.prototype.getElementsByName if (typeof XMLDocument.prototype.getElementsByName != "function") { @@ -94,14 +94,14 @@ name = String(name); var node = this.documentElement.firstElementChild; var selected = []; - while (node != null) { + while (node !== null) { if (node.getAttribute('name') == name) { selected.push(node); } node = node.nextElementSibling; } return selected; - } + }; } var check_dependancies = function () { @@ -122,7 +122,7 @@ return false; } return true; -} +}; var onload = function () { // Function called once the browser has loaded all files. @@ -131,7 +131,7 @@ // Create a web audio API context // Fixed for cross-browser support var AudioContext = window.AudioContext || window.webkitAudioContext; - audioContext = new AudioContext; + audioContext = new AudioContext(); // Create test state testState = new stateMachine(); @@ -152,7 +152,7 @@ interfaceContext.resizeWindow(event); }; - if (window.location.search.length != 0) { + if (window.location.search.length !== 0) { var search = window.location.search.split('?')[1]; // Now split the requests into pairs var searchQueries = search.split('&'); @@ -204,11 +204,11 @@ span.textContent = "There was an error when loading your XML file. Please check your path in the URL. After the path to this page, there should be '?url=path/to/your/file.xml'. Check the spelling of your filename as well. If you are still having issues, check the log of the python server or your webserver distribution for 404 codes for your file."; document.getElementsByTagName('body')[0].appendChild(msg); document.getElementsByTagName('body')[0].appendChild(span); - } + }; r.send(); }; xmlhttp.send(); -}; +} function loadProjectSpecCallback(response) { // Function called after asynchronous download of XML project specification @@ -219,10 +219,11 @@ var parse = new DOMParser(); var responseDocument = parse.parseFromString(response, 'text/xml'); var errorNode = responseDocument.getElementsByTagName('parsererror'); + var msg, span; if (errorNode.length >= 1) { - var msg = document.createElement("h3"); + msg = document.createElement("h3"); msg.textContent = "FATAL ERROR"; - var span = document.createElement("span"); + span = document.createElement("span"); span.textContent = "The XML parser returned the following errors when decoding your XML file"; document.getElementsByTagName('body')[0].innerHTML = null; document.getElementsByTagName('body')[0].appendChild(msg); @@ -230,10 +231,10 @@ document.getElementsByTagName('body')[0].appendChild(errorNode[0]); return; } - if (responseDocument == undefined || responseDocument.firstChild == undefined) { - var msg = document.createElement("h3"); + if (responseDocument === undefined || responseDocument.firstChild === undefined) { + msg = document.createElement("h3"); msg.textContent = "FATAL ERROR"; - var span = document.createElement("span"); + span = document.createElement("span"); span.textContent = "The project XML was not decoded properly, try refreshing your browser and clearing caches. If the problem persists, contact the test creator."; document.getElementsByTagName('body')[0].innerHTML = null; document.getElementsByTagName('body')[0].appendChild(msg); @@ -254,16 +255,16 @@ console.log(xmllint); if (xmllint != 'document.xml validates\n') { document.getElementsByTagName('body')[0].innerHTML = null; - var msg = document.createElement("h3"); + msg = document.createElement("h3"); msg.textContent = "FATAL ERROR"; - var span = document.createElement("h4"); + span = document.createElement("h4"); span.textContent = "The XML validator returned the following errors when decoding your XML file"; document.getElementsByTagName('body')[0].appendChild(msg); document.getElementsByTagName('body')[0].appendChild(span); xmllint = xmllint.split('\n'); for (var i in xmllint) { document.getElementsByTagName('body')[0].appendChild(document.createElement('br')); - var span = document.createElement("span"); + span = document.createElement("span"); span.textContent = xmllint[i]; document.getElementsByTagName('body')[0].appendChild(span); } @@ -278,15 +279,16 @@ // document is a result projectXML = document.implementation.createDocument(null, "waet"); projectXML.firstChild.appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true)); - var child = responseDocument.firstChild.firstChild; - while (child != null) { + var child = responseDocument.firstChild.firstChild, + copy; + while (child !== null) { if (child.nodeName == "survey") { // One of the global survey elements if (child.getAttribute("state") == "complete") { // We need to remove this survey from <setup> var location = child.getAttribute("location"); var globalSurveys = projectXML.getElementsByTagName("setup")[0].getElementsByTagName("survey")[0]; - while (globalSurveys != null) { + while (globalSurveys !== null) { if (location == "pre" || location == "before") { if (globalSurveys.getAttribute("location") == "pre" || globalSurveys.getAttribute("location") == "before") { projectXML.getElementsByTagName("setup")[0].removeChild(globalSurveys); @@ -302,7 +304,7 @@ } } else { // We need to complete this, so it must be regenerated by store - var copy = child; + copy = child; child = child.previousElementSibling; responseDocument.firstChild.removeChild(copy); } @@ -310,7 +312,7 @@ if (child.getAttribute("state") == "empty") { // We need to complete this page projectXML.firstChild.appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true)); - var copy = child; + copy = child; child = child.previousElementSibling; responseDocument.firstChild.removeChild(copy); } @@ -323,7 +325,7 @@ storage.initialise(responseDocument); } /// CHECK FOR SAMPLE RATE COMPATIBILITY - if (specification.sampleRate != undefined) { + if (specification.sampleRate !== null) { if (Number(specification.sampleRate) != audioContext.sampleRate) { var errStr = 'Sample rates do not match! Requested ' + Number(specification.sampleRate) + ', got ' + audioContext.sampleRate + '. Please set the sample rate to match before completing this test.'; interfaceContext.lightbox.post("Error", errStr); @@ -335,7 +337,7 @@ getInterfaces.open("GET", "interfaces/interfaces.json"); getInterfaces.onerror = function (e) { throw (e); - } + }; getInterfaces.onload = function () { if (getInterfaces.status !== 200) { throw (new Error(getInterfaces.status)); @@ -363,14 +365,14 @@ css.setAttribute("href", v); head.appendChild(css); }); - } + }; getInterfaces.send(); - if (gReturnURL != undefined) { + if (gReturnURL !== undefined) { console.log("returnURL Overide from " + specification.returnURL + " to " + gReturnURL); specification.returnURL = gReturnURL; } - if (gSaveFilenamePrefix != undefined) { + if (gSaveFilenamePrefix !== undefined) { specification.saveFilenamePrefix = gSaveFilenamePrefix; } @@ -415,7 +417,7 @@ } } var saveURL = projectReturn + "php/save.php?key=" + storage.SessionKey.key + saveUrlSuffix; - var xmlhttp = new XMLHttpRequest; + var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", saveURL, true); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.onerror = function () { @@ -517,7 +519,7 @@ } function randomString(length) { - var str = "" + var str = ""; for (var i = 0; i < length; i += 2) { var num = Math.floor(Math.random() * 1295); str += num.toString(36); @@ -532,7 +534,7 @@ var inputSequence = []; // For safety purposes: keep track of randomisation for (var counter = 0; counter < N; ++counter) - inputSequence.push(counter) // Fill array + inputSequence.push(counter); // Fill array var inputSequenceClone = inputSequence.slice(0); var holdArr = []; @@ -584,6 +586,443 @@ e.preventDefault(); } }); + // Generators & Processors // + + function processConditional(node, value) { + function jumpToId(jumpID) { + var index = this.popupOptions.findIndex(function (item, index, element) { + if (item.specification.id == jumpID) { + return true; + } else { + return false; + } + }, this); + this.currentIndex = index - 1; + } + var conditionFunction; + if (node.specification.type === "question") { + conditionFunction = processQuestionConditional; + } else if (node.specification.type === "checkbox") { + conditionFunction = processCheckboxConditional; + } else if (node.specification.type === "radio") { + conditionFunction = processRadioConditional; + } else if (node.specifiication.type === "number") { + conditionFunction = processNumberConditional; + } else if (node.specification.type === "slider") { + conditionFunction = processSliderConditional; + } else { + return; + } + for (var i = 0; i < node.specification.conditions.length; i++) { + var condition = node.specification.conditions[i]; + var pass = conditionFunction(condition, value); + var jumpID; + if (pass) { + jumpID = condition.jumpToOnPass; + } else { + jumpID = condition.jumpToOnFail; + } + if (jumpID !== undefined) { + jumpToId.call(this, jumpID); + break; + } + } + } + + function postQuestion(node) { + var textArea = document.createElement('textarea'); + switch (node.specification.boxsize) { + case 'small': + textArea.cols = "20"; + textArea.rows = "1"; + break; + case 'normal': + textArea.cols = "30"; + textArea.rows = "2"; + break; + case 'large': + textArea.cols = "40"; + textArea.rows = "5"; + break; + case 'huge': + textArea.cols = "50"; + textArea.rows = "10"; + break; + } + if (node.response === undefined) { + node.response = ""; + } else { + textArea.value = node.response; + } + this.popupResponse.appendChild(textArea); + textArea.focus(); + this.popupResponse.style.textAlign = "center"; + this.popupResponse.style.left = "0%"; + } + + function processQuestionConditional(condition, value) { + switch (condition.check) { + case "equals": + // Deliberately loose check + if (value == condition.value) { + return true; + } + break; + case "greaterThan": + case "lessThan": + console.log("Survey Element of type 'question' cannot interpret greaterThan/lessThan conditions. IGNORING"); + break; + case "contains": + if (textArea.value.includes(condition.value)) { + return true; + } + break; + } + return false; + } + + function processQuestion(node) { + var textArea = this.popupResponse.getElementsByTagName("textarea")[0]; + if (node.specification.mandatory === true && textArea.value.length === 0) { + interfaceContext.lightbox.post("Error", "This question is mandatory"); + return false; + } + // Save the text content + console.log("Question: " + node.specification.statement); + console.log("Question Response: " + textArea.value); + node.response = textArea.value; + processConditional.call(this, node, textArea.value); + return true; + } + + function postCheckbox(node) { + if (node.response === undefined) { + node.response = Array(node.specification.options.length); + } + var table = document.createElement("table"); + table.className = "popup-option-list"; + table.border = "0"; + node.response = []; + node.specification.options.forEach(function (option, index) { + var tr = document.createElement("tr"); + table.appendChild(tr); + var td = document.createElement("td"); + tr.appendChild(td); + var input = document.createElement('input'); + input.id = option.name; + input.type = 'checkbox'; + td.appendChild(input); + + td = document.createElement("td"); + tr.appendChild(td); + var span = document.createElement('span'); + span.textContent = option.text; + td.appendChild(span); + tr = document.createElement('div'); + tr.setAttribute('name', 'option'); + tr.className = "popup-option-checbox"; + if (node.response[index] !== undefined) { + if (node.response[index].checked === true) { + input.checked = "true"; + } + } + index++; + }); + this.popupResponse.appendChild(table); + } + + function processCheckbox(node) { + console.log("Checkbox: " + node.specification.statement); + var inputs = this.popupResponse.getElementsByTagName('input'); + node.response = []; + var numChecked = 0, + i; + for (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 false; + } + } + } + for (i = 0; i < node.specification.options.length; i++) { + node.response.push({ + name: node.specification.options[i].name, + text: node.specification.options[i].text, + checked: inputs[i].checked + }); + console.log(node.specification.options[i].name + ": " + inputs[i].checked); + } + processConditional.call(this, node, node.response); + return true; + } + + function processCheckboxConditional(condition, response) { + switch (condition.check) { + case "contains": + for (var i = 0; i < response.length; i++) { + var value = response[i]; + if (value.name === condition.value && value.checked) { + return true; + } + } + break; + case "equals": + case "greaterThan": + case "lessThan": + console.log("Survey Element of type 'checkbox' cannot interpret equals/greaterThan/lessThan conditions. IGNORING"); + break; + default: + console.log("Unknown condition. IGNORING"); + break; + } + return false; + } + + function postRadio(node) { + if (node.response === undefined) { + node.response = { + name: "", + text: "" + }; + } + var index = 0; + var table = document.createElement("table"); + table.className = "popup-option-list"; + table.border = "0"; + node.specification.options.forEach(function (option) { + var tr = document.createElement("tr"); + table.appendChild(tr); + var td = document.createElement("td"); + tr.appendChild(td); + var input = document.createElement('input'); + input.id = option.name; + input.type = 'radio'; + input.name = node.specification.id; + td.appendChild(input); + + td = document.createElement("td"); + tr.appendChild(td); + var span = document.createElement('span'); + span.textContent = option.text; + td.appendChild(span); + tr = document.createElement('div'); + tr.setAttribute('name', 'option'); + tr.className = "popup-option-checbox"; + if (node.response[index] !== undefined) { + if (node.response[index].checked === true) { + input.checked = "true"; + } + } + index++; + }); + this.popupResponse.appendChild(table); + } + + function processRadio(node) { + var optHold = this.popupResponse; + console.log("Radio: " + node.specification.statement); + node.response = null; + var i = 0; + var inputs = optHold.getElementsByTagName('input'); + while (node.response === null) { + if (i == inputs.length) { + if (node.specification.mandatory === true) { + interfaceContext.lightbox.post("Error", "Please select one option"); + return false; + } + break; + } + if (inputs[i].checked === true) { + node.response = node.specification.options[i]; + console.log("Selected: " + node.specification.options[i].name); + } + i++; + } + processConditional.call(this, node, node.response); + return true; + } + + function processRadioConditional(condition, response) { + switch (condition.check) { + case "equals": + if (node.response === condition.value) { + return true; + } + break; + case "contains": + case "greaterThan": + case "lessThan": + console.log("Survey Element of type 'radio' cannot interpret contains/greaterThan/lessThan conditions. IGNORING"); + break; + default: + console.log("Unknown condition. IGNORING"); + break; + } + return false; + } + + function postNumber(node) { + var input = document.createElement('input'); + input.type = 'textarea'; + if (node.specification.min !== null) { + input.min = node.specification.min; + } + if (node.specification.max !== null) { + input.max = node.specification.max; + } + if (node.specification.step !== null) { + input.step = node.specification.step; + } + if (node.response !== undefined) { + input.value = node.response; + } + this.popupResponse.appendChild(input); + this.popupResponse.style.textAlign = "center"; + this.popupResponse.style.left = "0%"; + } + + function processNumber(node) { + var input = this.popupContent.getElementsByTagName('input')[0]; + if (node.mandatory === true && input.value.length === 0) { + interfaceContext.lightbox.post("Error", 'This question is mandatory. Please enter a number'); + return false; + } + var enteredNumber = Number(input.value); + if (isNaN(enteredNumber)) { + interfaceContext.lightbox.post("Error", 'Please enter a valid number'); + return false; + } + if (enteredNumber < node.min && node.min !== null) { + interfaceContext.lightbox.post("Error", 'Number is below the minimum value of ' + node.min); + return false; + } + if (enteredNumber > node.max && node.max !== null) { + interfaceContext.lightbox.post("Error", 'Number is above the maximum value of ' + node.max); + return false; + } + node.response = input.value; + processConditional.call(this, node, node.response); + return true; + } + + function processNumberConditional(condtion, value) { + switch (condition.check) { + case "greaterThan": + if (node.response > Number(condition.value)) { + return true; + } + break; + case "lessThan": + if (node.response < Number(condition.value)) { + return true; + } + break; + case "equals": + if (node.response == condition.value) { + return true; + } + break; + case "contains": + console.log("Survey Element of type 'number' cannot interpret \"contains\" conditions. IGNORING"); + break; + default: + console.log("Unknown condition. IGNORING"); + break; + } + return false; + } + + function postVideo(node) { + var video = document.createElement("video"); + video.src = node.specification.url; + this.popupResponse.appendChild(video); + } + + function postYoutube(node) { + var iframe = document.createElement("iframe"); + iframe.className = "youtube"; + iframe.src = node.specification.url; + this.popupResponse.appendChild(iframe); + } + + function postSlider(node) { + 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"; + } + + function processSlider(node) { + var input = this.popupContent.getElementsByTagName('input')[0]; + node.response = input.value; + processConditional.call(this, node, node.response); + return true; + } + + function processSliderConditional(condition, value) { + 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)) { + return true; + } + break; + case "lessThan": + if (node.response < Number(condition.value)) { + return true; + } + break; + case "equals": + if (node.response == condition.value) { + return true; + } + break; + default: + console.log("Unknown condition. IGNORING"); + break; + } + return false; + } this.createPopup = function () { // Create popup window interface @@ -614,7 +1053,7 @@ }; this.showPopup = function () { - if (this.popup == null) { + if (this.popup === null) { this.createPopup(); } this.popup.style.visibility = 'visible'; @@ -641,157 +1080,19 @@ this.popupTitle.innerHTML = ""; this.popupTitle.appendChild(p.parseFromString(converter.makeHtml(node.specification.statement), "text/html").getElementsByTagName("body")[0].firstElementChild); if (node.specification.type == 'question') { - var textArea = document.createElement('textarea'); - switch (node.specification.boxsize) { - case 'small': - textArea.cols = "20"; - textArea.rows = "1"; - break; - case 'normal': - textArea.cols = "30"; - textArea.rows = "2"; - break; - case 'large': - textArea.cols = "40"; - textArea.rows = "5"; - break; - case 'huge': - textArea.cols = "50"; - textArea.rows = "10"; - break; - } - if (node.response == undefined) { - node.response = ""; - } else { - textArea.value = node.response; - } - this.popupResponse.appendChild(textArea); - textArea.focus(); - this.popupResponse.style.textAlign = "center"; - this.popupResponse.style.left = "0%"; + postQuestion.call(this, node); } else if (node.specification.type == 'checkbox') { - if (node.response == undefined) { - node.response = Array(node.specification.options.length); - } - var index = 0; - var table = document.createElement("table"); - table.className = "popup-option-list"; - table.border = "0"; - for (var option of node.specification.options) { - var tr = document.createElement("tr"); - table.appendChild(tr); - var td = document.createElement("td"); - tr.appendChild(td); - var input = document.createElement('input'); - input.id = option.name; - input.type = 'checkbox'; - td.appendChild(input); - - td = document.createElement("td"); - tr.appendChild(td); - var span = document.createElement('span'); - span.textContent = option.text; - td.appendChild(span); - var tr = document.createElement('div'); - tr.setAttribute('name', 'option'); - tr.className = "popup-option-checbox"; - if (node.response[index] != undefined) { - if (node.response[index].checked == true) { - input.checked = "true"; - } - } - index++; - } - this.popupResponse.appendChild(table); + postCheckbox.call(this, node); } else if (node.specification.type == 'radio') { - if (node.response == undefined) { - node.response = { - name: "", - text: "" - }; - } - var index = 0; - var table = document.createElement("table"); - table.className = "popup-option-list"; - table.border = "0"; - for (var option of node.specification.options) { - var tr = document.createElement("tr"); - table.appendChild(tr); - var td = document.createElement("td"); - tr.appendChild(td); - var input = document.createElement('input'); - input.id = option.name; - input.type = 'radio'; - input.name = node.specification.id; - td.appendChild(input); - - td = document.createElement("td"); - tr.appendChild(td); - var span = document.createElement('span'); - span.textContent = option.text; - td.appendChild(span); - var tr = document.createElement('div'); - tr.setAttribute('name', 'option'); - tr.className = "popup-option-checbox"; - if (node.response[index] != undefined) { - if (node.response[index].checked == true) { - input.checked = "true"; - } - } - index++; - } - this.popupResponse.appendChild(table); + postRadio.call(this, node); } else if (node.specification.type == 'number') { - var input = document.createElement('input'); - input.type = 'textarea'; - if (node.specification.min != null) { - input.min = node.specification.min; - } - if (node.specification.max != null) { - input.max = node.specification.max; - } - if (node.specification.step != null) { - input.step = node.specification.step; - } - if (node.response != undefined) { - input.value = node.response; - } - this.popupResponse.appendChild(input); - this.popupResponse.style.textAlign = "center"; - this.popupResponse.style.left = "0%"; + postNumber.call(this, node); } else if (node.specification.type == "video") { - var video = document.createElement("video"); - video.src = node.specification.url; - this.popupResponse.appendChild(video); + postVideo.call(this, node); } else if (node.specification.type == "youtube") { - var iframe = document.createElement("iframe"); - iframe.className = "youtube"; - iframe.src = node.specification.url; - this.popupResponse.appendChild(iframe); + postYoutube.call(this, node); } 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"; + postSlider.call(this, node); } if (this.currentIndex + 1 == this.popupOptions.length) { if (this.node.location == "pre") { @@ -815,12 +1116,12 @@ this.popupOptions = []; this.node = node; this.store = store; - for (var opt of node.options) { + node.options.forEach(function (opt) { this.popupOptions.push({ specification: opt, response: null }); - } + }, this); this.currentIndex = 0; this.showPopup(); this.postNode(); @@ -831,294 +1132,30 @@ this.proceedClicked = function () { // Each time the popup button is clicked! - if (testState.stateIndex == 0 && specification.calibration) { + if (testState.stateIndex === 0 && specification.calibration) { interfaceContext.calibrationModuleObject.collect(); advanceState(); return; } - var node = this.popupOptions[this.currentIndex]; + var node = this.popupOptions[this.currentIndex], + pass = true; if (node.specification.type == 'question') { // Must extract the question data - var textArea = $(popup.popupContent).find('textarea')[0]; - if (node.specification.mandatory == true && textArea.value.length == 0) { - interfaceContext.lightbox.post("Error", "This question is mandatory"); - return; - } else { - // Save the text content - console.log("Question: " + node.specification.statement); - console.log("Question Response: " + textArea.value); - node.response = textArea.value; - } - // Perform the conditional - for (var condition of node.specification.conditions) { - var pass = false; - switch (condition.check) { - case "equals": - if (textArea.value == condition.value) { - pass = true; - } - break; - case "greaterThan": - case "lessThan": - console.log("Survey Element of type 'question' cannot interpret greaterThan/lessThan conditions. IGNORING"); - break; - case "contains": - if (textArea.value.includes(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; - } - } + pass = processQuestion.call(this, node); } else if (node.specification.type == 'checkbox') { // Must extract checkbox data - 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, - text: node.specification.options[i].text, - checked: inputs[i].checked - }); - console.log(node.specification.options[i].name + ": " + inputs[i].checked); - } + pass = processCheckbox.call(this, node); + } else if (node.specification.type == "radio") { // Perform the conditional - for (var condition of node.specification.conditions) { - var pass = false; - switch (condition.check) { - case "equals": - case "greaterThan": - case "lessThan": - console.log("Survey Element of type 'checkbox' cannot interpret equals/greaterThan/lessThan conditions. IGNORING"); - break; - case "contains": - for (var response of node.response) { - if (response.name == condition.value && response.checked) { - pass = true; - break; - } - } - 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; - } - } - } else if (node.specification.type == "radio") { - var optHold = this.popupResponse; - console.log("Radio: " + node.specification.statement); - node.response = null; - var i = 0; - var inputs = optHold.getElementsByTagName('input'); - while (node.response == null) { - if (i == inputs.length) { - if (node.specification.mandatory == true) { - interfaceContext.lightbox.post("Error", "Please select one option"); - return; - } - break; - } - if (inputs[i].checked == true) { - node.response = node.specification.options[i]; - console.log("Selected: " + node.specification.options[i].name); - } - i++; - } + pass = processRadio.call(this, node); + } else if (node.specification.type == "number") { // Perform the conditional - for (var condition of node.specification.conditions) { - var pass = false; - switch (condition.check) { - case "contains": - case "greaterThan": - case "lessThan": - console.log("Survey Element of type 'radio' cannot interpret contains/greaterThan/lessThan conditions. IGNORING"); - 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; - } - } - } else if (node.specification.type == "number") { - var input = this.popupContent.getElementsByTagName('input')[0]; - if (node.mandatory == true && input.value.length == 0) { - interfaceContext.lightbox.post("Error", 'This question is mandatory. Please enter a number'); - return; - } - var enteredNumber = Number(input.value); - if (isNaN(enteredNumber)) { - interfaceContext.lightbox.post("Error", 'Please enter a valid number'); - return; - } - if (enteredNumber < node.min && node.min != null) { - interfaceContext.lightbox.post("Error", 'Number is below the minimum value of ' + node.min); - return; - } - if (enteredNumber > node.max && node.max != null) { - interfaceContext.lightbox.post("Error", 'Number is above the maximum value of ' + node.max); - return; - } - node.response = input.value; - // Perform the conditional - 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; - } - } + pass = processNumber.call(this, node); } 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; - } - } + pass = processSlider.call(this, node); + } + if (pass === false) { + return; } this.currentIndex++; if (this.currentIndex < this.popupOptions.length) { @@ -1128,9 +1165,9 @@ this.popupTitle.innerHTML = ""; this.popupResponse.innerHTML = ""; this.hidePopup(); - for (var node of this.popupOptions) { + this.popupOptions.forEach(function (node) { this.store.postResult(node); - } + }, this); this.store.complete(); advanceState(); } @@ -1146,7 +1183,7 @@ this.resize = function (event) { // Called on window resize; - if (this.popup != null) { + if (this.popup !== null) { this.popup.style.left = (window.innerWidth / 2) - 250 + 'px'; this.popup.style.top = (window.innerHeight / 2) - 125 + 'px'; var blank = document.getElementsByClassName('testHalt')[0]; @@ -1156,16 +1193,16 @@ }; this.hideNextButton = function () { this.buttonProceed.style.visibility = "hidden"; - } + }; this.hidePreviousButton = function () { this.buttonPrevious.style.visibility = "hidden"; - } + }; this.showNextButton = function () { this.buttonProceed.style.visibility = "visible"; - } + }; this.showPreviousButton = function () { this.buttonPrevious.style.visibility = "visible"; - } + }; } function advanceState() { @@ -1187,7 +1224,8 @@ // Get the data from Specification var pagePool = []; var pageInclude = []; - for (var page of specification.pages) { + for (var i = 0; i < specification.pages.length; i++) { + var page = specification.pages[i]; if (page.alwaysInclude) { pageInclude.push(page); } else { @@ -1201,7 +1239,7 @@ console.log("WARNING - You have specified more pages in <setup poolSize> than you have created!!"); numPages = specification.pages.length; } - if (specification.poolSize == 0) { + if (specification.poolSize === 0) { numPages = specification.pages.length; } numPages -= pageInclude.length; @@ -1227,7 +1265,7 @@ pageInclude[i].presentedId = i; this.stateMap.push(pageInclude[i]); // For each selected page, we must get the sub pool - if (pageInclude[i].poolSize != 0 && pageInclude[i].poolSize != pageInclude[i].audioElements.length) { + if (pageInclude[i].poolSize !== 0 && pageInclude[i].poolSize !== pageInclude[i].audioElements.length) { var elemInclude = []; var elemPool = []; for (var elem of pageInclude[i].audioElements) { @@ -1244,15 +1282,15 @@ audioEngineContext.loadPageData(pageInclude[i]); } - if (specification.preTest != null) { + if (specification.preTest !== null) { this.preTestSurvey = specification.preTest; } - if (specification.postTest != null) { + if (specification.postTest !== null) { this.postTestSurvey = specification.postTest; } if (this.stateMap.length > 0) { - if (this.stateIndex != null) { + if (this.stateIndex !== null) { console.log('NOTE - State already initialise'); } this.stateIndex = -2; @@ -1262,7 +1300,7 @@ } }; this.advanceState = function () { - if (this.stateIndex == null) { + if (this.stateIndex === null) { this.initialise(); } if (this.stateIndex > -2) { @@ -1270,7 +1308,7 @@ } if (this.stateIndex == -2) { this.stateIndex++; - if (this.preTestSurvey != null) { + if (this.preTestSurvey !== null) { popup.initState(this.preTestSurvey, storage.globalPreTest); } else { this.advanceState(); @@ -1290,7 +1328,7 @@ // All test pages complete, post test console.log('Ending test ...'); this.stateIndex++; - if (this.postTestSurvey == null) { + if (this.postTestSurvey === null) { this.advanceState(); } else { popup.initState(this.postTestSurvey, storage.globalPostTest); @@ -1299,7 +1337,7 @@ createProjectSave(specification.projectReturn); } else { popup.hidePopup(); - if (this.currentStateMap == null) { + if (this.currentStateMap === null) { this.currentStateMap = this.stateMap[this.stateIndex]; // Find and extract the outside reference var elements = [], @@ -1319,7 +1357,7 @@ this.currentStateMap.audioElements = elements.concat(ref); this.currentStore = storage.testPages[this.stateIndex]; - if (this.currentStateMap.preTest != null) { + if (this.currentStateMap.preTest !== null) { this.currentStatePosition = 'pre'; popup.initState(this.currentStateMap.preTest, storage.testPages[this.stateIndex].preTest); } else { @@ -1336,7 +1374,7 @@ this.currentStatePosition = 'post'; // Save the data this.testPageCompleted(); - if (this.currentStateMap.postTest == null) { + if (this.currentStateMap.postTest === null) { this.advanceState(); return; } else { @@ -1348,7 +1386,7 @@ this.currentStateMap = null; this.advanceState(); break; - }; + } } }; @@ -1382,14 +1420,14 @@ } else { return null; } - } + }; this.getCurrentTestPageStore = function () { if (this.stateIndex >= 0 && this.stateIndex < this.stateMap.length) { return this.currentStore; } else { return null; } - } + }; } function AudioEngine(specification) { @@ -1444,7 +1482,7 @@ } for (var i = 0; i < this.users.length; i++) { this.users[i].state = 1; - if (this.users[i].interfaceDOM != null) { + if (this.users[i].interfaceDOM !== null) { this.users[i].bufferLoaded(this); } } @@ -1472,7 +1510,7 @@ } } return false; - } + }; this.getMedia = function () { var self = this; var currentUrlIndex = 0; @@ -1516,7 +1554,7 @@ return true; }, function (e) { var waveObj = new WAVE(); - if (waveObj.open(response) == 0) { + if (waveObj.open(response) === 0) { self.buffer = audioContext.createBuffer(waveObj.num_channels, waveObj.num_samples, waveObj.sample_rate); for (var c = 0; c < waveObj.num_channels; c++) { var buffer_ptr = self.buffer.getChannelData(c); @@ -1524,14 +1562,13 @@ buffer_ptr[n] = waveObj.decoded_data[c][n]; } } - - delete waveObj; } - if (self.buffer != undefined) { + if (self.buffer !== undefined) { self.status = 2; calculateLoudness(self, "I"); return true; } + waveObj = undefined; return false; }); } @@ -1541,7 +1578,7 @@ this.status = -1; for (var i = 0; i < this.users.length; i++) { this.users[i].state = -1; - if (this.users[i].interfaceDOM != null) { + if (this.users[i].interfaceDOM !== null) { this.users[i].bufferLoaded(this); } } @@ -1552,7 +1589,7 @@ if (event.lengthComputable) { this.progress = event.loaded / event.total; for (var i = 0; i < this.users.length; i++) { - if (this.users[i].interfaceDOM != null) { + if (this.users[i].interfaceDOM !== null) { if (typeof this.users[i].interfaceDOM.updateLoading === "function") { this.users[i].interfaceDOM.updateLoading(this.progress * 100); } @@ -1584,10 +1621,10 @@ this.copyBuffer = function (preSilenceTime, postSilenceTime) { // Copies the entire bufferObj. - if (preSilenceTime == undefined) { + if (preSilenceTime === undefined) { preSilenceTime = 0; } - if (postSilenceTime == undefined) { + if (postSilenceTime === undefined) { postSilenceTime = 0; } var preSilenceSamples = secondsToSamples(preSilenceTime, this.buffer.sampleRate); @@ -1595,7 +1632,7 @@ var newLength = this.buffer.length + preSilenceSamples + postSilenceSamples; var copybuffer = audioContext.createBuffer(this.buffer.numberOfChannels, newLength, this.buffer.sampleRate); // Now we can use some efficient background copy schemes if we are just padding the end - if (preSilenceSamples == 0 && typeof copybuffer.copyToChannel == "function") { + if (preSilenceSamples === 0 && typeof copybuffer.copyToChannel === "function") { for (var c = 0; c < this.buffer.numberOfChannels; c++) { copybuffer.copyToChannel(this.buffer.getChannelData(c), c); } @@ -1611,7 +1648,7 @@ copybuffer.lufs = this.buffer.lufs; copybuffer.playbackGain = this.buffer.playbackGain; return copybuffer; - } + }; this.cropBuffer = function (startTime, stopTime) { // Copy and return the cropped buffer @@ -1632,7 +1669,7 @@ } } return copybuffer; - } + }; }; this.loadPageData = function (page) { @@ -1646,7 +1683,7 @@ break; } } - if (buffer == null) { + if (buffer === null) { buffer = new this.bufferObj(); var urls = [{ url: URL, @@ -1667,15 +1704,15 @@ this.play = function (id) { // Start the timer and set the audioEngine state to playing (1) - if (this.status == 0) { + if (this.status === 0) { // Check if all audioObjects are ready this.bufferReady(id); } else { this.status = 1; } - if (this.status == 1) { + if (this.status === 1) { this.timer.startTest(); - if (id == undefined) { + if (id === undefined) { id = -1; console.error('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); return; @@ -1734,7 +1771,7 @@ break; } } - if (buffer == null) { + if (buffer === null) { console.log("[WARN]: Buffer was not loaded in pre-test! " + URL); buffer = new this.bufferObj(); this.buffers.push(buffer); @@ -1772,7 +1809,7 @@ this.checkAllPlayed = function () { arr = []; for (var id = 0; id < this.audioObjects.length; id++) { - if (this.audioObjects[id].metric.wasListenedTo == false) { + if (this.audioObjects[id].metric.wasListenedTo === false) { arr.push(this.audioObjects[id].id); } } @@ -1782,11 +1819,11 @@ this.checkAllReady = function () { var ready = true; for (var i = 0; i < this.audioObjects.length; i++) { - if (this.audioObjects[i].state == 0) { + if (this.audioObjects[i].state === 0) { // Track not ready console.log('WAIT -- audioObject ' + i + ' not ready yet!'); ready = false; - }; + } } return ready; }; @@ -1819,7 +1856,7 @@ return true; } return false; - } + }; this.exportXML = function () { @@ -1861,7 +1898,7 @@ if (callee.status == -1) { // ERROR this.state = -1; - if (this.interfaceDOM != null) { + if (this.interfaceDOM !== null) { this.interfaceDOM.error(); } this.buffer = callee; @@ -1875,7 +1912,7 @@ var copybuffer = new callee.constructor(); copybuffer.buffer = callee.cropBuffer(startTime || 0, stopTime || callee.buffer.duration); - if (preSilenceTime != 0 || postSilenceTime != 0) { + if (preSilenceTime !== 0 || postSilenceTime !== 0) { copybuffer.buffer = copybuffer.copyBuffer(preSilenceTime, postSilenceTime); } @@ -1888,7 +1925,7 @@ } else { this.buffer.buffer.playbackGain = 1.0; } - if (this.interfaceDOM != null) { + if (this.interfaceDOM !== null) { this.interfaceDOM.enable(); } this.onplayGain = decibelToLinear(this.specification.gain) * (this.buffer.buffer.playbackGain || 1.0); @@ -1917,7 +1954,7 @@ }; this.loopStop = function (setTime) { - if (this.outputGain.gain.value != 0.0) { + if (this.outputGain.gain.value !== 0.0) { this.outputGain.gain.linearRampToValueAtTime(0.0, setTime); this.metric.stopListening(audioEngineContext.timer.getTestTime()); } @@ -1925,7 +1962,7 @@ }; this.play = function (startTime) { - if (this.bufferNode == undefined && this.buffer.buffer != undefined) { + if (this.bufferNode === undefined && this.buffer.buffer !== undefined) { this.bufferNode = audioContext.createBufferSource(); this.bufferNode.owner = this; this.bufferNode.connect(this.outputGain); @@ -1934,7 +1971,7 @@ this.bufferNode.onended = function (event) { // Safari does not like using 'this' to reference the calling object! //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); - if (event.currentTarget != null) { + if (event.currentTarget !== null) { event.currentTarget.owner.stop(audioContext.currentTime + 1); } }; @@ -1959,7 +1996,7 @@ this.stop = function (stopTime) { this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); - if (this.bufferNode != undefined) { + if (this.bufferNode !== undefined) { this.metric.stopListening(audioEngineContext.timer.getTestTime(), this.getCurrentPosition()); this.bufferNode.stop(stopTime); this.bufferNode = undefined; @@ -1970,7 +2007,7 @@ this.getCurrentPosition = function () { var time = audioEngineContext.timer.getTestTime(); - if (this.bufferNode != undefined) { + if (this.bufferNode !== undefined) { var position = (time - this.bufferNode.playbackStartTime) % this.buffer.buffer.duration; if (isNaN(position)) { return 0; @@ -1990,8 +2027,8 @@ this.storeDOM.appendChild(file); if (this.specification.type != 'outside-reference') { var interfaceXML = this.interfaceDOM.exportXMLDOM(this); - if (interfaceXML != null) { - if (interfaceXML.length == undefined) { + if (interfaceXML !== null) { + if (interfaceXML.length === undefined) { this.storeDOM.appendChild(interfaceXML); } else { for (var i = 0; i < interfaceXML.length; i++) { @@ -1999,7 +2036,7 @@ } } } - if (this.commentDOM != null) { + if (this.commentDOM !== null) { this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this)); } } @@ -2020,7 +2057,7 @@ this.testDuration = 0; this.minimumTestTime = 0; // No minimum test time this.startTest = function () { - if (this.testStarted == false) { + if (this.testStarted === false) { this.testStartTime = audioContext.currentTime; this.testStarted = true; this.updateTestTime(); @@ -2128,7 +2165,7 @@ }; this.startListening = function (time) { - if (this.listenHold == false) { + if (this.listenHold === false) { this.wasListenedTo = true; this.listenStart = time; this.listenHold = true; @@ -2147,7 +2184,7 @@ }; this.stopListening = function (time, bufferStopTime) { - if (this.listenHold == true) { + if (this.listenHold === true) { var diff = time - this.listenStart; this.listenedTimer += (diff); this.listenStart = 0; @@ -2157,7 +2194,7 @@ var testTime = evnt.getElementsByTagName('testTime')[0]; var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; testTime.setAttribute('stop', time); - if (bufferStopTime == undefined) { + if (bufferStopTime === undefined) { bufferTime.setAttribute('stop', this.parent.getCurrentPosition()); } else { bufferTime.setAttribute('stop', bufferStopTime); @@ -2214,9 +2251,9 @@ if (audioEngineContext.metric.enableFlagComments) { var flagComments = storage.document.createElement('metricresult'); flagComments.setAttribute('name', 'elementFlagComments'); - if (this.parent.commentDOM == null) { + if (this.parent.commentDOM === null) { flag.textContent = 'false'; - } else if (this.parent.commentDOM.textContent.length == 0) { + } else if (this.parent.commentDOM.textContent.length === 0) { flag.textContent = 'false'; } else { flag.textContet = 'true'; @@ -2303,7 +2340,7 @@ hold.appendChild(time); return hold; - } + }; this.lightbox = { parent: this, @@ -2345,7 +2382,7 @@ resize: function (event) { this.root.style.left = (window.innerWidth / 2) - 250 + 'px'; } - } + }; this.lightbox.root.appendChild(this.lightbox.content); this.lightbox.root.appendChild(this.lightbox.accept); @@ -2434,7 +2471,7 @@ }; this.deleteCommentBoxes = function () { - if (this.injectPoint != null) { + if (this.injectPoint !== null) { for (var box of this.boxes) { this.injectPoint.removeChild(box.trackComment); } @@ -2442,7 +2479,7 @@ } this.boxes = []; }; - } + }; this.commentQuestions = []; @@ -2552,7 +2589,7 @@ question.textContent = this.string.textContent; var response = document.createElement('response'); var i = 0; - while (this.options[i].checked == false) { + while (this.options[i].checked === false) { i++; if (i >= this.options.length) { break; @@ -2589,7 +2626,7 @@ options.style.marginLeft = spanMargin; text.style.marginRight = spanMargin; text.style.marginLeft = spanMargin; - while (options.nextSibling != undefined) { + while (options.nextSibling !== undefined) { options = options.nextSibling; text = text.nextSibling; options.style.marginRight = spanMargin; @@ -2688,7 +2725,7 @@ options.style.marginLeft = spanMargin; text.style.marginRight = spanMargin; text.style.marginLeft = spanMargin; - while (options.nextSibling != undefined) { + while (options.nextSibling !== undefined) { options = options.nextSibling; text = text.nextSibling; options.style.marginRight = spanMargin; @@ -2828,8 +2865,8 @@ // audioObject has an error!! this.outsideReferenceHolder.textContent = "Error"; this.outsideReferenceHolder.style.backgroundColor = "#F00"; - } - } + }; + }; this.playhead = new function () { this.object = document.createElement('div'); @@ -2900,7 +2937,7 @@ this.interval = undefined; this.start = function () { - if (this.playbackObject != undefined && this.interval == undefined) { + if (this.playbackObject !== undefined && this.interval === undefined) { if (this.maxTime < 60) { this.interval = setInterval(function () { interfaceContext.playhead.update(); @@ -2951,10 +2988,10 @@ interfaceContext.volume.valueLin = decibelToLinear(interfaceContext.volume.valueDB); interfaceContext.volume.valueText.textContent = interfaceContext.volume.valueDB + 'dB'; audioEngineContext.outputGain.gain.value = interfaceContext.volume.valueLin; - } + }; this.slider.onmouseup = function (event) { var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker'); - if (storePoint.length == 0) { + if (storePoint.length === 0) { storePoint = storage.document.createElement('metricresult'); storePoint.setAttribute('name', 'volumeTracker'); testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].appendChild(storePoint); @@ -2966,7 +3003,7 @@ node.setAttribute('volume', interfaceContext.volume.valueDB); node.setAttribute('format', 'dBFS'); storePoint.appendChild(node); - } + }; var title = document.createElement('div'); title.innerHTML = '<span>Master Volume Control</span>'; @@ -2980,12 +3017,12 @@ this.resize = function (event) { if (window.innerWidth < 1000) { - this.object.className = "master-volume-holder-inline" + this.object.className = "master-volume-holder-inline"; } else { this.object.className = 'master-volume-holder-float'; } - } - } + }; + }; this.calibrationModuleObject = null; this.calibrationModule = function () { @@ -3025,7 +3062,7 @@ audioEngineContext.outputGain.gain.value = value; interfaceContext.volume.slider.value = this.input.value; } else { - this.gain.gain.value = value + this.gain.gain.value = value; } break; } @@ -3033,7 +3070,7 @@ disconnect: function () { this.gain.disconnect(); } - } + }; obj.root.className = "calibration-slider"; obj.root.appendChild(obj.input); obj.oscillator.connect(obj.gain); @@ -3061,7 +3098,7 @@ f0 *= 2; } inject.appendChild(this.holder); - } + }; this.collect = function () { for (var obj of this.calibrationNodes) { var node = storage.document.createElement("calibrationresult"); @@ -3071,8 +3108,8 @@ node.setAttribute("gain-lin", obj.gain.gain.value); this.storeDOM.appendChild(node); } - } - } + }; + }; // Global Checkers @@ -3131,13 +3168,13 @@ break; } } - if (passed == false) { + if (passed === false) { check_pass = false; console.log("Continue listening to track-" + object.interfaceDOM.getPresentedId()); error_obj.push(object.interfaceDOM.getPresentedId()); } } - if (check_pass == false) { + if (check_pass === false) { var str_start = "You have not completely listened to fragments "; for (var i = 0; i < error_obj.length; i++) { str_start += error_obj[i]; @@ -3157,11 +3194,11 @@ var str = "You have not moved "; var failed = []; for (var ao of audioEngineContext.audioObjects) { - if (ao.metric.wasMoved == false && ao.interfaceDOM.canMove() == true) { + if (ao.metric.wasMoved === false && ao.interfaceDOM.canMove() === true) { failed.push(ao.interfaceDOM.getPresentedId()); } } - if (failed.length == 0) { + if (failed.length === 0) { return true; } else if (failed.length == 1) { str += 'track ' + failed[0]; @@ -3182,11 +3219,11 @@ var str = "You have not played "; var failed = []; for (var ao of audioEngineContext.audioObjects) { - if (ao.metric.wasListenedTo == false) { + if (ao.metric.wasListenedTo === false) { failed.push(ao.interfaceDOM.getPresentedId()); } } - if (failed.length == 0) { + if (failed.length === 0) { return true; } else if (failed.length == 1) { str += 'track ' + failed[0]; @@ -3218,7 +3255,7 @@ } } return true; - } + }; this.checkScaleRange = function (min, max) { var page = testState.getCurrentTestPage(); var audioObjects = audioEngineContext.audioObjects; @@ -3240,7 +3277,7 @@ state = false; } if (maxRanking * 100 < max) { - str += "At least one fragment must be above the " + max + " mark." + str += "At least one fragment must be above the " + max + " mark."; state = false; } if (!state) { @@ -3249,7 +3286,7 @@ interfaceContext.lightbox.post("Error", str); } return state; - } + }; this.storeErrorNode = function (errorMessage) { var time = audioEngineContext.timer.getTestTime(); @@ -3274,13 +3311,12 @@ case "capital": return String.fromCharCode((index + offset) % 26 + 65); case "samediff": - if (index == 0) { + if (index === 0) { return "Same"; } else if (index == 1) { return "Difference"; - } else { - return ""; } + return ""; case "number": return String(index + offset); default: @@ -3288,7 +3324,7 @@ } } - if (typeof labelStart !== "string" || labelStart.length == 0) { + if (typeof labelStart !== "string" || labelStart.length === 0) { labelStart = String.fromCharCode(0); } @@ -3330,7 +3366,7 @@ } else { throw ("Invalid arguments"); } - } + }; this.getCombinedInterfaces = function (page) { // Combine the interfaces with the global interface nodes @@ -3355,7 +3391,7 @@ } }); return local; - } + }; } function Storage() { @@ -3368,7 +3404,7 @@ this.state = 0; this.initialise = function (existingStore) { - if (existingStore == undefined) { + if (existingStore === undefined) { // We need to get the sessionKey this.SessionKey.requestKey(); this.document = document.implementation.createDocument(null, "waetresult", null); @@ -3384,10 +3420,10 @@ this.root = existingStore.firstChild; this.SessionKey.key = this.root.getAttribute("key"); } - if (specification.preTest != undefined) { + if (specification.preTest !== undefined) { this.globalPreTest = new this.surveyNode(this, this.root, specification.preTest); } - if (specification.postTest != undefined) { + if (specification.postTest !== undefined) { this.globalPostTest = new this.surveyNode(this, this.root, specification.postTest); } }; @@ -3399,7 +3435,7 @@ handleEvent: function () { var parse = new DOMParser(); var xml = parse.parseFromString(this.request.response, "text/xml"); - if (this.request.response.length == 0) { + if (this.request.response.length === 0) { console.error("An unspecified error occured, no server key could be generated"); return; } @@ -3432,7 +3468,7 @@ this.request.send(); }, update: function () { - if (this.key == null) { + if (this.key === null) { console.log("Cannot save as key == null"); return; } @@ -3467,10 +3503,10 @@ console.log("Intermediate save: Error! " + message.textContent); } } - } + }; xmlhttp.send([hold.innerHTML]); } - } + }; this.createTestPageStore = function (specification) { var store = new this.pageNode(this, specification); @@ -3502,7 +3538,7 @@ return; } var surveyresult = this.XMLDOM.firstChild; - while (surveyresult != null) { + while (surveyresult !== null) { if (surveyresult.getAttribute("ref") == node.specification.id) { break; } @@ -3525,7 +3561,7 @@ surveyresult.appendChild(child); break; case "checkbox": - if (node.response == undefined) { + if (node.response === undefined) { surveyresult.appendChild(this.parent.document.createElement('response')); break; } @@ -3541,7 +3577,7 @@ this.complete = function () { this.state = "complete"; this.XMLDOM.setAttribute("state", this.state); - } + }; }; this.pageNode = function (parent, specification) { @@ -3553,10 +3589,10 @@ this.XMLDOM.setAttribute('ref', specification.id); this.XMLDOM.setAttribute('presentedId', specification.presentedId); this.XMLDOM.setAttribute("state", this.state); - if (specification.preTest != undefined) { + if (specification.preTest !== undefined) { this.preTest = new this.parent.surveyNode(this.parent, this.XMLDOM, this.specification.preTest); } - if (specification.postTest != undefined) { + if (specification.postTest !== undefined) { this.postTest = new this.parent.surveyNode(this.parent, this.XMLDOM, this.specification.postTest); } @@ -3568,9 +3604,9 @@ for (var element of this.specification.audioElements) { var aeNode = this.parent.document.createElement('audioelement'); aeNode.setAttribute('ref', element.id); - if (element.name != undefined) { - aeNode.setAttribute('name', element.name) - }; + if (element.name !== undefined) { + aeNode.setAttribute('name', element.name); + } aeNode.setAttribute('type', element.type); aeNode.setAttribute('url', element.url); aeNode.setAttribute('fqurl', qualifyURL(element.url)); @@ -3590,13 +3626,13 @@ this.complete = function () { this.state = "complete"; this.XMLDOM.setAttribute("state", "complete"); - } + }; }; this.update = function () { this.SessionKey.update(); - } + }; this.finish = function () { - if (this.state == 0) { + if (this.state === 0) { this.update(); } this.state = 1;