From 384357849eebdfd87395b2b1693f6e17d75f6ec6 Mon Sep 17 00:00:00 2001 From: antoniomm Date: Thu, 27 Sep 2018 12:34:58 +0200 Subject: [PATCH 1/2] feature/#19-add-table-head-support: adding thead to the table --- src/js/table.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/js/table.js b/src/js/table.js index 4441028..15f27fe 100644 --- a/src/js/table.js +++ b/src/js/table.js @@ -12,11 +12,14 @@ Table.prototype = { }, insert: function (rows, cols) { - var html = this._html(rows, cols); + var htmlHeader, html; + htmlHeader = this._html(0, cols, "header"); + html = this._html(rows, cols); this._editor.pasteHTML( '' + + '' + htmlHeader + '' + '' + html + '' + @@ -39,10 +42,10 @@ Table.prototype = { this._editor.checkSelection(); }, - _html: function (rows, cols) { + _html: function (rows, cols, defaultText) { var html = '', x, y, - text = getSelectionText(this._doc); + text = (defaultText)? defaultText: getSelectionText(this._doc); for (x = 0; x <= rows; x++) { html += ''; @@ -71,17 +74,22 @@ Table.prototype = { e.preventDefault(); e.stopPropagation(); table = this._getTableElements(el); + var tbody = this._getTBody(getParentOf(el, 'table')); if (e.shiftKey) { this._tabBackwards(el.previousSibling, table.row); } else { if (this._isLastCell(el, table.row, table.root)) { - this._insertRow(getParentOf(el, 'tbody'), table.row.cells.length); + this._insertRow(tbody, table.row.cells.length); } placeCaretAtNode(this._doc, el); } } }, + _getTBody: function (table) { + return table.querySelector('tbody'); + }, + _getTableElements: function (el) { return { cell: getParentOf(el, 'td'), @@ -109,8 +117,8 @@ Table.prototype = { _isLastCell: function (el, row, table) { return ( - (row.cells.length - 1) === el.cellIndex && - (table.rows.length - 1) === row.rowIndex + (row.cells.length - 1) === el.cellIndex && + (table.rows.length - 1) === row.rowIndex ); }, From c69f2e3a357134b2fae3973cda62796f40fb505d Mon Sep 17 00:00:00 2001 From: antoniomm Date: Thu, 27 Sep 2018 12:40:25 +0200 Subject: [PATCH 2/2] feature/#19-add-table-head-support: adding thead to the table, resolved style problems --- src/js/table.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/table.js b/src/js/table.js index 15f27fe..9f8f7d0 100644 --- a/src/js/table.js +++ b/src/js/table.js @@ -13,7 +13,7 @@ Table.prototype = { insert: function (rows, cols) { var htmlHeader, html; - htmlHeader = this._html(0, cols, "header"); + htmlHeader = this._html(0, cols, 'header'); html = this._html(rows, cols); this._editor.pasteHTML( @@ -45,7 +45,7 @@ Table.prototype = { _html: function (rows, cols, defaultText) { var html = '', x, y, - text = (defaultText)? defaultText: getSelectionText(this._doc); + text = (defaultText) ? defaultText : getSelectionText(this._doc); for (x = 0; x <= rows; x++) { html += '';