web.bower_components.summernote.src.js.editing.Table.js Maven / Gradle / Ivy
define([
'summernote/core/dom', 'summernote/core/range', 'summernote/core/list'
], function (dom, range, list) {
/**
* Table
* @class
*/
var Table = function () {
/**
* handle tab key
*
* @param {WrappedRange} rng
* @param {Boolean} isShift
*/
this.tab = function (rng, isShift) {
var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
var table = dom.ancestor(cell, dom.isTable);
var cells = dom.listDescendant(table, dom.isCell);
var nextCell = list[isShift ? 'prev' : 'next'](cells, cell);
if (nextCell) {
range.create(nextCell, 0).select();
}
};
/**
* create empty table element
*
* @param {Number} rowCount
* @param {Number} colCount
* @return {Node}
*/
this.createTable = function (colCount, rowCount) {
var tds = [], tdHTML;
for (var idxCol = 0; idxCol < colCount; idxCol++) {
tds.push('' + dom.blank + ' ');
}
tdHTML = tds.join('');
var trs = [], trHTML;
for (var idxRow = 0; idxRow < rowCount; idxRow++) {
trs.push('' + tdHTML + ' ');
}
trHTML = trs.join('');
return $('' + trHTML + '
')[0];
};
};
return Table;
});