# HG changeset patch # User Nicholas Jillings # Date 1489223186 0 # Node ID 78717148d815cd5ab841e7182990be2d816dd5a5 # Parent 66a24a6a03586bb9303612d740912411edbf0c77 #180. Remove null/undefined differences. All undefined === undefined. Specifiction generates good XML diff -r 66a24a6a0358 -r 78717148d815 js/specification.js --- a/js/specification.js Sat Mar 11 08:48:04 2017 +0000 +++ b/js/specification.js Sat Mar 11 09:06:26 2017 +0000 @@ -5,27 +5,26 @@ // Handles the decoding of the project specification XML into a simple JavaScript Object. // attributes - this.interface = null; - this.projectReturn = null; - this.returnURL = null; - this.randomiseOrder = null; - this.poolSize = null; - this.loudness = null; - this.sampleRate = null; - this.calibration = null; - this.crossFade = null; - this.preSilence = null; - this.postSilence = null; - this.playOne = null; + this.interface = undefined; + this.projectReturn = undefined; + this.returnURL = undefined; + this.randomiseOrder = undefined; + this.poolSize = undefined; + this.loudness = undefined; + this.sampleRate = undefined; + this.calibration = undefined; + this.crossFade = undefined; + this.preSilence = undefined; + this.postSilence = undefined; + this.playOne = undefined; // nodes - this.metrics = null; + this.metrics = undefined; this.preTest = undefined; this.postTest = undefined; this.pages = []; - this.interfaces = null; + this.interfaces = undefined; this.errors = []; - this.schema = null; this.exitText = "Thank you."; var processAttribute = function (attribute, schema) { @@ -207,9 +206,9 @@ }; this.surveyNode = function (specification) { - this.location = null; + this.location = undefined; this.options = []; - this.parent = null; + this.parent = undefined; this.schema = schemaRoot.getAllElementsByName('survey')[0]; this.specification = specification; @@ -413,8 +412,8 @@ }; this.interfaceNode = function (specification) { - this.title = null; - this.name = null; + this.title = undefined; + this.name = undefined; this.options = []; this.scales = []; this.schema = schemaRoot.getAllElementsByName('interface')[1]; @@ -438,7 +437,7 @@ var projectAttr = ioNode.getAttribute(attributeName); if (projectAttr !== null) { processAttribute(projectAttr, attributeMap[j]); - this[attributeName] = projectAttr; + option[attributeName] = projectAttr; } } this.options.push(option); @@ -519,21 +518,21 @@ this.hostURL = undefined; this.randomiseOrder = undefined; this.loop = undefined; - this.outsideReference = null; - this.loudness = null; - this.label = null; - this.labelStart = ""; - this.preTest = null; - this.postTest = null; + this.outsideReference = undefined; + this.loudness = undefined; + this.label = undefined; + this.labelStart = undefined; + this.preTest = undefined; + this.postTest = undefined; this.interfaces = []; - this.playOne = null; - this.restrictMovement = null; + this.playOne = undefined; + this.restrictMovement = undefined; this.commentBoxPrefix = "Comment on track"; this.audioElements = []; this.commentQuestions = []; this.schema = schemaRoot.getAllElementsByName("page")[0]; this.specification = specification; - this.parent = null; + this.parent = undefined; this.decode = function (parent, xml) { this.parent = parent; @@ -574,14 +573,14 @@ for (i = 0; i < survey.length; i++) { var location = survey[i].getAttribute('location'); if (location == 'pre' || location == 'before') { - if (this.preTest !== null) { + if (this.preTest !== undefined) { this.errors.push("Already a pre/before test survey defined! Ignoring second!!"); } else { this.preTest = new parent.surveyNode(this.specification); this.preTest.decode(parent, survey[i], surveySchema); } } else if (location == 'post' || location == 'after') { - if (this.postTest !== null) { + if (this.postTest !== undefined) { this.errors.push("Already a post/after test survey defined! Ignoring second!!"); } else { this.postTest = new parent.surveyNode(this.specification); @@ -619,16 +618,13 @@ var i; for (i = 0; i < attributes.length; i++) { var name = attributes[i].getAttribute("name"); - if (name === undefined) { + if (name === null) { name = attributes[i].getAttribute("ref"); } if (this[name] !== undefined || attributes[i].getAttribute("use") == "required") { AHNode.setAttribute(name, this[name]); } } - if (this.loudness !== null) { - AHNode.setAttribute("loudness", this.loudness); - } // var commentboxprefix = root.createElement("commentboxprefix"); commentboxprefix.textContent = this.commentBoxPrefix; @@ -652,7 +648,7 @@ }; this.commentQuestionNode = function (specification) { - this.id = null; + this.id = undefined; this.name = undefined; this.type = undefined; this.statement = undefined; @@ -660,6 +656,9 @@ this.decode = function (parent, xml) { this.id = xml.id; this.name = xml.getAttribute('name'); + if (this.name === null) { + this.name = undefined; + } switch (xml.nodeName) { case "commentradio": this.type = "radio"; @@ -777,21 +776,21 @@ }; this.audioElementNode = function (specification) { - this.url = null; - this.id = null; - this.name = null; - this.parent = null; - this.type = null; - this.marker = null; + this.url = undefined; + this.id = undefined; + this.name = undefined; + this.parent = undefined; + this.type = undefined; + this.marker = undefined; this.enforce = false; this.gain = 0.0; - this.label = null; + this.label = undefined; this.startTime = undefined; this.stopTime = undefined; this.sampleRate = undefined; this.alternatives = []; this.schema = schemaRoot.getAllElementsByName('audioelement')[0]; - this.parent = null; + this.parent = undefined; this.decode = function (parent, xml) { this.parent = parent; var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); @@ -821,7 +820,7 @@ var attributes = this.schema.getAllElementsByTagName('xs:attribute'); for (var i = 0; i < attributes.length; i++) { var name = attributes[i].getAttribute("name"); - if (name === undefined) { + if (name === null) { name = attributes[i].getAttribute("ref"); } if (this[name] !== undefined || attributes[i].getAttribute("use") == "required") {