只读模式
group, 分享
评论更多问题
博客标签总是存在一个
This commit is contained in:
lealife committed 2015-06-15 18:01:48 +08:00
1 parent 7e458bb433
commit 6987a38820
1453 files changed
+114558 -91533

No files matched your search

+61 -19
View File
@@ -27,12 +27,13 @@ define("tinymce/tableplugin/TableGrid", [
}
return function(editor, table) {
var grid, startPos, endPos, selectedCell, selection = editor.selection, dom = selection.dom;
var grid, gridWidth, startPos, endPos, selectedCell, selection = editor.selection, dom = selection.dom;
function buildGrid() {
var startY = 0;
grid = [];
gridWidth = 0;
each(['thead', 'tbody', 'tfoot'], function(part) {
var rows = dom.select('> ' + part + ' tr', table);
@@ -70,6 +71,8 @@ define("tinymce/tableplugin/TableGrid", [
};
}
}
gridWidth = Math.max(gridWidth, x + 1);
});
});
@@ -114,7 +117,7 @@ define("tinymce/tableplugin/TableGrid", [
each(table.rows, function(row) {
each(row.cells, function(cell) {
if (dom.hasClass(cell, 'mce-item-selected') || cell == selectedCell.elm) {
if (dom.hasClass(cell, 'mce-item-selected') || (selectedCell && cell == selectedCell.elm)) {
rows.push(row);
return false;
}
@@ -182,7 +185,7 @@ define("tinymce/tableplugin/TableGrid", [
if (formatNode) {
cell.appendChild(formatNode);
} else {
if (!Env.ie) {
if (!Env.ie || Env.ie > 10) {
cell.innerHTML = '<br data-mce-bogus="1" />';
}
}
@@ -219,11 +222,14 @@ define("tinymce/tableplugin/TableGrid", [
// Restore selection to start position if it still exists
buildGrid();
// Restore the selection to the closest table position
row = grid[Math.min(grid.length - 1, startPos.y)];
if (row) {
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
selection.collapse(true);
// If we have a valid startPos object
if (startPos) {
// Restore the selection to the closest table position
row = grid[Math.min(grid.length - 1, startPos.y)];
if (row) {
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
selection.collapse(true);
}
}
}
@@ -311,11 +317,13 @@ define("tinymce/tableplugin/TableGrid", [
});
});
// Use selection
startX = startPos.x;
startY = startPos.y;
endX = endPos.x;
endY = endPos.y;
// Use selection, but make sure startPos is valid before accessing
if (startPos) {
startX = startPos.x;
startY = startPos.y;
endX = endPos.x;
endY = endPos.y;
}
}
// Find start/end cells
@@ -343,6 +351,7 @@ define("tinymce/tableplugin/TableGrid", [
cell = grid[y][x].elm;
/*jshint loopfunc:true */
/*eslint no-loop-func:0 */
if (cell != startCell) {
// Move children to startCell
children = Tools.grep(cell.childNodes);
@@ -394,6 +403,11 @@ define("tinymce/tableplugin/TableGrid", [
}
});
// If posY is undefined there is nothing for us to do here...just return to avoid crashing below
if (posY === undefined) {
return;
}
for (x = 0; x < grid[0].length; x++) {
// Cell not found could be because of an invalid table structure
if (!grid[posY][x]) {
@@ -520,9 +534,7 @@ define("tinymce/tableplugin/TableGrid", [
var rows;
function deleteRow(tr) {
var nextTr, pos, lastCell;
nextTr = dom.getNext(tr, 'tr');
var pos, lastCell;
// Move down row spanned cells
each(tr.cells, function(cell) {
@@ -658,7 +670,7 @@ define("tinymce/tableplugin/TableGrid", [
each(grid, function(row, y) {
each(row, function(cell, x) {
if (cell.elm == target) {
pos = {x : x, y : y};
pos = {x: x, y: y};
return false;
}
});
@@ -713,7 +725,7 @@ define("tinymce/tableplugin/TableGrid", [
});
});
return {x : maxX, y : maxY};
return {x: maxX, y: maxY};
}
function setEndCell(cell) {
@@ -792,6 +804,34 @@ define("tinymce/tableplugin/TableGrid", [
}
}
function moveRelIdx(cellElm, delta) {
var pos, index, cell;
pos = getPos(cellElm);
index = pos.y * gridWidth + pos.x;
do {
index += delta;
cell = getCell(index % gridWidth, Math.floor(index / gridWidth));
if (!cell) {
break;
}
if (cell.elm != cellElm) {
selection.select(cell.elm, true);
if (dom.isEmpty(cell.elm)) {
selection.collapse(true);
}
return true;
}
} while (cell.elm == cellElm);
return false;
}
table = table || dom.getParent(selection.getStart(), 'table');
buildGrid();
@@ -816,7 +856,9 @@ define("tinymce/tableplugin/TableGrid", [
pasteRows: pasteRows,
getPos: getPos,
setStartCell: setStartCell,
setEndCell: setEndCell
setEndCell: setEndCell,
moveRelIdx: moveRelIdx,
refresh: buildGrid
});
};
});