function table(height, width, cellCss, tableCss) {
  var contents = null, row, col;
  if ($.isArray(height)) {
    tableCss = cellCss;
    cellCss = width;
    contents = height;
    height = contents.length;
    width = 0;
    for (row = 0; row < height; row++) {
      if ($.isArray(contents[row])) {
        width = Math.max(width, contents[row].length);
      } else {
        width = Math.max(width, 1);
      }
    }
  }
  var html = ['<table>'];
  for (row = 0; row < height; row++) {
    html.push('<tr>');
    for (col = 0; col < width; col++) {
      if (contents) {
        if ($.isArray(contents[row]) && col < contents[row].length) {
          html.push('<td>' + escapeHtml(contents[row][col]) + '</td>');
        } else if (!$.isArray(contents[row]) && col == 0) {
          html.push('<td>' + escapeHtml(contents[row]) + '</td>');
        } else {
          html.push('<td></td>');
        }
      } else {
        html.push('<td></td>');
      }
    }
    html.push('</tr>');
  }
  html.push('</table>');
  var result = $(html.join(''));
  var defaultCss = {
    borderCollapse: 'collapse',
    width: '35px',
    height: '35px',
    border: '1px solid black',
    tableLayout: 'fixed',
    textAlign: 'center',
    margin: '0',
    padding: '0'
  };
  result.css($.extend({}, defaultCss,
    { width: 'auto', height: 'auto', maxWidth: 'auto', border: 'none'},
    tableCss));
  result.find('td').css($.extend({}, defaultCss, cellCss));
  result.appendTo('body');
  return result;
}
// Simplify creation of tables with cells.
Simplify creation of tables with cells.
Simplify creation of tables with cells .
function table(height, width, cellCss, tableCss) {
  var contents = null, row, col;
  if ($.isArray(height)) {
    tableCss = cellCss;
    cellCss = width;
    contents = height;
    height = contents.length;
    width = 0;
    for (row = 0; row < height; row++) {
      if ($.isArray(contents[row])) {
        width = Math.max(width, contents[row].length);
      } else {
        width = Math.max(width, 1);
      }
    }
  }
  var html = ['<table>'];
  for (row = 0; row < height; row++) {
    html.push('<tr>');
    for (col = 0; col < width; col++) {
      if (contents) {
        if ($.isArray(contents[row]) && col < contents[row].length) {
          html.push('<td>' + escapeHtml(contents[row][col]) + '</td>');
        } else if (!$.isArray(contents[row]) && col == 0) {
          html.push('<td>' + escapeHtml(contents[row]) + '</td>');
        } else {
          html.push('<td></td>');
        }
      } else {
        html.push('<td></td>');
      }
    }
    html.push('</tr>');
  }
  html.push('</table>');
  var result = $(html.join(''));
  var defaultCss = {
    borderCollapse: 'collapse',
    width: '35px',
    height: '35px',
    border: '1px solid black',
    tableLayout: 'fixed',
    textAlign: 'center',
    margin: '0',
    padding: '0'
  };
  result.css($.extend({}, defaultCss,
    { width: 'auto', height: 'auto', maxWidth: 'auto', border: 'none'},
    tableCss));
  result.find('td').css($.extend({}, defaultCss, cellCss));
  result.appendTo('body');
  return result;
}
function table ( height , width , cellCss , tableCss ) { var contents = null , row , col ; if ( $ . isArray ( height ) ) { tableCss = cellCss ; cellCss = width ; contents = height ; height = contents . length ; width = 0 ; for ( row = 0 ; row < height ; row ++ ) { if ( $ . isArray ( contents [ row ] ) ) { width = Math . max ( width , contents [ row ] . length ) ; } else { width = Math . max ( width , 1 ) ; } } } var html = [ '<table>' ] ; for ( row = 0 ; row < height ; row ++ ) { html . push ( '<tr>' ) ; for ( col = 0 ; col < width ; col ++ ) { if ( contents ) { if ( $ . isArray ( contents [ row ] ) && col < contents [ row ] . length ) { html . push ( '<td>' + escapeHtml ( contents [ row ] [ col ] ) + '</td>' ) ; } else if ( ! $ . isArray ( contents [ row ] ) && col == 0 ) { html . push ( '<td>' + escapeHtml ( contents [ row ] ) + '</td>' ) ; } else { html . push ( '<td></td>' ) ; } } else { html . push ( '<td></td>' ) ; } } html . push ( '</tr>' ) ; } html . push ( '</table>' ) ; var result = $ ( html . join ( '' ) ) ; var defaultCss = { borderCollapse : 'collapse' , width : '35px' , height : '35px' , border : '1px solid black' , tableLayout : 'fixed' , textAlign : 'center' , margin : '0' , padding : '0' } ; result . css ( $ . extend ( { } , defaultCss , { width : 'auto' , height : 'auto' , maxWidth : 'auto' , border : 'none' } , tableCss ) ) ; result . find ( 'td' ) . css ( $ . extend ( { } , defaultCss , cellCss ) ) ; result . appendTo ( 'body' ) ; return result ; }
Simplify creation of tables with cells.
Simplify creation of tables with cells .