Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1589:c33eef57f0b9
Added radio boxes
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Fri, 05 Jun 2015 12:42:32 +0100 |
parents | a64c6a1d869c |
children | 907abe027ebc |
comparison
equal
deleted
inserted
replaced
1588:a64c6a1d869c | 1589:c33eef57f0b9 |
---|---|
142 hold.appendChild(input); | 142 hold.appendChild(input); |
143 hold.appendChild(span); | 143 hold.appendChild(span); |
144 optHold.appendChild(hold); | 144 optHold.appendChild(hold); |
145 } | 145 } |
146 this.popupContent.appendChild(optHold); | 146 this.popupContent.appendChild(optHold); |
147 } else if (node.type == 'radio') { | |
148 var span = document.createElement('span'); | |
149 span.textContent = node.statement; | |
150 this.popupContent.appendChild(span); | |
151 var optHold = document.createElement('div'); | |
152 optHold.id = 'option-holder'; | |
153 optHold.align = 'none'; | |
154 optHold.style.float = 'left'; | |
155 optHold.style.width = "100%"; | |
156 for (var i=0; i<node.options.length; i++) { | |
157 var option = node.options[i]; | |
158 var input = document.createElement('input'); | |
159 input.id = option.name; | |
160 input.type = 'radio'; | |
161 input.name = node.id; | |
162 var span = document.createElement('span'); | |
163 span.textContent = option.text; | |
164 var hold = document.createElement('div'); | |
165 hold.setAttribute('name','option'); | |
166 hold.style.padding = '4px'; | |
167 hold.appendChild(input); | |
168 hold.appendChild(span); | |
169 optHold.appendChild(hold); | |
170 } | |
171 this.popupContent.appendChild(optHold); | |
147 } | 172 } |
148 this.popupContent.appendChild(this.popupButton); | 173 this.popupContent.appendChild(this.popupButton); |
149 }; | 174 }; |
150 | 175 |
151 this.initState = function(node) { | 176 this.initState = function(node) { |
190 } else if (node.type == 'checkbox') { | 215 } else if (node.type == 'checkbox') { |
191 // Must extract checkbox data | 216 // Must extract checkbox data |
192 var optHold = document.getElementById('option-holder'); | 217 var optHold = document.getElementById('option-holder'); |
193 var hold = document.createElement('checkbox'); | 218 var hold = document.createElement('checkbox'); |
194 console.log("Checkbox: "+ node.statement); | 219 console.log("Checkbox: "+ node.statement); |
220 hold.id = node.id; | |
195 for (var i=0; i<optHold.childElementCount; i++) { | 221 for (var i=0; i<optHold.childElementCount; i++) { |
196 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; | 222 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; |
197 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; | 223 var statement = optHold.childNodes[i].getElementsByTagName('span')[0]; |
198 var response = document.createElement('option'); | 224 var response = document.createElement('option'); |
199 response.setAttribute('id',input.id); | 225 response.setAttribute('id',input.id); |
200 response.setAttribute('checked',input.checked); | 226 response.setAttribute('checked',input.checked); |
201 hold.appendChild(response); | 227 hold.appendChild(response); |
202 console.log(input.id +': '+ input.checked); | 228 console.log(input.id +': '+ input.checked); |
203 } | 229 } |
230 this.responses.appendChild(hold); | |
231 } else if (node.type == "radio") { | |
232 var optHold = document.getElementById('option-holder'); | |
233 var hold = document.createElement('radio'); | |
234 var responseID = null; | |
235 var i=0; | |
236 while(responseID == null) { | |
237 var input = optHold.childNodes[i].getElementsByTagName('input')[0]; | |
238 if (input.checked == true) { | |
239 responseID = i; | |
240 } | |
241 i++; | |
242 } | |
243 hold.id = node.id; | |
244 hold.setAttribute('name',node.options[responseID].name); | |
245 hold.textContent = node.options[responseID].text; | |
204 this.responses.appendChild(hold); | 246 this.responses.appendChild(hold); |
205 } | 247 } |
206 this.currentIndex++; | 248 this.currentIndex++; |
207 if (this.currentIndex < this.popupOptions.length) { | 249 if (this.currentIndex < this.popupOptions.length) { |
208 this.postNode(); | 250 this.postNode(); |
1054 this.OptionNode = function(child) { | 1096 this.OptionNode = function(child) { |
1055 | 1097 |
1056 this.childOption = function(element) { | 1098 this.childOption = function(element) { |
1057 this.type = 'option'; | 1099 this.type = 'option'; |
1058 this.id = element.id; | 1100 this.id = element.id; |
1101 this.name = element.getAttribute('name'); | |
1059 this.text = element.textContent; | 1102 this.text = element.textContent; |
1060 } | 1103 } |
1061 | 1104 |
1062 this.type = child.nodeName; | 1105 this.type = child.nodeName; |
1063 if (child.nodeName == "question") { | 1106 if (child.nodeName == "question") { |
1066 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} | 1109 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} |
1067 else {this.mandatory = false;} | 1110 else {this.mandatory = false;} |
1068 this.question = child.textContent; | 1111 this.question = child.textContent; |
1069 } else if (child.nodeName == "statement") { | 1112 } else if (child.nodeName == "statement") { |
1070 this.statement = child.textContent; | 1113 this.statement = child.textContent; |
1071 } else if (child.nodeName == "checkbox") { | 1114 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") { |
1072 var element = child.firstElementChild; | 1115 var element = child.firstElementChild; |
1116 this.id = child.id; | |
1073 if (element == null) { | 1117 if (element == null) { |
1074 console.log('Malformed checkbox entry'); | 1118 console.log('Malformed' +child.nodeName+ 'entry'); |
1075 this.statement = 'Malformed checkbox entry'; | 1119 this.statement = 'Malformed' +child.nodeName+ 'entry'; |
1076 this.type = 'statement'; | 1120 this.type = 'statement'; |
1077 } else { | 1121 } else { |
1078 this.options = []; | 1122 this.options = []; |
1079 while (element != null) { | 1123 while (element != null) { |
1080 if (element.nodeName == 'statement' && this.statement == undefined){ | 1124 if (element.nodeName == 'statement' && this.statement == undefined){ |