Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1348:a2b096969d59
Added common .getAllElementsByName and .getAllElementsByTagName to aid cross-browser differences in specification.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 14 Jan 2016 15:20:31 +0000 |
parents | e3bc0083d515 |
children | 0fb2b60326d0 |
comparison
equal
deleted
inserted
replaced
1347:e3bc0083d515 | 1348:a2b096969d59 |
---|---|
23 AudioBufferSourceNode.prototype.owner = undefined; | 23 AudioBufferSourceNode.prototype.owner = undefined; |
24 // Add a prototype to the bufferNode to hold the desired LINEAR gain | 24 // Add a prototype to the bufferNode to hold the desired LINEAR gain |
25 AudioBuffer.prototype.playbackGain = undefined; | 25 AudioBuffer.prototype.playbackGain = undefined; |
26 // Add a prototype to the bufferNode to hold the computed LUFS loudness | 26 // Add a prototype to the bufferNode to hold the computed LUFS loudness |
27 AudioBuffer.prototype.lufs = undefined; | 27 AudioBuffer.prototype.lufs = undefined; |
28 | |
29 // Firefox does not have an XMLDocument.prototype.getElementsByName | |
30 // and there is no searchAll style command, this custom function will | |
31 // search all children recusrively for the name. Used for XSD where all | |
32 // element nodes must have a name and therefore can pull the schema node | |
33 XMLDocument.prototype.getAllElementsByName = function(name) | |
34 { | |
35 name = String(name); | |
36 var selected = this.documentElement.getAllElementsByName(name); | |
37 return selected; | |
38 } | |
39 | |
40 Element.prototype.getAllElementsByName = function(name) | |
41 { | |
42 name = String(name); | |
43 var selected = []; | |
44 var node = this.firstElementChild; | |
45 while(node != null) | |
46 { | |
47 if (node.getAttribute('name') == name) | |
48 { | |
49 selected.push(node); | |
50 } | |
51 if (node.childElementCount > 0) | |
52 { | |
53 selected = selected.concat(node.getAllElementsByName(name)); | |
54 } | |
55 node = node.nextElementSibling; | |
56 } | |
57 return selected; | |
58 } | |
59 | |
60 XMLDocument.prototype.getAllElementsByTagName = function(name) | |
61 { | |
62 name = String(name); | |
63 var selected = this.documentElement.getAllElementsByTagName(name); | |
64 return selected; | |
65 } | |
66 | |
67 Element.prototype.getAllElementsByTagName = function(name) | |
68 { | |
69 name = String(name); | |
70 var selected = []; | |
71 var node = this.firstElementChild; | |
72 while(node != null) | |
73 { | |
74 if (node.nodeName == name) | |
75 { | |
76 selected.push(node); | |
77 } | |
78 if (node.childElementCount > 0) | |
79 { | |
80 selected = selected.concat(node.getAllElementsByTagName(name)); | |
81 } | |
82 node = node.nextElementSibling; | |
83 } | |
84 return selected; | |
85 } | |
86 | |
87 // Firefox does not have an XMLDocument.prototype.getElementsByName | |
88 if (typeof XMLDocument.prototype.getElementsByName != "function") { | |
89 XMLDocument.prototype.getElementsByName = function(name) | |
90 { | |
91 name = String(name); | |
92 var node = this.documentElement.firstElementChild; | |
93 var selected = []; | |
94 while(node != null) | |
95 { | |
96 if (node.getAttribute('name') == name) | |
97 { | |
98 selected.push(node); | |
99 } | |
100 node = node.nextElementSibling; | |
101 } | |
102 return selected; | |
103 } | |
104 } | |
28 | 105 |
29 window.onload = function() { | 106 window.onload = function() { |
30 // Function called once the browser has loaded all files. | 107 // Function called once the browser has loaded all files. |
31 // This should perform any initial commands such as structure / loading documents | 108 // This should perform any initial commands such as structure / loading documents |
32 | 109 |
1179 this.buffer = callee; | 1256 this.buffer = callee; |
1180 } | 1257 } |
1181 this.state = 1; | 1258 this.state = 1; |
1182 this.buffer.buffer.playbackGain = callee.buffer.playbackGain; | 1259 this.buffer.buffer.playbackGain = callee.buffer.playbackGain; |
1183 this.buffer.buffer.lufs = callee.buffer.lufs; | 1260 this.buffer.buffer.lufs = callee.buffer.lufs; |
1184 var targetLUFS = this.specification.parent.loudness; | 1261 var targetLUFS = this.specification.parent.loudness || specification.loudness; |
1185 if (typeof targetLUFS === "number") | 1262 if (typeof targetLUFS === "number") |
1186 { | 1263 { |
1187 this.buffer.buffer.playbackGain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs); | 1264 this.buffer.buffer.playbackGain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs); |
1188 } else { | 1265 } else { |
1189 this.buffer.buffer.playbackGain = 1.0; | 1266 this.buffer.buffer.playbackGain = 1.0; |
1653 { | 1730 { |
1654 // attribute is the string returned from getAttribute on the XML | 1731 // attribute is the string returned from getAttribute on the XML |
1655 // schema is the <xs:attribute> node | 1732 // schema is the <xs:attribute> node |
1656 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) | 1733 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) |
1657 { | 1734 { |
1658 schema = this.schema.getElementsByName(schema.getAttribute('ref'))[0]; | 1735 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; |
1659 } | 1736 } |
1660 var defaultOpt = schema.getAttribute('default'); | 1737 var defaultOpt = schema.getAttribute('default'); |
1661 if (attribute == null) { | 1738 if (attribute == null) { |
1662 attribute = defaultOpt; | 1739 attribute = defaultOpt; |
1663 } | 1740 } |
1693 this.decode = function(projectXML) { | 1770 this.decode = function(projectXML) { |
1694 this.errors = []; | 1771 this.errors = []; |
1695 // projectXML - DOM Parsed document | 1772 // projectXML - DOM Parsed document |
1696 this.projectXML = projectXML.childNodes[0]; | 1773 this.projectXML = projectXML.childNodes[0]; |
1697 var setupNode = projectXML.getElementsByTagName('setup')[0]; | 1774 var setupNode = projectXML.getElementsByTagName('setup')[0]; |
1698 var schemaSetup = this.schema.getElementsByName('setup')[0]; | 1775 var schemaSetup = this.schema.getAllElementsByName('setup')[0]; |
1699 // First decode the attributes | 1776 // First decode the attributes |
1700 var attributes = schemaSetup.getElementsByTagName('attribute'); | 1777 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); |
1701 for (var i in attributes) | 1778 for (var i in attributes) |
1702 { | 1779 { |
1703 if (isNaN(Number(i)) == true){break;} | 1780 if (isNaN(Number(i)) == true){break;} |
1704 var attributeName = attributes[i].getAttribute('name'); | 1781 var attributeName = attributes[i].getAttribute('name'); |
1705 var projectAttr = setupNode.getAttribute(attributeName); | 1782 var projectAttr = setupNode.getAttribute(attributeName); |
1741 | 1818 |
1742 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); | 1819 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); |
1743 | 1820 |
1744 // Now process the survey node options | 1821 // Now process the survey node options |
1745 var survey = setupNode.getElementsByTagName('survey'); | 1822 var survey = setupNode.getElementsByTagName('survey'); |
1746 var surveySchema = specification.schema.getElementsByName('survey')[0]; | 1823 var surveySchema = specification.schema.getAllElementsByName('survey')[0]; |
1747 for (var i in survey) { | 1824 for (var i in survey) { |
1748 if (isNaN(Number(i)) == true){break;} | 1825 if (isNaN(Number(i)) == true){break;} |
1749 var location = survey[i].getAttribute('location'); | 1826 var location = survey[i].getAttribute('location'); |
1750 if (location == 'pre' || location == 'before') | 1827 if (location == 'pre' || location == 'before') |
1751 { | 1828 { |
1770 } | 1847 } |
1771 this.interfaces = new this.interfaceNode(); | 1848 this.interfaces = new this.interfaceNode(); |
1772 if (interfaceNode.length != 0) | 1849 if (interfaceNode.length != 0) |
1773 { | 1850 { |
1774 interfaceNode = interfaceNode[0]; | 1851 interfaceNode = interfaceNode[0]; |
1775 this.interfaces.decode(this,interfaceNode,this.schema.getElementsByName('interface')[1]); | 1852 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); |
1776 } | 1853 } |
1777 | 1854 |
1778 // Page tags | 1855 // Page tags |
1779 var pageTags = projectXML.getElementsByTagName('page'); | 1856 var pageTags = projectXML.getElementsByTagName('page'); |
1780 var pageSchema = this.schema.getElementsByName('page')[0]; | 1857 var pageSchema = this.schema.getAllElementsByName('page')[0]; |
1781 for (var i=0; i<pageTags.length; i++) | 1858 for (var i=0; i<pageTags.length; i++) |
1782 { | 1859 { |
1783 var node = new this.page(); | 1860 var node = new this.page(); |
1784 node.decode(this,pageTags[i],pageSchema); | 1861 node.decode(this,pageTags[i],pageSchema); |
1785 this.pages.push(node); | 1862 this.pages.push(node); |
1813 this.step = undefined; | 1890 this.step = undefined; |
1814 | 1891 |
1815 this.decode = function(parent,child,schema) | 1892 this.decode = function(parent,child,schema) |
1816 { | 1893 { |
1817 this.schema = schema; | 1894 this.schema = schema; |
1818 var attributeMap = schema.getElementsByTagName('attribute'); | 1895 var attributeMap = schema.getAllElementsByTagName('xs:attribute'); |
1819 for (var i in attributeMap){ | 1896 for (var i in attributeMap){ |
1820 if(isNaN(Number(i)) == true){break;} | 1897 if(isNaN(Number(i)) == true){break;} |
1821 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 1898 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
1822 var projectAttr = child.getAttribute(attributeName); | 1899 var projectAttr = child.getAttribute(attributeName); |
1823 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); | 1900 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); |
1895 this.decode = function(parent,xml,schema) { | 1972 this.decode = function(parent,xml,schema) { |
1896 this.schema = schema; | 1973 this.schema = schema; |
1897 this.location = xml.getAttribute('location'); | 1974 this.location = xml.getAttribute('location'); |
1898 if (this.location == 'before'){this.location = 'pre';} | 1975 if (this.location == 'before'){this.location = 'pre';} |
1899 else if (this.location == 'after'){this.location = 'post';} | 1976 else if (this.location == 'after'){this.location = 'post';} |
1900 var surveyentrySchema = schema.getElementsByTagName('element')[0]; | 1977 var surveyentrySchema = schema.getAllElementsByName('surveyentry')[0]; |
1901 for (var i in xml.children) | 1978 for (var i in xml.children) |
1902 { | 1979 { |
1903 if(isNaN(Number(i))==true){break;} | 1980 if(isNaN(Number(i))==true){break;} |
1904 var node = new this.OptionNode(); | 1981 var node = new this.OptionNode(); |
1905 node.decode(parent,xml.children[i],surveyentrySchema); | 1982 node.decode(parent,xml.children[i],surveyentrySchema); |
1933 { | 2010 { |
1934 this.title = titleNode[0].textContent; | 2011 this.title = titleNode[0].textContent; |
1935 } | 2012 } |
1936 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption'); | 2013 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption'); |
1937 // Extract interfaceoption node schema | 2014 // Extract interfaceoption node schema |
1938 var interfaceOptionNodeSchema = schema.getElementsByTagName('element'); | 2015 var interfaceOptionNodeSchema = schema.getAllElementsByName('interfaceoption')[0]; |
1939 for (var i=0; i<interfaceOptionNodeSchema.length; i++) { | 2016 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute'); |
1940 if (interfaceOptionNodeSchema[i].getAttribute('name') == 'interfaceoption') { | |
1941 interfaceOptionNodeSchema = interfaceOptionNodeSchema[i]; | |
1942 break; | |
1943 } | |
1944 } | |
1945 var attributeMap = interfaceOptionNodeSchema.getElementsByTagName('attribute'); | |
1946 for (var i=0; i<interfaceOptionNodes.length; i++) | 2017 for (var i=0; i<interfaceOptionNodes.length; i++) |
1947 { | 2018 { |
1948 var ioNode = interfaceOptionNodes[i]; | 2019 var ioNode = interfaceOptionNodes[i]; |
1949 var option = {}; | 2020 var option = {}; |
1950 for (var j=0; j<attributeMap.length; j++) | 2021 for (var j=0; j<attributeMap.length; j++) |
2003 this.schema = null; | 2074 this.schema = null; |
2004 | 2075 |
2005 this.decode = function(parent,xml,schema) | 2076 this.decode = function(parent,xml,schema) |
2006 { | 2077 { |
2007 this.schema = schema; | 2078 this.schema = schema; |
2008 var attributeMap = this.schema.getElementsByTagName('attribute'); | 2079 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
2009 for (var i=0; i<attributeMap.length; i++) | 2080 for (var i=0; i<attributeMap.length; i++) |
2010 { | 2081 { |
2011 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 2082 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
2012 var projectAttr = xml.getAttribute(attributeName); | 2083 var projectAttr = xml.getAttribute(attributeName); |
2013 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); | 2084 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); |
2032 // Now decode the interfaces | 2103 // Now decode the interfaces |
2033 var interfaceNode = xml.getElementsByTagName('interface'); | 2104 var interfaceNode = xml.getElementsByTagName('interface'); |
2034 for (var i=0; i<interfaceNode.length; i++) | 2105 for (var i=0; i<interfaceNode.length; i++) |
2035 { | 2106 { |
2036 var node = new parent.interfaceNode(); | 2107 var node = new parent.interfaceNode(); |
2037 node.decode(this,interfaceNode[i],parent.schema.getElementsByName('interface')[1]); | 2108 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]); |
2038 this.interfaces.push(node); | 2109 this.interfaces.push(node); |
2039 } | 2110 } |
2040 | 2111 |
2041 // Now process the survey node options | 2112 // Now process the survey node options |
2042 var survey = xml.getElementsByTagName('survey'); | 2113 var survey = xml.getElementsByTagName('survey'); |
2043 var surveySchema = parent.schema.getElementsByName('survey')[0]; | 2114 var surveySchema = parent.schema.getAllElementsByName('survey')[0]; |
2044 for (var i in survey) { | 2115 for (var i in survey) { |
2045 if (isNaN(Number(i)) == true){break;} | 2116 if (isNaN(Number(i)) == true){break;} |
2046 var location = survey[i].getAttribute('location'); | 2117 var location = survey[i].getAttribute('location'); |
2047 if (location == 'pre' || location == 'before') | 2118 if (location == 'pre' || location == 'before') |
2048 { | 2119 { |
2060 } | 2131 } |
2061 } | 2132 } |
2062 | 2133 |
2063 // Now process the audioelement tags | 2134 // Now process the audioelement tags |
2064 var audioElements = xml.getElementsByTagName('audioelement'); | 2135 var audioElements = xml.getElementsByTagName('audioelement'); |
2065 var audioElementSchema = parent.schema.getElementsByName('audioelement')[0]; | 2136 var audioElementSchema = parent.schema.getAllElementsByName('audioelement')[0]; |
2066 for (var i=0; i<audioElements.length; i++) | 2137 for (var i=0; i<audioElements.length; i++) |
2067 { | 2138 { |
2068 var node = new this.audioElementNode(); | 2139 var node = new this.audioElementNode(); |
2069 node.decode(this,audioElements[i],audioElementSchema); | 2140 node.decode(this,audioElements[i],audioElementSchema); |
2070 this.audioElements.push(node); | 2141 this.audioElements.push(node); |
2071 } | 2142 } |
2072 | 2143 |
2073 // Now decode the commentquestions | 2144 // Now decode the commentquestions |
2074 var commentQuestions = xml.getElementsByTagName('commentquestion'); | 2145 var commentQuestions = xml.getElementsByTagName('commentquestion'); |
2075 var commentQuestionSchema = parent.schema.getElementsByName('commentquestion')[0]; | 2146 var commentQuestionSchema = parent.schema.getAllElementsByName('commentquestion')[0]; |
2076 for (var i=0; i<commentQuestions.length; i++) | 2147 for (var i=0; i<commentQuestions.length; i++) |
2077 { | 2148 { |
2078 var node = new this.commentQuestionNode(); | 2149 var node = new this.commentQuestionNode(); |
2079 node.decode(parent,commentQuestions[i],commentQuestionSchema); | 2150 node.decode(parent,commentQuestions[i],commentQuestionSchema); |
2080 this.commentQuestions.push(node); | 2151 this.commentQuestions.push(node); |
2166 this.parent = null; | 2237 this.parent = null; |
2167 this.decode = function(parent,xml,schema) | 2238 this.decode = function(parent,xml,schema) |
2168 { | 2239 { |
2169 this.schema = schema; | 2240 this.schema = schema; |
2170 this.parent = parent; | 2241 this.parent = parent; |
2171 var attributeMap = this.schema.getElementsByTagName('attribute'); | 2242 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); |
2172 for (var i=0; i<attributeMap.length; i++) | 2243 for (var i=0; i<attributeMap.length; i++) |
2173 { | 2244 { |
2174 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); | 2245 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); |
2175 var projectAttr = xml.getAttribute(attributeName); | 2246 var projectAttr = xml.getAttribute(attributeName); |
2176 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]); | 2247 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]); |