diff 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
line wrap: on
line diff
--- a/js/core.js	Mon Apr 25 15:54:25 2016 +0100
+++ b/js/core.js	Wed Apr 27 09:38:45 2016 +0100
@@ -241,8 +241,8 @@
     } else if (responseDocument.firstChild.nodeName == "waetresult") {
         // document is a result
         projectXML = document.implementation.createDocument(null,"waet");
-        projectXML.children[0].appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true));
-        var child = responseDocument.children[0].children[0];
+        projectXML.firstChild.appendChild(responseDocument.getElementsByTagName('waet')[0].getElementsByTagName("setup")[0].cloneNode(true));
+        var child = responseDocument.firstChild.firstChild;
         while (child != null) {
             if (child.nodeName == "survey") {
                 // One of the global survey elements
@@ -268,15 +268,15 @@
                     // We need to complete this, so it must be regenerated by store
                     var copy = child;
                     child = child.previousElementSibling;
-                    responseDocument.children[0].removeChild(copy);
+                    responseDocument.firstChild.removeChild(copy);
                 }
             } else if (child.nodeName == "page") {
                 if (child.getAttribute("state") == "empty") {
                     // We need to complete this page
-                    projectXML.children[0].appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true));
+                    projectXML.firstChild.appendChild(responseDocument.getElementById(child.getAttribute("ref")).cloneNode(true));
                     var copy = child;
                     child = child.previousElementSibling;
-                    responseDocument.children[0].removeChild(copy);
+                    responseDocument.firstChild.removeChild(copy);
                 }
             }
             child = child.nextElementSibling;
@@ -2102,9 +2102,11 @@
 		this.span = document.createElement('div');
 		this.inputs.align = 'center';
 		this.inputs.style.marginLeft = '12px';
+        this.inputs.className = "comment-radio-inputs-holder";
 		this.span.style.marginLeft = '12px';
 		this.span.align = 'center';
 		this.span.style.marginTop = '15px';
+        this.span.className = "comment-radio-span-holder";
 		
 		var optCount = commentQuestion.options.length;
 		for (var optNode of commentQuestion.options)
@@ -2174,9 +2176,9 @@
 				boxwidth = 400;
 			}
 			this.holder.style.width = boxwidth+"px";
-			var text = this.holder.children[2];
-			var options = this.holder.children[3];
-			var optCount = options.children.length;
+			var text = this.holder.getElementsByClassName("comment-radio-span-holder")[0];
+			var options = this.holder.getElementsByClassName("comment-radio-inputs-holder")[0];
+			var optCount = options.childElementCount;
 			var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
 			var options = options.firstChild;
 			var text = text.firstChild;
@@ -2214,9 +2216,11 @@
 		this.span = document.createElement('div');
 		this.inputs.align = 'center';
 		this.inputs.style.marginLeft = '12px';
+        this.inputs.className = "comment-checkbox-inputs-holder";
 		this.span.style.marginLeft = '12px';
 		this.span.align = 'center';
 		this.span.style.marginTop = '15px';
+        this.span.className = "comment-checkbox-span-holder";
 		
 		var optCount = commentQuestion.options.length;
 		for (var i=0; i<optCount; i++)
@@ -2277,9 +2281,9 @@
 				boxwidth = 400;
 			}
 			this.holder.style.width = boxwidth+"px";
-			var text = this.holder.children[2];
-			var options = this.holder.children[3];
-			var optCount = options.children.length;
+			var text = this.holder.getElementsByClassName("comment-checkbox-span-holder")[0];
+			var options = this.holder.getElementsByClassName("comment-checkbox-inputs-holder")[0];
+			var optCount = options.childElementCount;
 			var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
 			var options = options.firstChild;
 			var text = text.firstChild;
@@ -2810,7 +2814,7 @@
             this.root.appendChild(interfaceContext.returnNavigator());
         } else {
             this.document = existingStore;
-            this.root = existingStore.children[0];
+            this.root = existingStore.firstChild;
             this.SessionKey.key = this.root.getAttribute("key");
         }
         if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);}
@@ -2901,7 +2905,7 @@
 			// From popup: node is the popupOption node containing both spec. and results
 			// ID is the position
 			if (node.specification.type == 'statement'){return;}
-			var surveyresult = this.XMLDOM.children[0];
+			var surveyresult = this.XMLDOM.firstChild;
             while(surveyresult != null) {
                 if (surveyresult.getAttribute("ref") == node.specification.id)
                 {