diff core.js @ 1182:b7bf91ac6d01

Bug #1562: Checkbox and radios will be center aligned, left justified. Also solves issue #1571. Only tested in OSX Chrome!
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 12 Feb 2016 09:02:41 +0000
parents 3303a667548a
children eef2d4ea18fb
line wrap: on
line diff
--- a/core.js	Fri Feb 12 08:42:15 2016 +0000
+++ b/core.js	Fri Feb 12 09:02:41 2016 +0000
@@ -515,11 +515,14 @@
             }
 			this.popupResponse.appendChild(textArea);
 			textArea.focus();
+            this.popupResponse.style.textAlign="center";
+            this.popupResponse.style.left="0%";
 		} else if (node.specification.type == 'checkbox') {
             if (node.response == undefined) {
                 node.response = Array(node.specification.options.length);
             }
             var index = 0;
+            var max_w = 0;
 			for (var option of node.specification.options) {
 				var input = document.createElement('input');
 				input.id = option.name;
@@ -537,13 +540,21 @@
                         input.checked = "true";
                     }
                 }
+                var w = $(span).width();
+                if (w > max_w)
+                    max_w = w;
                 index++;
 			}
+            max_w += 12;
+            this.popupResponse.style.textAlign="";
+            var leftP = ((max_w/500)/2)*100;
+            this.popupResponse.style.left=leftP+"%";
 		} else if (node.specification.type == 'radio') {
             if (node.response == undefined) {
                 node.response = {name: "", text: ""};
             }
             var index = 0;
+            var max_w = 0;
 			for (var option of node.specification.options) {
 				var input = document.createElement('input');
 				input.id = option.name;
@@ -560,7 +571,14 @@
                 if (input.id == node.response.name) {
                     input.checked = "true";
                 }
+                var w = $(span).width();
+                if (w > max_w)
+                    max_w = w;
 			}
+            max_w += 12;
+            this.popupResponse.style.textAlign="";
+            var leftP = ((max_w/500)/2)*100;
+            this.popupResponse.style.left=leftP+"%";
 		} else if (node.specification.type == 'number') {
 			var input = document.createElement('input');
 			input.type = 'textarea';
@@ -571,6 +589,8 @@
                 input.value = node.response;
             }
 			this.popupResponse.appendChild(input);
+            this.popupResponse.style.textAlign="center";
+            this.popupResponse.style.left="0%";
 		}
 		if(this.currentIndex+1 == this.popupOptions.length) {
 			if (this.node.location == "pre") {