Add newline processing in report table cells.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 24 Sep 2014 22:26:41 +0300
changeset 132 8715659bcce6
parent 131 02d7eb74bfe5
child 133 69e0ef5b24f4
Add newline processing in report table cells.
2048.html
--- a/2048.html	Wed Sep 24 22:06:58 2014 +0300
+++ b/2048.html	Wed Sep 24 22:26:41 2014 +0300
@@ -301,6 +301,14 @@
     // UI widgets.
 
     ui.dom = {};
+    ui.dom.putBr = function(parentDom, text) {
+      var lines = text.split('\n');
+      parentDom.appendChild(document.createTextNode(lines[0]));
+      for (var i = 1; i < lines.length; i++) {
+        parentDom.appendChild(document.createElement('br'));
+        parentDom.appendChild(document.createTextNode(lines[i]));
+      }
+    }
     ui.dom.table = function(tbl, cols, cfg) {
       var tableDom = document.createElement('table');
       if (typeof cfg.tblClass === 'string')
@@ -310,7 +318,7 @@
       var trDom = document.createElement('tr');
       for (var i = 0; i < cols.length; i++) {
         var thDom = document.createElement('td');
-        thDom.appendChild(document.createTextNode(cols[i]));
+        ui.dom.putBr(thDom, cols[i]);
         trDom.appendChild(thDom);
       }
       tableDom.appendChild(trDom);
@@ -869,21 +877,21 @@
         }
         tbl.push(tblRow);
       }
-      var tblCols = ['maxVal', 'n', '%'];
+      var tblCols = ['max\nval', 'n', '%'];
       if (scoreChecked) {
-        tblCols.push('min score');
-        tblCols.push('mean score');
-        tblCols.push('max score');
+        tblCols.push('min\nscore');
+        tblCols.push('mean\nscore');
+        tblCols.push('max\nscore');
       }
       if (turnChecked) {
-        tblCols.push('min turn');
-        tblCols.push('mean turn');
-        tblCols.push('max turn');
+        tblCols.push('min\nturn');
+        tblCols.push('mean\nturn');
+        tblCols.push('max\nturn');
       }
       if (speedChecked) {
-        tblCols.push('min speed');
-        tblCols.push('mean speed');
-        tblCols.push('max speed');
+        tblCols.push('min\nspeed');
+        tblCols.push('mean\nspeed');
+        tblCols.push('max\nspeed');
       }
       var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) });
       reportDom.appendChild(tableDom);