comparison js/core.js @ 2294:5a2aaa964f6d

Further fix for #21. Removed all reference to .children in core.js
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 27 Apr 2016 09:38:45 +0100
parents 185232d01324
children b0b4d264d9a8
comparison
equal deleted inserted replaced
2293:138f002fb8f5 2294:5a2aaa964f6d
239 storage.initialise(); 239 storage.initialise();
240 240
241 } else if (responseDocument.firstChild.nodeName == "waetresult") { 241 } else if (responseDocument.firstChild.nodeName == "waetresult") {
242 // document is a result 242 // document is a result
243 projectXML = document.implementation.createDocument(null,"waet"); 243 projectXML = document.implementation.createDocument(null,"waet");
244 projectXML.children[0].appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true)); 244 projectXML.firstChild.appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true));
245 var child = responseDocument.children[0].children[0]; 245 var child = responseDocument.firstChild.firstChild;
246 while (child != null) { 246 while (child != null) {
247 if (child.nodeName == "survey") { 247 if (child.nodeName == "survey") {
248 // One of the global survey elements 248 // One of the global survey elements
249 if (child.getAttribute("state") == "complete") { 249 if (child.getAttribute("state") == "complete") {
250 // We need to remove this survey from <setup> 250 // We need to remove this survey from <setup>
266 } 266 }
267 } else { 267 } else {
268 // We need to complete this, so it must be regenerated by store 268 // We need to complete this, so it must be regenerated by store
269 var copy = child; 269 var copy = child;
270 child = child.previousElementSibling; 270 child = child.previousElementSibling;
271 responseDocument.children[0].removeChild(copy); 271 responseDocument.firstChild.removeChild(copy);
272 } 272 }
273 } else if (child.nodeName == "page") { 273 } else if (child.nodeName == "page") {
274 if (child.getAttribute("state") == "empty") { 274 if (child.getAttribute("state") == "empty") {
275 // We need to complete this page 275 // We need to complete this page
276 projectXML.children[0].appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true)); 276 projectXML.firstChild.appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true));
277 var copy = child; 277 var copy = child;
278 child = child.previousElementSibling; 278 child = child.previousElementSibling;
279 responseDocument.children[0].removeChild(copy); 279 responseDocument.firstChild.removeChild(copy);
280 } 280 }
281 } 281 }
282 child = child.nextElementSibling; 282 child = child.nextElementSibling;
283 } 283 }
284 // Build the specification 284 // Build the specification
2100 this.options = []; 2100 this.options = [];
2101 this.inputs = document.createElement('div'); 2101 this.inputs = document.createElement('div');
2102 this.span = document.createElement('div'); 2102 this.span = document.createElement('div');
2103 this.inputs.align = 'center'; 2103 this.inputs.align = 'center';
2104 this.inputs.style.marginLeft = '12px'; 2104 this.inputs.style.marginLeft = '12px';
2105 this.inputs.className = "comment-radio-inputs-holder";
2105 this.span.style.marginLeft = '12px'; 2106 this.span.style.marginLeft = '12px';
2106 this.span.align = 'center'; 2107 this.span.align = 'center';
2107 this.span.style.marginTop = '15px'; 2108 this.span.style.marginTop = '15px';
2109 this.span.className = "comment-radio-span-holder";
2108 2110
2109 var optCount = commentQuestion.options.length; 2111 var optCount = commentQuestion.options.length;
2110 for (var optNode of commentQuestion.options) 2112 for (var optNode of commentQuestion.options)
2111 { 2113 {
2112 var div = document.createElement('div'); 2114 var div = document.createElement('div');
2172 else if (boxwidth < 400) 2174 else if (boxwidth < 400)
2173 { 2175 {
2174 boxwidth = 400; 2176 boxwidth = 400;
2175 } 2177 }
2176 this.holder.style.width = boxwidth+"px"; 2178 this.holder.style.width = boxwidth+"px";
2177 var text = this.holder.children[2]; 2179 var text = this.holder.getElementsByClassName("comment-radio-span-holder")[0];
2178 var options = this.holder.children[3]; 2180 var options = this.holder.getElementsByClassName("comment-radio-inputs-holder")[0];
2179 var optCount = options.children.length; 2181 var optCount = options.childElementCount;
2180 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; 2182 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
2181 var options = options.firstChild; 2183 var options = options.firstChild;
2182 var text = text.firstChild; 2184 var text = text.firstChild;
2183 options.style.marginRight = spanMargin; 2185 options.style.marginRight = spanMargin;
2184 options.style.marginLeft = spanMargin; 2186 options.style.marginLeft = spanMargin;
2212 this.options = []; 2214 this.options = [];
2213 this.inputs = document.createElement('div'); 2215 this.inputs = document.createElement('div');
2214 this.span = document.createElement('div'); 2216 this.span = document.createElement('div');
2215 this.inputs.align = 'center'; 2217 this.inputs.align = 'center';
2216 this.inputs.style.marginLeft = '12px'; 2218 this.inputs.style.marginLeft = '12px';
2219 this.inputs.className = "comment-checkbox-inputs-holder";
2217 this.span.style.marginLeft = '12px'; 2220 this.span.style.marginLeft = '12px';
2218 this.span.align = 'center'; 2221 this.span.align = 'center';
2219 this.span.style.marginTop = '15px'; 2222 this.span.style.marginTop = '15px';
2223 this.span.className = "comment-checkbox-span-holder";
2220 2224
2221 var optCount = commentQuestion.options.length; 2225 var optCount = commentQuestion.options.length;
2222 for (var i=0; i<optCount; i++) 2226 for (var i=0; i<optCount; i++)
2223 { 2227 {
2224 var div = document.createElement('div'); 2228 var div = document.createElement('div');
2275 else if (boxwidth < 400) 2279 else if (boxwidth < 400)
2276 { 2280 {
2277 boxwidth = 400; 2281 boxwidth = 400;
2278 } 2282 }
2279 this.holder.style.width = boxwidth+"px"; 2283 this.holder.style.width = boxwidth+"px";
2280 var text = this.holder.children[2]; 2284 var text = this.holder.getElementsByClassName("comment-checkbox-span-holder")[0];
2281 var options = this.holder.children[3]; 2285 var options = this.holder.getElementsByClassName("comment-checkbox-inputs-holder")[0];
2282 var optCount = options.children.length; 2286 var optCount = options.childElementCount;
2283 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; 2287 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
2284 var options = options.firstChild; 2288 var options = options.firstChild;
2285 var text = text.firstChild; 2289 var text = text.firstChild;
2286 options.style.marginRight = spanMargin; 2290 options.style.marginRight = spanMargin;
2287 options.style.marginLeft = spanMargin; 2291 options.style.marginLeft = spanMargin;
2808 this.root.appendChild(projectDocument); 2812 this.root.appendChild(projectDocument);
2809 this.root.appendChild(interfaceContext.returnDateNode()); 2813 this.root.appendChild(interfaceContext.returnDateNode());
2810 this.root.appendChild(interfaceContext.returnNavigator()); 2814 this.root.appendChild(interfaceContext.returnNavigator());
2811 } else { 2815 } else {
2812 this.document = existingStore; 2816 this.document = existingStore;
2813 this.root = existingStore.children[0]; 2817 this.root = existingStore.firstChild;
2814 this.SessionKey.key = this.root.getAttribute("key"); 2818 this.SessionKey.key = this.root.getAttribute("key");
2815 } 2819 }
2816 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} 2820 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);}
2817 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} 2821 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);}
2818 }; 2822 };
2899 this.postResult = function(node) 2903 this.postResult = function(node)
2900 { 2904 {
2901 // From popup: node is the popupOption node containing both spec. and results 2905 // From popup: node is the popupOption node containing both spec. and results
2902 // ID is the position 2906 // ID is the position
2903 if (node.specification.type == 'statement'){return;} 2907 if (node.specification.type == 'statement'){return;}
2904 var surveyresult = this.XMLDOM.children[0]; 2908 var surveyresult = this.XMLDOM.firstChild;
2905 while(surveyresult != null) { 2909 while(surveyresult != null) {
2906 if (surveyresult.getAttribute("ref") == node.specification.id) 2910 if (surveyresult.getAttribute("ref") == node.specification.id)
2907 { 2911 {
2908 break; 2912 break;
2909 } 2913 }