update tinymce to 3.5b2 to fix issues with FF 11 and pasting into code blocks
This commit is contained in:
parent
810e69ef0a
commit
f55779fd83
296 changed files with 17157 additions and 10477 deletions
30
library/tinymce/jscripts/tiny_mce/plugins/table/cell.htm
vendored
Executable file → Normal file
30
library/tinymce/jscripts/tiny_mce/plugins/table/cell.htm
vendored
Executable file → Normal file
|
|
@ -5,16 +5,17 @@
|
|||
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
|
||||
<script type="text/javascript" src="../../utils/mctabs.js"></script>
|
||||
<script type="text/javascript" src="../../utils/form_utils.js"></script>
|
||||
<script type="text/javascript" src="../../utils/validate.js"></script>
|
||||
<script type="text/javascript" src="../../utils/editable_selects.js"></script>
|
||||
<script type="text/javascript" src="js/cell.js"></script>
|
||||
<link href="css/cell.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body id="tablecell" style="display: none">
|
||||
<body id="tablecell" style="display: none" role="application">
|
||||
<form onsubmit="updateAction();return false;" action="#">
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="general_tab" class="current"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
<li id="general_tab" class="current" aria-controls="general_panel"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab" aria-controls="advanced_panel"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
<fieldset>
|
||||
<legend>{#table_dlg.general_props}</legend>
|
||||
|
||||
<table border="0" cellpadding="4" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="4" cellspacing="0">
|
||||
<tr>
|
||||
<td><label for="align">{#table_dlg.align}</label></td>
|
||||
<td>
|
||||
|
|
@ -70,10 +71,10 @@
|
|||
|
||||
<tr>
|
||||
<td><label for="width">{#table_dlg.width}</label></td>
|
||||
<td><input id="width" name="width" type="text" value="" size="4" maxlength="4" onchange="changedSize();" /></td>
|
||||
<td><input id="width" name="width" type="text" value="" size="7" maxlength="7" onchange="changedSize();" class="size" /></td>
|
||||
|
||||
<td><label for="height">{#table_dlg.height}</label></td>
|
||||
<td><input id="height" name="height" type="text" value="" size="4" maxlength="4" onchange="changedSize();" /></td>
|
||||
<td><input id="height" name="height" type="text" value="" size="7" maxlength="7" onchange="changedSize();" class="size" /></td>
|
||||
</tr>
|
||||
|
||||
<tr id="styleSelectRow">
|
||||
|
|
@ -92,7 +93,7 @@
|
|||
<fieldset>
|
||||
<legend>{#table_dlg.advanced_props}</legend>
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="4">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="4">
|
||||
<tr>
|
||||
<td class="column1"><label for="id">{#table_dlg.id}</label></td>
|
||||
<td><input id="id" name="id" type="text" value="" style="width: 200px" /></td>
|
||||
|
|
@ -124,7 +125,7 @@
|
|||
<tr>
|
||||
<td class="column1"><label for="backgroundimage">{#table_dlg.bgimage}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="backgroundimage" name="backgroundimage" type="text" value="" style="width: 200px" onchange="changedBackgroundImage();" /></td>
|
||||
<td id="backgroundimagebrowsercontainer"> </td>
|
||||
|
|
@ -133,10 +134,10 @@
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="column1"><label for="bordercolor">{#table_dlg.bordercolor}</label></td>
|
||||
<tr role="group" aria-labelledby="bordercolor_label">
|
||||
<td class="column1"><label id="bordercolor_label" for="bordercolor">{#table_dlg.bordercolor}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="bordercolor" name="bordercolor" type="text" value="" size="9" onchange="updateColor('bordercolor_pick','bordercolor');changedColor();" /></td>
|
||||
<td id="bordercolor_pickcontainer"> </td>
|
||||
|
|
@ -145,10 +146,10 @@
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="column1"><label for="bgcolor">{#table_dlg.bgcolor}</label></td>
|
||||
<tr role="group" aria-labelledby="bgcolor_label">
|
||||
<td class="column1"><label id="bgcolor_label" for="bgcolor">{#table_dlg.bgcolor}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="bgcolor" name="bgcolor" type="text" value="" size="9" onchange="updateColor('bgcolor_pick','bgcolor');changedColor();" /></td>
|
||||
<td id="bgcolor_pickcontainer"> </td>
|
||||
|
|
@ -166,6 +167,7 @@
|
|||
<select id="action" name="action">
|
||||
<option value="cell">{#table_dlg.cell_cell}</option>
|
||||
<option value="row">{#table_dlg.cell_row}</option>
|
||||
<option value="col">{#table_dlg.cell_col}</option>
|
||||
<option value="all">{#table_dlg.cell_all}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
|||
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/cell.css
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/cell.css
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/row.css
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/row.css
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/table.css
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/css/table.css
vendored
Executable file → Normal file
2
library/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin.js
vendored
Executable file → Normal file
2
library/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin.js
vendored
Executable file → Normal file
File diff suppressed because one or more lines are too long
2553
library/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin_src.js
vendored
Executable file → Normal file
2553
library/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin_src.js
vendored
Executable file → Normal file
|
|
@ -1,1125 +1,1428 @@
|
|||
/**
|
||||
* editor_plugin_src.js
|
||||
*
|
||||
* Copyright 2009, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://tinymce.moxiecode.com/license
|
||||
* Contributing: http://tinymce.moxiecode.com/contributing
|
||||
*/
|
||||
|
||||
(function(tinymce) {
|
||||
var each = tinymce.each;
|
||||
|
||||
/**
|
||||
* Table Grid class.
|
||||
*/
|
||||
function TableGrid(table, dom, selection) {
|
||||
var grid, startPos, endPos, selectedCell;
|
||||
|
||||
buildGrid();
|
||||
selectedCell = dom.getParent(selection.getStart(), 'th,td');
|
||||
if (selectedCell) {
|
||||
startPos = getPos(selectedCell);
|
||||
endPos = findEndPos();
|
||||
selectedCell = getCell(startPos.x, startPos.y);
|
||||
}
|
||||
|
||||
function cloneNode(node, children) {
|
||||
node = node.cloneNode(children);
|
||||
node.removeAttribute('id');
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
function buildGrid() {
|
||||
var startY = 0;
|
||||
|
||||
grid = [];
|
||||
|
||||
each(['thead', 'tbody', 'tfoot'], function(part) {
|
||||
var rows = dom.select(part + ' tr', table);
|
||||
|
||||
each(rows, function(tr, y) {
|
||||
y += startY;
|
||||
|
||||
each(dom.select('td,th', tr), function(td, x) {
|
||||
var x2, y2, rowspan, colspan;
|
||||
|
||||
// Skip over existing cells produced by rowspan
|
||||
if (grid[y]) {
|
||||
while (grid[y][x])
|
||||
x++;
|
||||
}
|
||||
|
||||
// Get col/rowspan from cell
|
||||
rowspan = getSpanVal(td, 'rowspan');
|
||||
colspan = getSpanVal(td, 'colspan');
|
||||
|
||||
// Fill out rowspan/colspan right and down
|
||||
for (y2 = y; y2 < y + rowspan; y2++) {
|
||||
if (!grid[y2])
|
||||
grid[y2] = [];
|
||||
|
||||
for (x2 = x; x2 < x + colspan; x2++) {
|
||||
grid[y2][x2] = {
|
||||
part : part,
|
||||
real : y2 == y && x2 == x,
|
||||
elm : td,
|
||||
rowspan : rowspan,
|
||||
colspan : colspan
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
startY += rows.length;
|
||||
});
|
||||
};
|
||||
|
||||
function getCell(x, y) {
|
||||
var row;
|
||||
|
||||
row = grid[y];
|
||||
if (row)
|
||||
return row[x];
|
||||
};
|
||||
|
||||
function getSpanVal(td, name) {
|
||||
return parseInt(td.getAttribute(name) || 1);
|
||||
};
|
||||
|
||||
function isCellSelected(cell) {
|
||||
return dom.hasClass(cell.elm, 'mceSelected') || cell == selectedCell;
|
||||
};
|
||||
|
||||
function getSelectedRows() {
|
||||
var rows = [];
|
||||
|
||||
each(table.rows, function(row) {
|
||||
each(row.cells, function(cell) {
|
||||
if (dom.hasClass(cell, 'mceSelected') || cell == selectedCell.elm) {
|
||||
rows.push(row);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function deleteTable() {
|
||||
var rng = dom.createRng();
|
||||
|
||||
rng.setStartAfter(table);
|
||||
rng.setEndAfter(table);
|
||||
|
||||
selection.setRng(rng);
|
||||
|
||||
dom.remove(table);
|
||||
};
|
||||
|
||||
function cloneCell(cell) {
|
||||
var formatNode;
|
||||
|
||||
// Clone formats
|
||||
tinymce.walk(cell, function(node) {
|
||||
var curNode;
|
||||
|
||||
if (node.nodeType == 3) {
|
||||
each(dom.getParents(node.parentNode, null, cell).reverse(), function(node) {
|
||||
node = cloneNode(node, false);
|
||||
|
||||
if (!formatNode)
|
||||
formatNode = curNode = node;
|
||||
else if (curNode)
|
||||
curNode.appendChild(node);
|
||||
|
||||
curNode = node;
|
||||
});
|
||||
|
||||
// Add something to the inner node
|
||||
if (curNode)
|
||||
curNode.innerHTML = tinymce.isIE ? ' ' : '<br _mce_bogus="1" />';
|
||||
|
||||
return false;
|
||||
}
|
||||
}, 'childNodes');
|
||||
|
||||
cell = cloneNode(cell, false);
|
||||
cell.rowSpan = cell.colSpan = 1;
|
||||
|
||||
if (formatNode) {
|
||||
cell.appendChild(formatNode);
|
||||
} else {
|
||||
if (!tinymce.isIE)
|
||||
cell.innerHTML = '<br _mce_bogus="1" />';
|
||||
}
|
||||
|
||||
return cell;
|
||||
};
|
||||
|
||||
function cleanup() {
|
||||
var rng = dom.createRng();
|
||||
|
||||
// Empty rows
|
||||
each(dom.select('tr', table), function(tr) {
|
||||
if (tr.cells.length == 0)
|
||||
dom.remove(tr);
|
||||
});
|
||||
|
||||
// Empty table
|
||||
if (dom.select('tr', table).length == 0) {
|
||||
rng.setStartAfter(table);
|
||||
rng.setEndAfter(table);
|
||||
selection.setRng(rng);
|
||||
dom.remove(table);
|
||||
return;
|
||||
}
|
||||
|
||||
// Empty header/body/footer
|
||||
each(dom.select('thead,tbody,tfoot', table), function(part) {
|
||||
if (part.rows.length == 0)
|
||||
dom.remove(part);
|
||||
});
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
function fillLeftDown(x, y, rows, cols) {
|
||||
var tr, x2, r, c, cell;
|
||||
|
||||
tr = grid[y][x].elm.parentNode;
|
||||
for (r = 1; r <= rows; r++) {
|
||||
tr = dom.getNext(tr, 'tr');
|
||||
|
||||
if (tr) {
|
||||
// Loop left to find real cell
|
||||
for (x2 = x; x2 >= 0; x2--) {
|
||||
cell = grid[y + r][x2].elm;
|
||||
|
||||
if (cell.parentNode == tr) {
|
||||
// Append clones after
|
||||
for (c = 1; c <= cols; c++)
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x2 == -1) {
|
||||
// Insert nodes before first cell
|
||||
for (c = 1; c <= cols; c++)
|
||||
tr.insertBefore(cloneCell(tr.cells[0]), tr.cells[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function split() {
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
var colSpan, rowSpan, newCell, i;
|
||||
|
||||
if (isCellSelected(cell)) {
|
||||
cell = cell.elm;
|
||||
colSpan = getSpanVal(cell, 'colspan');
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (colSpan > 1 || rowSpan > 1) {
|
||||
cell.colSpan = cell.rowSpan = 1;
|
||||
|
||||
// Insert cells right
|
||||
for (i = 0; i < colSpan - 1; i++)
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
|
||||
fillLeftDown(x, y, rowSpan - 1, colSpan);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function merge(cell, cols, rows) {
|
||||
var startX, startY, endX, endY, x, y, startCell, endCell, cell, children;
|
||||
|
||||
// Use specified cell and cols/rows
|
||||
if (cell) {
|
||||
pos = getPos(cell);
|
||||
startX = pos.x;
|
||||
startY = pos.y;
|
||||
endX = startX + (cols - 1);
|
||||
endY = startY + (rows - 1);
|
||||
} else {
|
||||
// Use selection
|
||||
startX = startPos.x;
|
||||
startY = startPos.y;
|
||||
endX = endPos.x;
|
||||
endY = endPos.y;
|
||||
}
|
||||
|
||||
// Find start/end cells
|
||||
startCell = getCell(startX, startY);
|
||||
endCell = getCell(endX, endY);
|
||||
|
||||
// Check if the cells exists and if they are of the same part for example tbody = tbody
|
||||
if (startCell && endCell && startCell.part == endCell.part) {
|
||||
// Split and rebuild grid
|
||||
split();
|
||||
buildGrid();
|
||||
|
||||
// Set row/col span to start cell
|
||||
startCell = getCell(startX, startY).elm;
|
||||
startCell.colSpan = (endX - startX) + 1;
|
||||
startCell.rowSpan = (endY - startY) + 1;
|
||||
|
||||
// Remove other cells and add it's contents to the start cell
|
||||
for (y = startY; y <= endY; y++) {
|
||||
for (x = startX; x <= endX; x++) {
|
||||
cell = grid[y][x].elm;
|
||||
|
||||
if (cell != startCell) {
|
||||
// Move children to startCell
|
||||
children = tinymce.grep(cell.childNodes);
|
||||
each(children, function(node, i) {
|
||||
// Jump over last BR element
|
||||
if (node.nodeName != 'BR' || i != children.length - 1)
|
||||
startCell.appendChild(node);
|
||||
});
|
||||
|
||||
// Remove cell
|
||||
dom.remove(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty rows etc and restore caret location
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
function insertRow(before) {
|
||||
var posY, cell, lastCell, x, rowElm, newRow, newCell, otherCell;
|
||||
|
||||
// Find first/last row
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell)) {
|
||||
cell = cell.elm;
|
||||
rowElm = cell.parentNode;
|
||||
newRow = cloneNode(rowElm, false);
|
||||
posY = y;
|
||||
|
||||
if (before)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (before)
|
||||
return !posY;
|
||||
});
|
||||
|
||||
for (x = 0; x < grid[0].length; x++) {
|
||||
cell = grid[posY][x].elm;
|
||||
|
||||
if (cell != lastCell) {
|
||||
if (!before) {
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
if (rowSpan > 1) {
|
||||
cell.rowSpan = rowSpan + 1;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Check if cell above can be expanded
|
||||
if (posY > 0 && grid[posY - 1][x]) {
|
||||
otherCell = grid[posY - 1][x].elm;
|
||||
rowSpan = getSpanVal(otherCell, 'rowspan');
|
||||
if (rowSpan > 1) {
|
||||
otherCell.rowSpan = rowSpan + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert new cell into new row
|
||||
newCell = cloneCell(cell)
|
||||
newCell.colSpan = cell.colSpan;
|
||||
newRow.appendChild(newCell);
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
}
|
||||
|
||||
if (newRow.hasChildNodes()) {
|
||||
if (!before)
|
||||
dom.insertAfter(newRow, rowElm);
|
||||
else
|
||||
rowElm.parentNode.insertBefore(newRow, rowElm);
|
||||
}
|
||||
};
|
||||
|
||||
function insertCol(before) {
|
||||
var posX, lastCell;
|
||||
|
||||
// Find first/last column
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell)) {
|
||||
posX = x;
|
||||
|
||||
if (before)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (before)
|
||||
return !posX;
|
||||
});
|
||||
|
||||
each(grid, function(row, y) {
|
||||
var cell = row[posX].elm, rowSpan, colSpan;
|
||||
|
||||
if (cell != lastCell) {
|
||||
colSpan = getSpanVal(cell, 'colspan');
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (colSpan == 1) {
|
||||
if (!before) {
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
fillLeftDown(posX, y, rowSpan - 1, colSpan);
|
||||
} else {
|
||||
cell.parentNode.insertBefore(cloneCell(cell), cell);
|
||||
fillLeftDown(posX, y, rowSpan - 1, colSpan);
|
||||
}
|
||||
} else
|
||||
cell.colSpan++;
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function deleteCols() {
|
||||
var cols = [];
|
||||
|
||||
// Get selected column indexes
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell) && tinymce.inArray(cols, x) === -1) {
|
||||
each(grid, function(row) {
|
||||
var cell = row[x].elm, colSpan;
|
||||
|
||||
colSpan = getSpanVal(cell, 'colspan');
|
||||
|
||||
if (colSpan > 1)
|
||||
cell.colSpan = colSpan - 1;
|
||||
else
|
||||
dom.remove(cell);
|
||||
});
|
||||
|
||||
cols.push(x);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cleanup();
|
||||
};
|
||||
|
||||
function deleteRows() {
|
||||
var rows;
|
||||
|
||||
function deleteRow(tr) {
|
||||
var nextTr, pos, lastCell;
|
||||
|
||||
nextTr = dom.getNext(tr, 'tr');
|
||||
|
||||
// Move down row spanned cells
|
||||
each(tr.cells, function(cell) {
|
||||
var rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (rowSpan > 1) {
|
||||
cell.rowSpan = rowSpan - 1;
|
||||
pos = getPos(cell);
|
||||
fillLeftDown(pos.x, pos.y, 1, 1);
|
||||
}
|
||||
});
|
||||
|
||||
// Delete cells
|
||||
pos = getPos(tr.cells[0]);
|
||||
each(grid[pos.y], function(cell) {
|
||||
var rowSpan;
|
||||
|
||||
cell = cell.elm;
|
||||
|
||||
if (cell != lastCell) {
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (rowSpan <= 1)
|
||||
dom.remove(cell);
|
||||
else
|
||||
cell.rowSpan = rowSpan - 1;
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Get selected rows and move selection out of scope
|
||||
rows = getSelectedRows();
|
||||
|
||||
// Delete all selected rows
|
||||
each(rows.reverse(), function(tr) {
|
||||
deleteRow(tr);
|
||||
});
|
||||
|
||||
cleanup();
|
||||
};
|
||||
|
||||
function cutRows() {
|
||||
var rows = getSelectedRows();
|
||||
|
||||
dom.remove(rows);
|
||||
cleanup();
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function copyRows() {
|
||||
var rows = getSelectedRows();
|
||||
|
||||
each(rows, function(row, i) {
|
||||
rows[i] = cloneNode(row, true);
|
||||
});
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function pasteRows(rows, before) {
|
||||
var selectedRows = getSelectedRows(),
|
||||
targetRow = selectedRows[before ? 0 : selectedRows.length - 1],
|
||||
targetCellCount = targetRow.cells.length;
|
||||
|
||||
// Calc target cell count
|
||||
each(grid, function(row) {
|
||||
var match;
|
||||
|
||||
targetCellCount = 0;
|
||||
each(row, function(cell, x) {
|
||||
if (cell.real)
|
||||
targetCellCount += cell.colspan;
|
||||
|
||||
if (cell.elm.parentNode == targetRow)
|
||||
match = 1;
|
||||
});
|
||||
|
||||
if (match)
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!before)
|
||||
rows.reverse();
|
||||
|
||||
each(rows, function(row) {
|
||||
var cellCount = row.cells.length, cell;
|
||||
|
||||
// Remove col/rowspans
|
||||
for (i = 0; i < cellCount; i++) {
|
||||
cell = row.cells[i];
|
||||
cell.colSpan = cell.rowSpan = 1;
|
||||
}
|
||||
|
||||
// Needs more cells
|
||||
for (i = cellCount; i < targetCellCount; i++)
|
||||
row.appendChild(cloneCell(row.cells[cellCount - 1]));
|
||||
|
||||
// Needs less cells
|
||||
for (i = targetCellCount; i < cellCount; i++)
|
||||
dom.remove(row.cells[i]);
|
||||
|
||||
// Add before/after
|
||||
if (before)
|
||||
targetRow.parentNode.insertBefore(row, targetRow);
|
||||
else
|
||||
dom.insertAfter(row, targetRow);
|
||||
});
|
||||
};
|
||||
|
||||
function getPos(target) {
|
||||
var pos;
|
||||
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (cell.elm == target) {
|
||||
pos = {x : x, y : y};
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return !pos;
|
||||
});
|
||||
|
||||
return pos;
|
||||
};
|
||||
|
||||
function setStartCell(cell) {
|
||||
startPos = getPos(cell);
|
||||
};
|
||||
|
||||
function findEndPos() {
|
||||
var pos, maxX, maxY;
|
||||
|
||||
maxX = maxY = 0;
|
||||
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
var colSpan, rowSpan;
|
||||
|
||||
if (isCellSelected(cell)) {
|
||||
cell = grid[y][x];
|
||||
|
||||
if (x > maxX)
|
||||
maxX = x;
|
||||
|
||||
if (y > maxY)
|
||||
maxY = y;
|
||||
|
||||
if (cell.real) {
|
||||
colSpan = cell.colspan - 1;
|
||||
rowSpan = cell.rowspan - 1;
|
||||
|
||||
if (colSpan) {
|
||||
if (x + colSpan > maxX)
|
||||
maxX = x + colSpan;
|
||||
}
|
||||
|
||||
if (rowSpan) {
|
||||
if (y + rowSpan > maxY)
|
||||
maxY = y + rowSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {x : maxX, y : maxY};
|
||||
};
|
||||
|
||||
function setEndCell(cell) {
|
||||
var startX, startY, endX, endY, maxX, maxY, colSpan, rowSpan;
|
||||
|
||||
endPos = getPos(cell);
|
||||
|
||||
if (startPos && endPos) {
|
||||
// Get start/end positions
|
||||
startX = Math.min(startPos.x, endPos.x);
|
||||
startY = Math.min(startPos.y, endPos.y);
|
||||
endX = Math.max(startPos.x, endPos.x);
|
||||
endY = Math.max(startPos.y, endPos.y);
|
||||
|
||||
// Expand end positon to include spans
|
||||
maxX = endX;
|
||||
maxY = endY;
|
||||
|
||||
// Expand startX
|
||||
for (y = startY; y <= maxY; y++) {
|
||||
cell = grid[y][startX];
|
||||
|
||||
if (!cell.real) {
|
||||
if (startX - (cell.colspan - 1) < startX)
|
||||
startX -= cell.colspan - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Expand startY
|
||||
for (x = startX; x <= maxX; x++) {
|
||||
cell = grid[startY][x];
|
||||
|
||||
if (!cell.real) {
|
||||
if (startY - (cell.rowspan - 1) < startY)
|
||||
startY -= cell.rowspan - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Find max X, Y
|
||||
for (y = startY; y <= endY; y++) {
|
||||
for (x = startX; x <= endX; x++) {
|
||||
cell = grid[y][x];
|
||||
|
||||
if (cell.real) {
|
||||
colSpan = cell.colspan - 1;
|
||||
rowSpan = cell.rowspan - 1;
|
||||
|
||||
if (colSpan) {
|
||||
if (x + colSpan > maxX)
|
||||
maxX = x + colSpan;
|
||||
}
|
||||
|
||||
if (rowSpan) {
|
||||
if (y + rowSpan > maxY)
|
||||
maxY = y + rowSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove current selection
|
||||
dom.removeClass(dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
|
||||
|
||||
// Add new selection
|
||||
for (y = startY; y <= maxY; y++) {
|
||||
for (x = startX; x <= maxX; x++)
|
||||
dom.addClass(grid[y][x].elm, 'mceSelected');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Expose to public
|
||||
tinymce.extend(this, {
|
||||
deleteTable : deleteTable,
|
||||
split : split,
|
||||
merge : merge,
|
||||
insertRow : insertRow,
|
||||
insertCol : insertCol,
|
||||
deleteCols : deleteCols,
|
||||
deleteRows : deleteRows,
|
||||
cutRows : cutRows,
|
||||
copyRows : copyRows,
|
||||
pasteRows : pasteRows,
|
||||
getPos : getPos,
|
||||
setStartCell : setStartCell,
|
||||
setEndCell : setEndCell
|
||||
});
|
||||
};
|
||||
|
||||
tinymce.create('tinymce.plugins.TablePlugin', {
|
||||
init : function(ed, url) {
|
||||
var winMan, clipboardRows;
|
||||
|
||||
function createTableGrid(node) {
|
||||
var selection = ed.selection, tblElm = ed.dom.getParent(node || selection.getNode(), 'table');
|
||||
|
||||
if (tblElm)
|
||||
return new TableGrid(tblElm, ed.dom, selection);
|
||||
};
|
||||
|
||||
function cleanup() {
|
||||
// Restore selection possibilities
|
||||
ed.getBody().style.webkitUserSelect = '';
|
||||
ed.dom.removeClass(ed.dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
|
||||
};
|
||||
|
||||
// Register buttons
|
||||
each([
|
||||
['table', 'table.desc', 'mceInsertTable', true],
|
||||
['delete_table', 'table.del', 'mceTableDelete'],
|
||||
['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
|
||||
['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
|
||||
['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
|
||||
['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
|
||||
['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
|
||||
['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
|
||||
['row_props', 'table.row_desc', 'mceTableRowProps', true],
|
||||
['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
|
||||
['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
|
||||
['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
|
||||
], function(c) {
|
||||
ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
|
||||
});
|
||||
|
||||
// Select whole table is a table border is clicked
|
||||
if (!tinymce.isIE) {
|
||||
ed.onClick.add(function(ed, e) {
|
||||
e = e.target;
|
||||
|
||||
if (e.nodeName === 'TABLE')
|
||||
ed.selection.select(e);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle node change updates
|
||||
ed.onNodeChange.add(function(ed, cm, n) {
|
||||
var p;
|
||||
|
||||
n = ed.selection.getStart();
|
||||
p = ed.dom.getParent(n, 'td,th,caption');
|
||||
cm.setActive('table', n.nodeName === 'TABLE' || !!p);
|
||||
|
||||
// Disable table tools if we are in caption
|
||||
if (p && p.nodeName === 'CAPTION')
|
||||
p = 0;
|
||||
|
||||
cm.setDisabled('delete_table', !p);
|
||||
cm.setDisabled('delete_col', !p);
|
||||
cm.setDisabled('delete_table', !p);
|
||||
cm.setDisabled('delete_row', !p);
|
||||
cm.setDisabled('col_after', !p);
|
||||
cm.setDisabled('col_before', !p);
|
||||
cm.setDisabled('row_after', !p);
|
||||
cm.setDisabled('row_before', !p);
|
||||
cm.setDisabled('row_props', !p);
|
||||
cm.setDisabled('cell_props', !p);
|
||||
cm.setDisabled('split_cells', !p);
|
||||
cm.setDisabled('merge_cells', !p);
|
||||
});
|
||||
|
||||
ed.onInit.add(function(ed) {
|
||||
var startTable, startCell, dom = ed.dom, tableGrid;
|
||||
|
||||
winMan = ed.windowManager;
|
||||
|
||||
// Add cell selection logic
|
||||
ed.onMouseDown.add(function(ed, e) {
|
||||
if (e.button != 2) {
|
||||
cleanup();
|
||||
|
||||
startCell = dom.getParent(e.target, 'td,th');
|
||||
startTable = dom.getParent(startCell, 'table');
|
||||
}
|
||||
});
|
||||
|
||||
dom.bind(ed.getDoc(), 'mouseover', function(e) {
|
||||
var sel, table, target = e.target;
|
||||
|
||||
if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
|
||||
table = dom.getParent(target, 'table');
|
||||
if (table == startTable) {
|
||||
if (!tableGrid) {
|
||||
tableGrid = createTableGrid(table);
|
||||
tableGrid.setStartCell(startCell);
|
||||
|
||||
ed.getBody().style.webkitUserSelect = 'none';
|
||||
}
|
||||
|
||||
tableGrid.setEndCell(target);
|
||||
}
|
||||
|
||||
// Remove current selection
|
||||
sel = ed.selection.getSel();
|
||||
|
||||
if (sel.removeAllRanges)
|
||||
sel.removeAllRanges();
|
||||
else
|
||||
sel.empty();
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
ed.onMouseUp.add(function(ed, e) {
|
||||
var rng, sel = ed.selection, selectedCells, nativeSel = sel.getSel(), walker, node, lastNode, endNode;
|
||||
|
||||
// Move selection to startCell
|
||||
if (startCell) {
|
||||
if (tableGrid)
|
||||
ed.getBody().style.webkitUserSelect = '';
|
||||
|
||||
function setPoint(node, start) {
|
||||
var walker = new tinymce.dom.TreeWalker(node, node);
|
||||
|
||||
do {
|
||||
// Text node
|
||||
if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
|
||||
if (start)
|
||||
rng.setStart(node, 0);
|
||||
else
|
||||
rng.setEnd(node, node.nodeValue.length);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// BR element
|
||||
if (node.nodeName == 'BR') {
|
||||
if (start)
|
||||
rng.setStartBefore(node);
|
||||
else
|
||||
rng.setEndBefore(node);
|
||||
|
||||
return;
|
||||
}
|
||||
} while (node = (start ? walker.next() : walker.prev()));
|
||||
};
|
||||
|
||||
// Try to expand text selection as much as we can only Gecko supports cell selection
|
||||
selectedCells = dom.select('td.mceSelected,th.mceSelected');
|
||||
if (selectedCells.length > 0) {
|
||||
rng = dom.createRng();
|
||||
node = selectedCells[0];
|
||||
endNode = selectedCells[selectedCells.length - 1];
|
||||
|
||||
setPoint(node, 1);
|
||||
walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
|
||||
|
||||
do {
|
||||
if (node.nodeName == 'TD' || node.nodeName == 'TH') {
|
||||
if (!dom.hasClass(node, 'mceSelected'))
|
||||
break;
|
||||
|
||||
lastNode = node;
|
||||
}
|
||||
} while (node = walker.next());
|
||||
|
||||
setPoint(lastNode);
|
||||
|
||||
sel.setRng(rng);
|
||||
}
|
||||
|
||||
ed.nodeChanged();
|
||||
startCell = tableGrid = startTable = null;
|
||||
}
|
||||
});
|
||||
|
||||
ed.onKeyUp.add(function(ed, e) {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
// Add context menu
|
||||
if (ed && ed.plugins.contextmenu) {
|
||||
ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
|
||||
var sm, se = ed.selection, el = se.getNode() || ed.getBody();
|
||||
|
||||
if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th') || ed.dom.select('td.mceSelected,th.mceSelected').length) {
|
||||
m.removeAll();
|
||||
|
||||
if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
|
||||
m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
|
||||
m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
|
||||
m.addSeparator();
|
||||
}
|
||||
|
||||
if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
|
||||
m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
|
||||
m.addSeparator();
|
||||
}
|
||||
|
||||
m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', value : {action : 'insert'}});
|
||||
m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable'});
|
||||
m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete'});
|
||||
m.addSeparator();
|
||||
|
||||
// Cell menu
|
||||
sm = m.addMenu({title : 'table.cell'});
|
||||
sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps'});
|
||||
sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells'});
|
||||
sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells'});
|
||||
|
||||
// Row menu
|
||||
sm = m.addMenu({title : 'table.row'});
|
||||
sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps'});
|
||||
sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
|
||||
sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
|
||||
sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
|
||||
sm.addSeparator();
|
||||
sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
|
||||
sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
|
||||
sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}).setDisabled(!clipboardRows);
|
||||
sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}).setDisabled(!clipboardRows);
|
||||
|
||||
// Column menu
|
||||
sm = m.addMenu({title : 'table.col'});
|
||||
sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
|
||||
sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
|
||||
sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
|
||||
} else
|
||||
m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable'});
|
||||
});
|
||||
}
|
||||
|
||||
// Fixes an issue on Gecko where it's impossible to place the caret behind a table
|
||||
// This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
|
||||
if (!tinymce.isIE) {
|
||||
function fixTableCaretPos() {
|
||||
var last;
|
||||
|
||||
// Skip empty text nodes form the end
|
||||
for (last = ed.getBody().lastChild; last && last.nodeType == 3 && !last.nodeValue.length; last = last.previousSibling) ;
|
||||
|
||||
if (last && last.nodeName == 'TABLE')
|
||||
ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
|
||||
};
|
||||
|
||||
// Fixes an bug where it's impossible to place the caret before a table in Gecko
|
||||
// this fix solves it by detecting when the caret is at the beginning of such a table
|
||||
// and then manually moves the caret infront of the table
|
||||
if (tinymce.isGecko) {
|
||||
ed.onKeyDown.add(function(ed, e) {
|
||||
var rng, table, dom = ed.dom;
|
||||
|
||||
// On gecko it's not possible to place the caret before a table
|
||||
if (e.keyCode == 37 || e.keyCode == 38) {
|
||||
rng = ed.selection.getRng();
|
||||
table = dom.getParent(rng.startContainer, 'table');
|
||||
|
||||
if (table && ed.getBody().firstChild == table) {
|
||||
if (isAtStart(rng, table)) {
|
||||
rng = dom.createRng();
|
||||
|
||||
rng.setStartBefore(table);
|
||||
rng.setEndBefore(table);
|
||||
|
||||
ed.selection.setRng(rng);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ed.onKeyUp.add(fixTableCaretPos);
|
||||
ed.onSetContent.add(fixTableCaretPos);
|
||||
ed.onVisualAid.add(fixTableCaretPos);
|
||||
|
||||
ed.onPreProcess.add(function(ed, o) {
|
||||
var last = o.node.lastChild;
|
||||
|
||||
if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
|
||||
ed.dom.remove(last);
|
||||
});
|
||||
|
||||
fixTableCaretPos();
|
||||
}
|
||||
});
|
||||
|
||||
// Register action commands
|
||||
each({
|
||||
mceTableSplitCells : function(grid) {
|
||||
grid.split();
|
||||
},
|
||||
|
||||
mceTableMergeCells : function(grid) {
|
||||
var rowSpan, colSpan, cell;
|
||||
|
||||
cell = ed.dom.getParent(ed.selection.getNode(), 'th,td');
|
||||
if (cell) {
|
||||
rowSpan = cell.rowSpan;
|
||||
colSpan = cell.colSpan;
|
||||
}
|
||||
|
||||
if (!ed.dom.select('td.mceSelected,th.mceSelected').length) {
|
||||
winMan.open({
|
||||
url : url + '/merge_cells.htm',
|
||||
width : 240 + parseInt(ed.getLang('table.merge_cells_delta_width', 0)),
|
||||
height : 110 + parseInt(ed.getLang('table.merge_cells_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
rows : rowSpan,
|
||||
cols : colSpan,
|
||||
onaction : function(data) {
|
||||
grid.merge(cell, data.cols, data.rows);
|
||||
},
|
||||
plugin_url : url
|
||||
});
|
||||
} else
|
||||
grid.merge();
|
||||
},
|
||||
|
||||
mceTableInsertRowBefore : function(grid) {
|
||||
grid.insertRow(true);
|
||||
},
|
||||
|
||||
mceTableInsertRowAfter : function(grid) {
|
||||
grid.insertRow();
|
||||
},
|
||||
|
||||
mceTableInsertColBefore : function(grid) {
|
||||
grid.insertCol(true);
|
||||
},
|
||||
|
||||
mceTableInsertColAfter : function(grid) {
|
||||
grid.insertCol();
|
||||
},
|
||||
|
||||
mceTableDeleteCol : function(grid) {
|
||||
grid.deleteCols();
|
||||
},
|
||||
|
||||
mceTableDeleteRow : function(grid) {
|
||||
grid.deleteRows();
|
||||
},
|
||||
|
||||
mceTableCutRow : function(grid) {
|
||||
clipboardRows = grid.cutRows();
|
||||
},
|
||||
|
||||
mceTableCopyRow : function(grid) {
|
||||
clipboardRows = grid.copyRows();
|
||||
},
|
||||
|
||||
mceTablePasteRowBefore : function(grid) {
|
||||
grid.pasteRows(clipboardRows, true);
|
||||
},
|
||||
|
||||
mceTablePasteRowAfter : function(grid) {
|
||||
grid.pasteRows(clipboardRows);
|
||||
},
|
||||
|
||||
mceTableDelete : function(grid) {
|
||||
grid.deleteTable();
|
||||
}
|
||||
}, function(func, name) {
|
||||
ed.addCommand(name, function() {
|
||||
var grid = createTableGrid();
|
||||
|
||||
if (grid) {
|
||||
func(grid);
|
||||
ed.execCommand('mceRepaint');
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Register dialog commands
|
||||
each({
|
||||
mceInsertTable : function(val) {
|
||||
winMan.open({
|
||||
url : url + '/table.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.table_delta_width', 0)),
|
||||
height : 320 + parseInt(ed.getLang('table.table_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url,
|
||||
action : val ? val.action : 0
|
||||
});
|
||||
},
|
||||
|
||||
mceTableRowProps : function() {
|
||||
winMan.open({
|
||||
url : url + '/row.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.rowprops_delta_width', 0)),
|
||||
height : 295 + parseInt(ed.getLang('table.rowprops_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url
|
||||
});
|
||||
},
|
||||
|
||||
mceTableCellProps : function() {
|
||||
winMan.open({
|
||||
url : url + '/cell.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.cellprops_delta_width', 0)),
|
||||
height : 295 + parseInt(ed.getLang('table.cellprops_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url
|
||||
});
|
||||
}
|
||||
}, function(func, name) {
|
||||
ed.addCommand(name, function(ui, val) {
|
||||
func(val);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
|
||||
})(tinymce);
|
||||
/**
|
||||
* editor_plugin_src.js
|
||||
*
|
||||
* Copyright 2009, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://tinymce.moxiecode.com/license
|
||||
* Contributing: http://tinymce.moxiecode.com/contributing
|
||||
*/
|
||||
|
||||
(function(tinymce) {
|
||||
var each = tinymce.each;
|
||||
|
||||
// Checks if the selection/caret is at the start of the specified block element
|
||||
function isAtStart(rng, par) {
|
||||
var doc = par.ownerDocument, rng2 = doc.createRange(), elm;
|
||||
|
||||
rng2.setStartBefore(par);
|
||||
rng2.setEnd(rng.endContainer, rng.endOffset);
|
||||
|
||||
elm = doc.createElement('body');
|
||||
elm.appendChild(rng2.cloneContents());
|
||||
|
||||
// Check for text characters of other elements that should be treated as content
|
||||
return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0;
|
||||
};
|
||||
|
||||
function getSpanVal(td, name) {
|
||||
return parseInt(td.getAttribute(name) || 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Table Grid class.
|
||||
*/
|
||||
function TableGrid(table, dom, selection) {
|
||||
var grid, startPos, endPos, selectedCell;
|
||||
|
||||
buildGrid();
|
||||
selectedCell = dom.getParent(selection.getStart(), 'th,td');
|
||||
if (selectedCell) {
|
||||
startPos = getPos(selectedCell);
|
||||
endPos = findEndPos();
|
||||
selectedCell = getCell(startPos.x, startPos.y);
|
||||
}
|
||||
|
||||
function cloneNode(node, children) {
|
||||
node = node.cloneNode(children);
|
||||
node.removeAttribute('id');
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
function buildGrid() {
|
||||
var startY = 0;
|
||||
|
||||
grid = [];
|
||||
|
||||
each(['thead', 'tbody', 'tfoot'], function(part) {
|
||||
var rows = dom.select('> ' + part + ' tr', table);
|
||||
|
||||
each(rows, function(tr, y) {
|
||||
y += startY;
|
||||
|
||||
each(dom.select('> td, > th', tr), function(td, x) {
|
||||
var x2, y2, rowspan, colspan;
|
||||
|
||||
// Skip over existing cells produced by rowspan
|
||||
if (grid[y]) {
|
||||
while (grid[y][x])
|
||||
x++;
|
||||
}
|
||||
|
||||
// Get col/rowspan from cell
|
||||
rowspan = getSpanVal(td, 'rowspan');
|
||||
colspan = getSpanVal(td, 'colspan');
|
||||
|
||||
// Fill out rowspan/colspan right and down
|
||||
for (y2 = y; y2 < y + rowspan; y2++) {
|
||||
if (!grid[y2])
|
||||
grid[y2] = [];
|
||||
|
||||
for (x2 = x; x2 < x + colspan; x2++) {
|
||||
grid[y2][x2] = {
|
||||
part : part,
|
||||
real : y2 == y && x2 == x,
|
||||
elm : td,
|
||||
rowspan : rowspan,
|
||||
colspan : colspan
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
startY += rows.length;
|
||||
});
|
||||
};
|
||||
|
||||
function getCell(x, y) {
|
||||
var row;
|
||||
|
||||
row = grid[y];
|
||||
if (row)
|
||||
return row[x];
|
||||
};
|
||||
|
||||
function setSpanVal(td, name, val) {
|
||||
if (td) {
|
||||
val = parseInt(val);
|
||||
|
||||
if (val === 1)
|
||||
td.removeAttribute(name, 1);
|
||||
else
|
||||
td.setAttribute(name, val, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function isCellSelected(cell) {
|
||||
return cell && (dom.hasClass(cell.elm, 'mceSelected') || cell == selectedCell);
|
||||
};
|
||||
|
||||
function getSelectedRows() {
|
||||
var rows = [];
|
||||
|
||||
each(table.rows, function(row) {
|
||||
each(row.cells, function(cell) {
|
||||
if (dom.hasClass(cell, 'mceSelected') || cell == selectedCell.elm) {
|
||||
rows.push(row);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function deleteTable() {
|
||||
var rng = dom.createRng();
|
||||
|
||||
rng.setStartAfter(table);
|
||||
rng.setEndAfter(table);
|
||||
|
||||
selection.setRng(rng);
|
||||
|
||||
dom.remove(table);
|
||||
};
|
||||
|
||||
function cloneCell(cell) {
|
||||
var formatNode;
|
||||
|
||||
// Clone formats
|
||||
tinymce.walk(cell, function(node) {
|
||||
var curNode;
|
||||
|
||||
if (node.nodeType == 3) {
|
||||
each(dom.getParents(node.parentNode, null, cell).reverse(), function(node) {
|
||||
node = cloneNode(node, false);
|
||||
|
||||
if (!formatNode)
|
||||
formatNode = curNode = node;
|
||||
else if (curNode)
|
||||
curNode.appendChild(node);
|
||||
|
||||
curNode = node;
|
||||
});
|
||||
|
||||
// Add something to the inner node
|
||||
if (curNode)
|
||||
curNode.innerHTML = tinymce.isIE ? ' ' : '<br data-mce-bogus="1" />';
|
||||
|
||||
return false;
|
||||
}
|
||||
}, 'childNodes');
|
||||
|
||||
cell = cloneNode(cell, false);
|
||||
setSpanVal(cell, 'rowSpan', 1);
|
||||
setSpanVal(cell, 'colSpan', 1);
|
||||
|
||||
if (formatNode) {
|
||||
cell.appendChild(formatNode);
|
||||
} else {
|
||||
if (!tinymce.isIE)
|
||||
cell.innerHTML = '<br data-mce-bogus="1" />';
|
||||
}
|
||||
|
||||
return cell;
|
||||
};
|
||||
|
||||
function cleanup() {
|
||||
var rng = dom.createRng();
|
||||
|
||||
// Empty rows
|
||||
each(dom.select('tr', table), function(tr) {
|
||||
if (tr.cells.length == 0)
|
||||
dom.remove(tr);
|
||||
});
|
||||
|
||||
// Empty table
|
||||
if (dom.select('tr', table).length == 0) {
|
||||
rng.setStartAfter(table);
|
||||
rng.setEndAfter(table);
|
||||
selection.setRng(rng);
|
||||
dom.remove(table);
|
||||
return;
|
||||
}
|
||||
|
||||
// Empty header/body/footer
|
||||
each(dom.select('thead,tbody,tfoot', table), function(part) {
|
||||
if (part.rows.length == 0)
|
||||
dom.remove(part);
|
||||
});
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
function fillLeftDown(x, y, rows, cols) {
|
||||
var tr, x2, r, c, cell;
|
||||
|
||||
tr = grid[y][x].elm.parentNode;
|
||||
for (r = 1; r <= rows; r++) {
|
||||
tr = dom.getNext(tr, 'tr');
|
||||
|
||||
if (tr) {
|
||||
// Loop left to find real cell
|
||||
for (x2 = x; x2 >= 0; x2--) {
|
||||
cell = grid[y + r][x2].elm;
|
||||
|
||||
if (cell.parentNode == tr) {
|
||||
// Append clones after
|
||||
for (c = 1; c <= cols; c++)
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x2 == -1) {
|
||||
// Insert nodes before first cell
|
||||
for (c = 1; c <= cols; c++)
|
||||
tr.insertBefore(cloneCell(tr.cells[0]), tr.cells[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function split() {
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
var colSpan, rowSpan, newCell, i;
|
||||
|
||||
if (isCellSelected(cell)) {
|
||||
cell = cell.elm;
|
||||
colSpan = getSpanVal(cell, 'colspan');
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (colSpan > 1 || rowSpan > 1) {
|
||||
setSpanVal(cell, 'rowSpan', 1);
|
||||
setSpanVal(cell, 'colSpan', 1);
|
||||
|
||||
// Insert cells right
|
||||
for (i = 0; i < colSpan - 1; i++)
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
|
||||
fillLeftDown(x, y, rowSpan - 1, colSpan);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function merge(cell, cols, rows) {
|
||||
var startX, startY, endX, endY, x, y, startCell, endCell, cell, children, count;
|
||||
|
||||
// Use specified cell and cols/rows
|
||||
if (cell) {
|
||||
pos = getPos(cell);
|
||||
startX = pos.x;
|
||||
startY = pos.y;
|
||||
endX = startX + (cols - 1);
|
||||
endY = startY + (rows - 1);
|
||||
} else {
|
||||
// Use selection
|
||||
startX = startPos.x;
|
||||
startY = startPos.y;
|
||||
endX = endPos.x;
|
||||
endY = endPos.y;
|
||||
}
|
||||
|
||||
// Find start/end cells
|
||||
startCell = getCell(startX, startY);
|
||||
endCell = getCell(endX, endY);
|
||||
|
||||
// Check if the cells exists and if they are of the same part for example tbody = tbody
|
||||
if (startCell && endCell && startCell.part == endCell.part) {
|
||||
// Split and rebuild grid
|
||||
split();
|
||||
buildGrid();
|
||||
|
||||
// Set row/col span to start cell
|
||||
startCell = getCell(startX, startY).elm;
|
||||
setSpanVal(startCell, 'colSpan', (endX - startX) + 1);
|
||||
setSpanVal(startCell, 'rowSpan', (endY - startY) + 1);
|
||||
|
||||
// Remove other cells and add it's contents to the start cell
|
||||
for (y = startY; y <= endY; y++) {
|
||||
for (x = startX; x <= endX; x++) {
|
||||
if (!grid[y] || !grid[y][x])
|
||||
continue;
|
||||
|
||||
cell = grid[y][x].elm;
|
||||
|
||||
if (cell != startCell) {
|
||||
// Move children to startCell
|
||||
children = tinymce.grep(cell.childNodes);
|
||||
each(children, function(node) {
|
||||
startCell.appendChild(node);
|
||||
});
|
||||
|
||||
// Remove bogus nodes if there is children in the target cell
|
||||
if (children.length) {
|
||||
children = tinymce.grep(startCell.childNodes);
|
||||
count = 0;
|
||||
each(children, function(node) {
|
||||
if (node.nodeName == 'BR' && dom.getAttrib(node, 'data-mce-bogus') && count++ < children.length - 1)
|
||||
startCell.removeChild(node);
|
||||
});
|
||||
}
|
||||
|
||||
// Remove cell
|
||||
dom.remove(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty rows etc and restore caret location
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
function insertRow(before) {
|
||||
var posY, cell, lastCell, x, rowElm, newRow, newCell, otherCell, rowSpan;
|
||||
|
||||
// Find first/last row
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell)) {
|
||||
cell = cell.elm;
|
||||
rowElm = cell.parentNode;
|
||||
newRow = cloneNode(rowElm, false);
|
||||
posY = y;
|
||||
|
||||
if (before)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (before)
|
||||
return !posY;
|
||||
});
|
||||
|
||||
for (x = 0; x < grid[0].length; x++) {
|
||||
// Cell not found could be because of an invalid table structure
|
||||
if (!grid[posY][x])
|
||||
continue;
|
||||
|
||||
cell = grid[posY][x].elm;
|
||||
|
||||
if (cell != lastCell) {
|
||||
if (!before) {
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
if (rowSpan > 1) {
|
||||
setSpanVal(cell, 'rowSpan', rowSpan + 1);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Check if cell above can be expanded
|
||||
if (posY > 0 && grid[posY - 1][x]) {
|
||||
otherCell = grid[posY - 1][x].elm;
|
||||
rowSpan = getSpanVal(otherCell, 'rowSpan');
|
||||
if (rowSpan > 1) {
|
||||
setSpanVal(otherCell, 'rowSpan', rowSpan + 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert new cell into new row
|
||||
newCell = cloneCell(cell);
|
||||
setSpanVal(newCell, 'colSpan', cell.colSpan);
|
||||
|
||||
newRow.appendChild(newCell);
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
}
|
||||
|
||||
if (newRow.hasChildNodes()) {
|
||||
if (!before)
|
||||
dom.insertAfter(newRow, rowElm);
|
||||
else
|
||||
rowElm.parentNode.insertBefore(newRow, rowElm);
|
||||
}
|
||||
};
|
||||
|
||||
function insertCol(before) {
|
||||
var posX, lastCell;
|
||||
|
||||
// Find first/last column
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell)) {
|
||||
posX = x;
|
||||
|
||||
if (before)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (before)
|
||||
return !posX;
|
||||
});
|
||||
|
||||
each(grid, function(row, y) {
|
||||
var cell, rowSpan, colSpan;
|
||||
|
||||
if (!row[posX])
|
||||
return;
|
||||
|
||||
cell = row[posX].elm;
|
||||
if (cell != lastCell) {
|
||||
colSpan = getSpanVal(cell, 'colspan');
|
||||
rowSpan = getSpanVal(cell, 'rowspan');
|
||||
|
||||
if (colSpan == 1) {
|
||||
if (!before) {
|
||||
dom.insertAfter(cloneCell(cell), cell);
|
||||
fillLeftDown(posX, y, rowSpan - 1, colSpan);
|
||||
} else {
|
||||
cell.parentNode.insertBefore(cloneCell(cell), cell);
|
||||
fillLeftDown(posX, y, rowSpan - 1, colSpan);
|
||||
}
|
||||
} else
|
||||
setSpanVal(cell, 'colSpan', cell.colSpan + 1);
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function deleteCols() {
|
||||
var cols = [];
|
||||
|
||||
// Get selected column indexes
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (isCellSelected(cell) && tinymce.inArray(cols, x) === -1) {
|
||||
each(grid, function(row) {
|
||||
var cell = row[x].elm, colSpan;
|
||||
|
||||
colSpan = getSpanVal(cell, 'colSpan');
|
||||
|
||||
if (colSpan > 1)
|
||||
setSpanVal(cell, 'colSpan', colSpan - 1);
|
||||
else
|
||||
dom.remove(cell);
|
||||
});
|
||||
|
||||
cols.push(x);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cleanup();
|
||||
};
|
||||
|
||||
function deleteRows() {
|
||||
var rows;
|
||||
|
||||
function deleteRow(tr) {
|
||||
var nextTr, pos, lastCell;
|
||||
|
||||
nextTr = dom.getNext(tr, 'tr');
|
||||
|
||||
// Move down row spanned cells
|
||||
each(tr.cells, function(cell) {
|
||||
var rowSpan = getSpanVal(cell, 'rowSpan');
|
||||
|
||||
if (rowSpan > 1) {
|
||||
setSpanVal(cell, 'rowSpan', rowSpan - 1);
|
||||
pos = getPos(cell);
|
||||
fillLeftDown(pos.x, pos.y, 1, 1);
|
||||
}
|
||||
});
|
||||
|
||||
// Delete cells
|
||||
pos = getPos(tr.cells[0]);
|
||||
each(grid[pos.y], function(cell) {
|
||||
var rowSpan;
|
||||
|
||||
cell = cell.elm;
|
||||
|
||||
if (cell != lastCell) {
|
||||
rowSpan = getSpanVal(cell, 'rowSpan');
|
||||
|
||||
if (rowSpan <= 1)
|
||||
dom.remove(cell);
|
||||
else
|
||||
setSpanVal(cell, 'rowSpan', rowSpan - 1);
|
||||
|
||||
lastCell = cell;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Get selected rows and move selection out of scope
|
||||
rows = getSelectedRows();
|
||||
|
||||
// Delete all selected rows
|
||||
each(rows.reverse(), function(tr) {
|
||||
deleteRow(tr);
|
||||
});
|
||||
|
||||
cleanup();
|
||||
};
|
||||
|
||||
function cutRows() {
|
||||
var rows = getSelectedRows();
|
||||
|
||||
dom.remove(rows);
|
||||
cleanup();
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function copyRows() {
|
||||
var rows = getSelectedRows();
|
||||
|
||||
each(rows, function(row, i) {
|
||||
rows[i] = cloneNode(row, true);
|
||||
});
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
function pasteRows(rows, before) {
|
||||
var selectedRows = getSelectedRows(),
|
||||
targetRow = selectedRows[before ? 0 : selectedRows.length - 1],
|
||||
targetCellCount = targetRow.cells.length;
|
||||
|
||||
// Calc target cell count
|
||||
each(grid, function(row) {
|
||||
var match;
|
||||
|
||||
targetCellCount = 0;
|
||||
each(row, function(cell, x) {
|
||||
if (cell.real)
|
||||
targetCellCount += cell.colspan;
|
||||
|
||||
if (cell.elm.parentNode == targetRow)
|
||||
match = 1;
|
||||
});
|
||||
|
||||
if (match)
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!before)
|
||||
rows.reverse();
|
||||
|
||||
each(rows, function(row) {
|
||||
var cellCount = row.cells.length, cell;
|
||||
|
||||
// Remove col/rowspans
|
||||
for (i = 0; i < cellCount; i++) {
|
||||
cell = row.cells[i];
|
||||
setSpanVal(cell, 'colSpan', 1);
|
||||
setSpanVal(cell, 'rowSpan', 1);
|
||||
}
|
||||
|
||||
// Needs more cells
|
||||
for (i = cellCount; i < targetCellCount; i++)
|
||||
row.appendChild(cloneCell(row.cells[cellCount - 1]));
|
||||
|
||||
// Needs less cells
|
||||
for (i = targetCellCount; i < cellCount; i++)
|
||||
dom.remove(row.cells[i]);
|
||||
|
||||
// Add before/after
|
||||
if (before)
|
||||
targetRow.parentNode.insertBefore(row, targetRow);
|
||||
else
|
||||
dom.insertAfter(row, targetRow);
|
||||
});
|
||||
};
|
||||
|
||||
function getPos(target) {
|
||||
var pos;
|
||||
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (cell.elm == target) {
|
||||
pos = {x : x, y : y};
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return !pos;
|
||||
});
|
||||
|
||||
return pos;
|
||||
};
|
||||
|
||||
function setStartCell(cell) {
|
||||
startPos = getPos(cell);
|
||||
};
|
||||
|
||||
function findEndPos() {
|
||||
var pos, maxX, maxY;
|
||||
|
||||
maxX = maxY = 0;
|
||||
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
var colSpan, rowSpan;
|
||||
|
||||
if (isCellSelected(cell)) {
|
||||
cell = grid[y][x];
|
||||
|
||||
if (x > maxX)
|
||||
maxX = x;
|
||||
|
||||
if (y > maxY)
|
||||
maxY = y;
|
||||
|
||||
if (cell.real) {
|
||||
colSpan = cell.colspan - 1;
|
||||
rowSpan = cell.rowspan - 1;
|
||||
|
||||
if (colSpan) {
|
||||
if (x + colSpan > maxX)
|
||||
maxX = x + colSpan;
|
||||
}
|
||||
|
||||
if (rowSpan) {
|
||||
if (y + rowSpan > maxY)
|
||||
maxY = y + rowSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {x : maxX, y : maxY};
|
||||
};
|
||||
|
||||
function setEndCell(cell) {
|
||||
var startX, startY, endX, endY, maxX, maxY, colSpan, rowSpan;
|
||||
|
||||
endPos = getPos(cell);
|
||||
|
||||
if (startPos && endPos) {
|
||||
// Get start/end positions
|
||||
startX = Math.min(startPos.x, endPos.x);
|
||||
startY = Math.min(startPos.y, endPos.y);
|
||||
endX = Math.max(startPos.x, endPos.x);
|
||||
endY = Math.max(startPos.y, endPos.y);
|
||||
|
||||
// Expand end positon to include spans
|
||||
maxX = endX;
|
||||
maxY = endY;
|
||||
|
||||
// Expand startX
|
||||
for (y = startY; y <= maxY; y++) {
|
||||
cell = grid[y][startX];
|
||||
|
||||
if (!cell.real) {
|
||||
if (startX - (cell.colspan - 1) < startX)
|
||||
startX -= cell.colspan - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Expand startY
|
||||
for (x = startX; x <= maxX; x++) {
|
||||
cell = grid[startY][x];
|
||||
|
||||
if (!cell.real) {
|
||||
if (startY - (cell.rowspan - 1) < startY)
|
||||
startY -= cell.rowspan - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Find max X, Y
|
||||
for (y = startY; y <= endY; y++) {
|
||||
for (x = startX; x <= endX; x++) {
|
||||
cell = grid[y][x];
|
||||
|
||||
if (cell.real) {
|
||||
colSpan = cell.colspan - 1;
|
||||
rowSpan = cell.rowspan - 1;
|
||||
|
||||
if (colSpan) {
|
||||
if (x + colSpan > maxX)
|
||||
maxX = x + colSpan;
|
||||
}
|
||||
|
||||
if (rowSpan) {
|
||||
if (y + rowSpan > maxY)
|
||||
maxY = y + rowSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove current selection
|
||||
dom.removeClass(dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
|
||||
|
||||
// Add new selection
|
||||
for (y = startY; y <= maxY; y++) {
|
||||
for (x = startX; x <= maxX; x++) {
|
||||
if (grid[y][x])
|
||||
dom.addClass(grid[y][x].elm, 'mceSelected');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Expose to public
|
||||
tinymce.extend(this, {
|
||||
deleteTable : deleteTable,
|
||||
split : split,
|
||||
merge : merge,
|
||||
insertRow : insertRow,
|
||||
insertCol : insertCol,
|
||||
deleteCols : deleteCols,
|
||||
deleteRows : deleteRows,
|
||||
cutRows : cutRows,
|
||||
copyRows : copyRows,
|
||||
pasteRows : pasteRows,
|
||||
getPos : getPos,
|
||||
setStartCell : setStartCell,
|
||||
setEndCell : setEndCell
|
||||
});
|
||||
};
|
||||
|
||||
tinymce.create('tinymce.plugins.TablePlugin', {
|
||||
init : function(ed, url) {
|
||||
var winMan, clipboardRows, hasCellSelection = true; // Might be selected cells on reload
|
||||
|
||||
function createTableGrid(node) {
|
||||
var selection = ed.selection, tblElm = ed.dom.getParent(node || selection.getNode(), 'table');
|
||||
|
||||
if (tblElm)
|
||||
return new TableGrid(tblElm, ed.dom, selection);
|
||||
};
|
||||
|
||||
function cleanup() {
|
||||
// Restore selection possibilities
|
||||
ed.getBody().style.webkitUserSelect = '';
|
||||
|
||||
if (hasCellSelection) {
|
||||
ed.dom.removeClass(ed.dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
|
||||
hasCellSelection = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Register buttons
|
||||
each([
|
||||
['table', 'table.desc', 'mceInsertTable', true],
|
||||
['delete_table', 'table.del', 'mceTableDelete'],
|
||||
['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
|
||||
['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
|
||||
['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
|
||||
['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
|
||||
['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
|
||||
['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
|
||||
['row_props', 'table.row_desc', 'mceTableRowProps', true],
|
||||
['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
|
||||
['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
|
||||
['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
|
||||
], function(c) {
|
||||
ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
|
||||
});
|
||||
|
||||
// Select whole table is a table border is clicked
|
||||
if (!tinymce.isIE) {
|
||||
ed.onClick.add(function(ed, e) {
|
||||
e = e.target;
|
||||
|
||||
if (e.nodeName === 'TABLE') {
|
||||
ed.selection.select(e);
|
||||
ed.nodeChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ed.onPreProcess.add(function(ed, args) {
|
||||
var nodes, i, node, dom = ed.dom, value;
|
||||
|
||||
nodes = dom.select('table', args.node);
|
||||
i = nodes.length;
|
||||
while (i--) {
|
||||
node = nodes[i];
|
||||
dom.setAttrib(node, 'data-mce-style', '');
|
||||
|
||||
if ((value = dom.getAttrib(node, 'width'))) {
|
||||
dom.setStyle(node, 'width', value);
|
||||
dom.setAttrib(node, 'width', '');
|
||||
}
|
||||
|
||||
if ((value = dom.getAttrib(node, 'height'))) {
|
||||
dom.setStyle(node, 'height', value);
|
||||
dom.setAttrib(node, 'height', '');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle node change updates
|
||||
ed.onNodeChange.add(function(ed, cm, n) {
|
||||
var p;
|
||||
|
||||
n = ed.selection.getStart();
|
||||
p = ed.dom.getParent(n, 'td,th,caption');
|
||||
cm.setActive('table', n.nodeName === 'TABLE' || !!p);
|
||||
|
||||
// Disable table tools if we are in caption
|
||||
if (p && p.nodeName === 'CAPTION')
|
||||
p = 0;
|
||||
|
||||
cm.setDisabled('delete_table', !p);
|
||||
cm.setDisabled('delete_col', !p);
|
||||
cm.setDisabled('delete_table', !p);
|
||||
cm.setDisabled('delete_row', !p);
|
||||
cm.setDisabled('col_after', !p);
|
||||
cm.setDisabled('col_before', !p);
|
||||
cm.setDisabled('row_after', !p);
|
||||
cm.setDisabled('row_before', !p);
|
||||
cm.setDisabled('row_props', !p);
|
||||
cm.setDisabled('cell_props', !p);
|
||||
cm.setDisabled('split_cells', !p);
|
||||
cm.setDisabled('merge_cells', !p);
|
||||
});
|
||||
|
||||
ed.onInit.add(function(ed) {
|
||||
var startTable, startCell, dom = ed.dom, tableGrid;
|
||||
|
||||
winMan = ed.windowManager;
|
||||
|
||||
// Add cell selection logic
|
||||
ed.onMouseDown.add(function(ed, e) {
|
||||
if (e.button != 2) {
|
||||
cleanup();
|
||||
|
||||
startCell = dom.getParent(e.target, 'td,th');
|
||||
startTable = dom.getParent(startCell, 'table');
|
||||
}
|
||||
});
|
||||
|
||||
dom.bind(ed.getDoc(), 'mouseover', function(e) {
|
||||
var sel, table, target = e.target;
|
||||
|
||||
if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
|
||||
table = dom.getParent(target, 'table');
|
||||
if (table == startTable) {
|
||||
if (!tableGrid) {
|
||||
tableGrid = createTableGrid(table);
|
||||
tableGrid.setStartCell(startCell);
|
||||
|
||||
ed.getBody().style.webkitUserSelect = 'none';
|
||||
}
|
||||
|
||||
tableGrid.setEndCell(target);
|
||||
hasCellSelection = true;
|
||||
}
|
||||
|
||||
// Remove current selection
|
||||
sel = ed.selection.getSel();
|
||||
|
||||
try {
|
||||
if (sel.removeAllRanges)
|
||||
sel.removeAllRanges();
|
||||
else
|
||||
sel.empty();
|
||||
} catch (ex) {
|
||||
// IE9 might throw errors here
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
ed.onMouseUp.add(function(ed, e) {
|
||||
var rng, sel = ed.selection, selectedCells, nativeSel = sel.getSel(), walker, node, lastNode, endNode;
|
||||
|
||||
// Move selection to startCell
|
||||
if (startCell) {
|
||||
if (tableGrid)
|
||||
ed.getBody().style.webkitUserSelect = '';
|
||||
|
||||
function setPoint(node, start) {
|
||||
var walker = new tinymce.dom.TreeWalker(node, node);
|
||||
|
||||
do {
|
||||
// Text node
|
||||
if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
|
||||
if (start)
|
||||
rng.setStart(node, 0);
|
||||
else
|
||||
rng.setEnd(node, node.nodeValue.length);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// BR element
|
||||
if (node.nodeName == 'BR') {
|
||||
if (start)
|
||||
rng.setStartBefore(node);
|
||||
else
|
||||
rng.setEndBefore(node);
|
||||
|
||||
return;
|
||||
}
|
||||
} while (node = (start ? walker.next() : walker.prev()));
|
||||
}
|
||||
|
||||
// Try to expand text selection as much as we can only Gecko supports cell selection
|
||||
selectedCells = dom.select('td.mceSelected,th.mceSelected');
|
||||
if (selectedCells.length > 0) {
|
||||
rng = dom.createRng();
|
||||
node = selectedCells[0];
|
||||
endNode = selectedCells[selectedCells.length - 1];
|
||||
rng.setStartBefore(node);
|
||||
rng.setEndAfter(node);
|
||||
|
||||
setPoint(node, 1);
|
||||
walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
|
||||
|
||||
do {
|
||||
if (node.nodeName == 'TD' || node.nodeName == 'TH') {
|
||||
if (!dom.hasClass(node, 'mceSelected'))
|
||||
break;
|
||||
|
||||
lastNode = node;
|
||||
}
|
||||
} while (node = walker.next());
|
||||
|
||||
setPoint(lastNode);
|
||||
|
||||
sel.setRng(rng);
|
||||
}
|
||||
|
||||
ed.nodeChanged();
|
||||
startCell = tableGrid = startTable = null;
|
||||
}
|
||||
});
|
||||
|
||||
ed.onKeyUp.add(function(ed, e) {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
ed.onKeyDown.add(function (ed, e) {
|
||||
fixTableCellSelection(ed);
|
||||
});
|
||||
|
||||
ed.onMouseDown.add(function (ed, e) {
|
||||
if (e.button != 2) {
|
||||
fixTableCellSelection(ed);
|
||||
}
|
||||
});
|
||||
function tableCellSelected(ed, rng, n, currentCell) {
|
||||
// The decision of when a table cell is selected is somewhat involved. The fact that this code is
|
||||
// required is actually a pointer to the root cause of this bug. A cell is selected when the start
|
||||
// and end offsets are 0, the start container is a text, and the selection node is either a TR (most cases)
|
||||
// or the parent of the table (in the case of the selection containing the last cell of a table).
|
||||
var TEXT_NODE = 3, table = ed.dom.getParent(rng.startContainer, 'TABLE'),
|
||||
tableParent, allOfCellSelected, tableCellSelection;
|
||||
if (table)
|
||||
tableParent = table.parentNode;
|
||||
allOfCellSelected =rng.startContainer.nodeType == TEXT_NODE &&
|
||||
rng.startOffset == 0 &&
|
||||
rng.endOffset == 0 &&
|
||||
currentCell &&
|
||||
(n.nodeName=="TR" || n==tableParent);
|
||||
tableCellSelection = (n.nodeName=="TD"||n.nodeName=="TH")&& !currentCell;
|
||||
return allOfCellSelected || tableCellSelection;
|
||||
// return false;
|
||||
}
|
||||
|
||||
// this nasty hack is here to work around some WebKit selection bugs.
|
||||
function fixTableCellSelection(ed) {
|
||||
if (!tinymce.isWebKit)
|
||||
return;
|
||||
|
||||
var rng = ed.selection.getRng();
|
||||
var n = ed.selection.getNode();
|
||||
var currentCell = ed.dom.getParent(rng.startContainer, 'TD,TH');
|
||||
|
||||
if (!tableCellSelected(ed, rng, n, currentCell))
|
||||
return;
|
||||
if (!currentCell) {
|
||||
currentCell=n;
|
||||
}
|
||||
|
||||
// Get the very last node inside the table cell
|
||||
var end = currentCell.lastChild;
|
||||
while (end.lastChild)
|
||||
end = end.lastChild;
|
||||
|
||||
// Select the entire table cell. Nothing outside of the table cell should be selected.
|
||||
rng.setEnd(end, end.nodeValue.length);
|
||||
ed.selection.setRng(rng);
|
||||
}
|
||||
ed.plugins.table.fixTableCellSelection=fixTableCellSelection;
|
||||
|
||||
// Add context menu
|
||||
if (ed && ed.plugins.contextmenu) {
|
||||
ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
|
||||
var sm, se = ed.selection, el = se.getNode() || ed.getBody();
|
||||
|
||||
if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th') || ed.dom.select('td.mceSelected,th.mceSelected').length) {
|
||||
m.removeAll();
|
||||
|
||||
if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
|
||||
m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
|
||||
m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
|
||||
m.addSeparator();
|
||||
}
|
||||
|
||||
if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
|
||||
m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
|
||||
m.addSeparator();
|
||||
}
|
||||
|
||||
m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', value : {action : 'insert'}});
|
||||
m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable'});
|
||||
m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete'});
|
||||
m.addSeparator();
|
||||
|
||||
// Cell menu
|
||||
sm = m.addMenu({title : 'table.cell'});
|
||||
sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps'});
|
||||
sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells'});
|
||||
sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells'});
|
||||
|
||||
// Row menu
|
||||
sm = m.addMenu({title : 'table.row'});
|
||||
sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps'});
|
||||
sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
|
||||
sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
|
||||
sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
|
||||
sm.addSeparator();
|
||||
sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
|
||||
sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
|
||||
sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}).setDisabled(!clipboardRows);
|
||||
sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}).setDisabled(!clipboardRows);
|
||||
|
||||
// Column menu
|
||||
sm = m.addMenu({title : 'table.col'});
|
||||
sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
|
||||
sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
|
||||
sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
|
||||
} else
|
||||
m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable'});
|
||||
});
|
||||
}
|
||||
|
||||
// Fix to allow navigating up and down in a table in WebKit browsers.
|
||||
if (tinymce.isWebKit) {
|
||||
function moveSelection(ed, e) {
|
||||
var VK = tinymce.VK;
|
||||
var key = e.keyCode;
|
||||
|
||||
function handle(upBool, sourceNode, event) {
|
||||
var siblingDirection = upBool ? 'previousSibling' : 'nextSibling';
|
||||
var currentRow = ed.dom.getParent(sourceNode, 'tr');
|
||||
var siblingRow = currentRow[siblingDirection];
|
||||
|
||||
if (siblingRow) {
|
||||
moveCursorToRow(ed, sourceNode, siblingRow, upBool);
|
||||
tinymce.dom.Event.cancel(event);
|
||||
return true;
|
||||
} else {
|
||||
var tableNode = ed.dom.getParent(currentRow, 'table');
|
||||
var middleNode = currentRow.parentNode;
|
||||
var parentNodeName = middleNode.nodeName.toLowerCase();
|
||||
if (parentNodeName === 'tbody' || parentNodeName === (upBool ? 'tfoot' : 'thead')) {
|
||||
var targetParent = getTargetParent(upBool, tableNode, middleNode, 'tbody');
|
||||
if (targetParent !== null) {
|
||||
return moveToRowInTarget(upBool, targetParent, sourceNode, event);
|
||||
}
|
||||
}
|
||||
return escapeTable(upBool, currentRow, siblingDirection, tableNode, event);
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetParent(upBool, topNode, secondNode, nodeName) {
|
||||
var tbodies = ed.dom.select('>' + nodeName, topNode);
|
||||
var position = tbodies.indexOf(secondNode);
|
||||
if (upBool && position === 0 || !upBool && position === tbodies.length - 1) {
|
||||
return getFirstHeadOrFoot(upBool, topNode);
|
||||
} else if (position === -1) {
|
||||
var topOrBottom = secondNode.tagName.toLowerCase() === 'thead' ? 0 : tbodies.length - 1;
|
||||
return tbodies[topOrBottom];
|
||||
} else {
|
||||
return tbodies[position + (upBool ? -1 : 1)];
|
||||
}
|
||||
}
|
||||
|
||||
function getFirstHeadOrFoot(upBool, parent) {
|
||||
var tagName = upBool ? 'thead' : 'tfoot';
|
||||
var headOrFoot = ed.dom.select('>' + tagName, parent);
|
||||
return headOrFoot.length !== 0 ? headOrFoot[0] : null;
|
||||
}
|
||||
|
||||
function moveToRowInTarget(upBool, targetParent, sourceNode, event) {
|
||||
var targetRow = getChildForDirection(targetParent, upBool);
|
||||
targetRow && moveCursorToRow(ed, sourceNode, targetRow, upBool);
|
||||
tinymce.dom.Event.cancel(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
function escapeTable(upBool, currentRow, siblingDirection, table, event) {
|
||||
var tableSibling = table[siblingDirection];
|
||||
if (tableSibling) {
|
||||
moveCursorToStartOfElement(tableSibling);
|
||||
return true;
|
||||
} else {
|
||||
var parentCell = ed.dom.getParent(table, 'td,th');
|
||||
if (parentCell) {
|
||||
return handle(upBool, parentCell, event);
|
||||
} else {
|
||||
var backUpSibling = getChildForDirection(currentRow, !upBool);
|
||||
moveCursorToStartOfElement(backUpSibling);
|
||||
return tinymce.dom.Event.cancel(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getChildForDirection(parent, up) {
|
||||
var child = parent && parent[up ? 'lastChild' : 'firstChild'];
|
||||
// BR is not a valid table child to return in this case we return the table cell
|
||||
return child && child.nodeName === 'BR' ? ed.dom.getParent(child, 'td,th') : child;
|
||||
}
|
||||
|
||||
function moveCursorToStartOfElement(n) {
|
||||
ed.selection.setCursorLocation(n, 0);
|
||||
}
|
||||
|
||||
function isVerticalMovement() {
|
||||
return key == VK.UP || key == VK.DOWN;
|
||||
}
|
||||
|
||||
function isInTable(ed) {
|
||||
var node = ed.selection.getNode();
|
||||
var currentRow = ed.dom.getParent(node, 'tr');
|
||||
return currentRow !== null;
|
||||
}
|
||||
|
||||
function columnIndex(column) {
|
||||
var colIndex = 0;
|
||||
var c = column;
|
||||
while (c.previousSibling) {
|
||||
c = c.previousSibling;
|
||||
colIndex = colIndex + getSpanVal(c, "colspan");
|
||||
}
|
||||
return colIndex;
|
||||
}
|
||||
|
||||
function findColumn(rowElement, columnIndex) {
|
||||
var c = 0;
|
||||
var r = 0;
|
||||
each(rowElement.children, function(cell, i) {
|
||||
c = c + getSpanVal(cell, "colspan");
|
||||
r = i;
|
||||
if (c > columnIndex)
|
||||
return false;
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
function moveCursorToRow(ed, node, row, upBool) {
|
||||
var srcColumnIndex = columnIndex(ed.dom.getParent(node, 'td,th'));
|
||||
var tgtColumnIndex = findColumn(row, srcColumnIndex);
|
||||
var tgtNode = row.childNodes[tgtColumnIndex];
|
||||
var rowCellTarget = getChildForDirection(tgtNode, upBool);
|
||||
moveCursorToStartOfElement(rowCellTarget || tgtNode);
|
||||
}
|
||||
|
||||
function shouldFixCaret(preBrowserNode) {
|
||||
var newNode = ed.selection.getNode();
|
||||
var newParent = ed.dom.getParent(newNode, 'td,th');
|
||||
var oldParent = ed.dom.getParent(preBrowserNode, 'td,th');
|
||||
return newParent && newParent !== oldParent && checkSameParentTable(newParent, oldParent)
|
||||
}
|
||||
|
||||
function checkSameParentTable(nodeOne, NodeTwo) {
|
||||
return ed.dom.getParent(nodeOne, 'TABLE') === ed.dom.getParent(NodeTwo, 'TABLE');
|
||||
}
|
||||
|
||||
if (isVerticalMovement() && isInTable(ed)) {
|
||||
var preBrowserNode = ed.selection.getNode();
|
||||
setTimeout(function() {
|
||||
if (shouldFixCaret(preBrowserNode)) {
|
||||
handle(!e.shiftKey && key === VK.UP, preBrowserNode, e);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ed.onKeyDown.add(moveSelection);
|
||||
}
|
||||
|
||||
// Fixes an issue on Gecko where it's impossible to place the caret behind a table
|
||||
// This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
|
||||
if (!tinymce.isIE) {
|
||||
function fixTableCaretPos() {
|
||||
var last;
|
||||
|
||||
// Skip empty text nodes form the end
|
||||
for (last = ed.getBody().lastChild; last && last.nodeType == 3 && !last.nodeValue.length; last = last.previousSibling) ;
|
||||
|
||||
if (last && last.nodeName == 'TABLE')
|
||||
ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
|
||||
};
|
||||
|
||||
// Fixes an bug where it's impossible to place the caret before a table in Gecko
|
||||
// this fix solves it by detecting when the caret is at the beginning of such a table
|
||||
// and then manually moves the caret infront of the table
|
||||
if (tinymce.isGecko) {
|
||||
ed.onKeyDown.add(function(ed, e) {
|
||||
var rng, table, dom = ed.dom;
|
||||
|
||||
// On gecko it's not possible to place the caret before a table
|
||||
if (e.keyCode == 37 || e.keyCode == 38) {
|
||||
rng = ed.selection.getRng();
|
||||
table = dom.getParent(rng.startContainer, 'table');
|
||||
|
||||
if (table && ed.getBody().firstChild == table) {
|
||||
if (isAtStart(rng, table)) {
|
||||
rng = dom.createRng();
|
||||
|
||||
rng.setStartBefore(table);
|
||||
rng.setEndBefore(table);
|
||||
|
||||
ed.selection.setRng(rng);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ed.onKeyUp.add(fixTableCaretPos);
|
||||
ed.onSetContent.add(fixTableCaretPos);
|
||||
ed.onVisualAid.add(fixTableCaretPos);
|
||||
|
||||
ed.onPreProcess.add(function(ed, o) {
|
||||
var last = o.node.lastChild;
|
||||
|
||||
if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
|
||||
ed.dom.remove(last);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Fixes bug in Gecko where shift-enter in table cell does not place caret on new line
|
||||
*/
|
||||
if (tinymce.isGecko) {
|
||||
ed.onKeyDown.add(function(ed, e) {
|
||||
if (e.keyCode === tinymce.VK.ENTER && e.shiftKey) {
|
||||
var node = ed.selection.getRng().startContainer;
|
||||
var tableCell = dom.getParent(node, 'td,th');
|
||||
if (tableCell) {
|
||||
var zeroSizedNbsp = ed.getDoc().createTextNode("\uFEFF");
|
||||
dom.insertAfter(zeroSizedNbsp, node);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
fixTableCaretPos();
|
||||
ed.startContent = ed.getContent({format : 'raw'});
|
||||
}
|
||||
});
|
||||
|
||||
// Register action commands
|
||||
each({
|
||||
mceTableSplitCells : function(grid) {
|
||||
grid.split();
|
||||
},
|
||||
|
||||
mceTableMergeCells : function(grid) {
|
||||
var rowSpan, colSpan, cell;
|
||||
|
||||
cell = ed.dom.getParent(ed.selection.getNode(), 'th,td');
|
||||
if (cell) {
|
||||
rowSpan = cell.rowSpan;
|
||||
colSpan = cell.colSpan;
|
||||
}
|
||||
|
||||
if (!ed.dom.select('td.mceSelected,th.mceSelected').length) {
|
||||
winMan.open({
|
||||
url : url + '/merge_cells.htm',
|
||||
width : 240 + parseInt(ed.getLang('table.merge_cells_delta_width', 0)),
|
||||
height : 110 + parseInt(ed.getLang('table.merge_cells_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
rows : rowSpan,
|
||||
cols : colSpan,
|
||||
onaction : function(data) {
|
||||
grid.merge(cell, data.cols, data.rows);
|
||||
},
|
||||
plugin_url : url
|
||||
});
|
||||
} else
|
||||
grid.merge();
|
||||
},
|
||||
|
||||
mceTableInsertRowBefore : function(grid) {
|
||||
grid.insertRow(true);
|
||||
},
|
||||
|
||||
mceTableInsertRowAfter : function(grid) {
|
||||
grid.insertRow();
|
||||
},
|
||||
|
||||
mceTableInsertColBefore : function(grid) {
|
||||
grid.insertCol(true);
|
||||
},
|
||||
|
||||
mceTableInsertColAfter : function(grid) {
|
||||
grid.insertCol();
|
||||
},
|
||||
|
||||
mceTableDeleteCol : function(grid) {
|
||||
grid.deleteCols();
|
||||
},
|
||||
|
||||
mceTableDeleteRow : function(grid) {
|
||||
grid.deleteRows();
|
||||
},
|
||||
|
||||
mceTableCutRow : function(grid) {
|
||||
clipboardRows = grid.cutRows();
|
||||
},
|
||||
|
||||
mceTableCopyRow : function(grid) {
|
||||
clipboardRows = grid.copyRows();
|
||||
},
|
||||
|
||||
mceTablePasteRowBefore : function(grid) {
|
||||
grid.pasteRows(clipboardRows, true);
|
||||
},
|
||||
|
||||
mceTablePasteRowAfter : function(grid) {
|
||||
grid.pasteRows(clipboardRows);
|
||||
},
|
||||
|
||||
mceTableDelete : function(grid) {
|
||||
grid.deleteTable();
|
||||
}
|
||||
}, function(func, name) {
|
||||
ed.addCommand(name, function() {
|
||||
var grid = createTableGrid();
|
||||
|
||||
if (grid) {
|
||||
func(grid);
|
||||
ed.execCommand('mceRepaint');
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Register dialog commands
|
||||
each({
|
||||
mceInsertTable : function(val) {
|
||||
winMan.open({
|
||||
url : url + '/table.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.table_delta_width', 0)),
|
||||
height : 320 + parseInt(ed.getLang('table.table_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url,
|
||||
action : val ? val.action : 0
|
||||
});
|
||||
},
|
||||
|
||||
mceTableRowProps : function() {
|
||||
winMan.open({
|
||||
url : url + '/row.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.rowprops_delta_width', 0)),
|
||||
height : 295 + parseInt(ed.getLang('table.rowprops_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url
|
||||
});
|
||||
},
|
||||
|
||||
mceTableCellProps : function() {
|
||||
winMan.open({
|
||||
url : url + '/cell.htm',
|
||||
width : 400 + parseInt(ed.getLang('table.cellprops_delta_width', 0)),
|
||||
height : 295 + parseInt(ed.getLang('table.cellprops_delta_height', 0)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url
|
||||
});
|
||||
}
|
||||
}, function(func, name) {
|
||||
ed.addCommand(name, function(ui, val) {
|
||||
func(val);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
|
||||
})(tinymce);
|
||||
|
|
|
|||
53
library/tinymce/jscripts/tiny_mce/plugins/table/js/cell.js
vendored
Executable file → Normal file
53
library/tinymce/jscripts/tiny_mce/plugins/table/js/cell.js
vendored
Executable file → Normal file
|
|
@ -63,6 +63,11 @@ function init() {
|
|||
function updateAction() {
|
||||
var el, inst = ed, tdElm, trElm, tableElm, formObj = document.forms[0];
|
||||
|
||||
if (!AutoValidator.validate(formObj)) {
|
||||
tinyMCEPopup.alert(AutoValidator.getErrorMessages(formObj).join('. ') + '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
tinyMCEPopup.restoreSelection();
|
||||
el = ed.selection.getStart();
|
||||
tdElm = ed.dom.getParent(el, "td,th");
|
||||
|
|
@ -83,8 +88,6 @@ function updateAction() {
|
|||
return;
|
||||
}
|
||||
|
||||
ed.execCommand('mceBeginUndoLevel');
|
||||
|
||||
switch (getSelectValue(formObj, 'action')) {
|
||||
case "cell":
|
||||
var celltype = getSelectValue(formObj, 'celltype');
|
||||
|
|
@ -125,6 +128,36 @@ function updateAction() {
|
|||
|
||||
break;
|
||||
|
||||
case "col":
|
||||
var curr, col = 0, cell = trElm.firstChild, rows = tableElm.getElementsByTagName("tr");
|
||||
|
||||
if (cell.nodeName != "TD" && cell.nodeName != "TH")
|
||||
cell = nextCell(cell);
|
||||
|
||||
do {
|
||||
if (cell == tdElm)
|
||||
break;
|
||||
col += cell.getAttribute("colspan");
|
||||
} while ((cell = nextCell(cell)) != null);
|
||||
|
||||
for (var i=0; i<rows.length; i++) {
|
||||
cell = rows[i].firstChild;
|
||||
|
||||
if (cell.nodeName != "TD" && cell.nodeName != "TH")
|
||||
cell = nextCell(cell);
|
||||
|
||||
curr = 0;
|
||||
do {
|
||||
if (curr == col) {
|
||||
cell = updateCell(cell, true);
|
||||
break;
|
||||
}
|
||||
curr += cell.getAttribute("colspan");
|
||||
} while ((cell = nextCell(cell)) != null);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "all":
|
||||
var rows = tableElm.getElementsByTagName("tr");
|
||||
|
||||
|
|
@ -166,15 +199,15 @@ function updateCell(td, skip_id) {
|
|||
var dom = ed.dom;
|
||||
|
||||
if (!skip_id)
|
||||
td.setAttribute('id', formObj.id.value);
|
||||
dom.setAttrib(td, 'id', formObj.id.value);
|
||||
|
||||
td.setAttribute('align', formObj.align.value);
|
||||
td.setAttribute('vAlign', formObj.valign.value);
|
||||
td.setAttribute('lang', formObj.lang.value);
|
||||
td.setAttribute('dir', getSelectValue(formObj, 'dir'));
|
||||
td.setAttribute('style', ed.dom.serializeStyle(ed.dom.parseStyle(formObj.style.value)));
|
||||
td.setAttribute('scope', formObj.scope.value);
|
||||
ed.dom.setAttrib(td, 'class', getSelectValue(formObj, 'class'));
|
||||
dom.setAttrib(td, 'align', formObj.align.value);
|
||||
dom.setAttrib(td, 'vAlign', formObj.valign.value);
|
||||
dom.setAttrib(td, 'lang', formObj.lang.value);
|
||||
dom.setAttrib(td, 'dir', getSelectValue(formObj, 'dir'));
|
||||
dom.setAttrib(td, 'style', ed.dom.serializeStyle(ed.dom.parseStyle(formObj.style.value)));
|
||||
dom.setAttrib(td, 'scope', formObj.scope.value);
|
||||
dom.setAttrib(td, 'class', getSelectValue(formObj, 'class'));
|
||||
|
||||
// Clear deprecated attributes
|
||||
ed.dom.setAttrib(td, 'width', '');
|
||||
|
|
|
|||
0
library/tinymce/jscripts/tiny_mce/plugins/table/js/merge_cells.js
vendored
Executable file → Normal file
0
library/tinymce/jscripts/tiny_mce/plugins/table/js/merge_cells.js
vendored
Executable file → Normal file
36
library/tinymce/jscripts/tiny_mce/plugins/table/js/row.js
vendored
Executable file → Normal file
36
library/tinymce/jscripts/tiny_mce/plugins/table/js/row.js
vendored
Executable file → Normal file
|
|
@ -56,6 +56,11 @@ function updateAction() {
|
|||
var inst = tinyMCEPopup.editor, dom = inst.dom, trElm, tableElm, formObj = document.forms[0];
|
||||
var action = getSelectValue(formObj, 'action');
|
||||
|
||||
if (!AutoValidator.validate(formObj)) {
|
||||
tinyMCEPopup.alert(AutoValidator.getErrorMessages(formObj).join('. ') + '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
tinyMCEPopup.restoreSelection();
|
||||
trElm = dom.getParent(inst.selection.getStart(), "tr");
|
||||
tableElm = dom.getParent(inst.selection.getStart(), "table");
|
||||
|
|
@ -80,8 +85,6 @@ function updateAction() {
|
|||
return;
|
||||
}
|
||||
|
||||
inst.execCommand('mceBeginUndoLevel');
|
||||
|
||||
switch (action) {
|
||||
case "row":
|
||||
updateRow(trElm);
|
||||
|
|
@ -123,19 +126,19 @@ function updateRow(tr_elm, skip_id, skip_parent) {
|
|||
|
||||
// Update row element
|
||||
if (!skip_id)
|
||||
tr_elm.setAttribute('id', formObj.id.value);
|
||||
dom.setAttrib(tr_elm, 'id', formObj.id.value);
|
||||
|
||||
tr_elm.setAttribute('align', getSelectValue(formObj, 'align'));
|
||||
tr_elm.setAttribute('vAlign', getSelectValue(formObj, 'valign'));
|
||||
tr_elm.setAttribute('lang', formObj.lang.value);
|
||||
tr_elm.setAttribute('dir', getSelectValue(formObj, 'dir'));
|
||||
tr_elm.setAttribute('style', dom.serializeStyle(dom.parseStyle(formObj.style.value)));
|
||||
dom.setAttrib(tr_elm, 'align', getSelectValue(formObj, 'align'));
|
||||
dom.setAttrib(tr_elm, 'vAlign', getSelectValue(formObj, 'valign'));
|
||||
dom.setAttrib(tr_elm, 'lang', formObj.lang.value);
|
||||
dom.setAttrib(tr_elm, 'dir', getSelectValue(formObj, 'dir'));
|
||||
dom.setAttrib(tr_elm, 'style', dom.serializeStyle(dom.parseStyle(formObj.style.value)));
|
||||
dom.setAttrib(tr_elm, 'class', getSelectValue(formObj, 'class'));
|
||||
|
||||
// Clear deprecated attributes
|
||||
tr_elm.setAttribute('background', '');
|
||||
tr_elm.setAttribute('bgColor', '');
|
||||
tr_elm.setAttribute('height', '');
|
||||
dom.setAttrib(tr_elm, 'background', '');
|
||||
dom.setAttrib(tr_elm, 'bgColor', '');
|
||||
dom.setAttrib(tr_elm, 'height', '');
|
||||
|
||||
// Set styles
|
||||
tr_elm.style.height = getCSSSize(formObj.height.value);
|
||||
|
|
@ -163,13 +166,10 @@ function updateRow(tr_elm, skip_id, skip_parent) {
|
|||
if (newParent == null) {
|
||||
newParent = doc.createElement(dest);
|
||||
|
||||
if (dest == "thead") {
|
||||
if (theTable.firstChild.nodeName == 'CAPTION')
|
||||
inst.dom.insertAfter(newParent, theTable.firstChild);
|
||||
else
|
||||
theTable.insertBefore(newParent, theTable.firstChild);
|
||||
} else
|
||||
theTable.appendChild(newParent);
|
||||
if (theTable.firstChild.nodeName == 'CAPTION')
|
||||
inst.dom.insertAfter(newParent, theTable.firstChild);
|
||||
else
|
||||
theTable.insertBefore(newParent, theTable.firstChild);
|
||||
}
|
||||
|
||||
// append the row to the new parent
|
||||
|
|
|
|||
88
library/tinymce/jscripts/tiny_mce/plugins/table/js/table.js
vendored
Executable file → Normal file
88
library/tinymce/jscripts/tiny_mce/plugins/table/js/table.js
vendored
Executable file → Normal file
|
|
@ -12,7 +12,7 @@ function insertTable() {
|
|||
tinyMCEPopup.restoreSelection();
|
||||
|
||||
if (!AutoValidator.validate(formObj)) {
|
||||
tinyMCEPopup.alert(inst.getLang('invalid_data'));
|
||||
tinyMCEPopup.alert(AutoValidator.getErrorMessages(formObj).join('. ') + '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ function insertTable() {
|
|||
// Get form data
|
||||
cols = formObj.elements['cols'].value;
|
||||
rows = formObj.elements['rows'].value;
|
||||
border = formObj.elements['border'].value != "" ? formObj.elements['border'].value : 0;
|
||||
border = formObj.elements['border'].value != "" ? formObj.elements['border'].value : 0;
|
||||
cellpadding = formObj.elements['cellpadding'].value != "" ? formObj.elements['cellpadding'].value : "";
|
||||
cellspacing = formObj.elements['cellspacing'].value != "" ? formObj.elements['cellspacing'].value : "";
|
||||
align = getSelectValue(formObj, "align");
|
||||
|
|
@ -58,11 +58,21 @@ function insertTable() {
|
|||
|
||||
// Update table
|
||||
if (action == "update") {
|
||||
inst.execCommand('mceBeginUndoLevel');
|
||||
|
||||
dom.setAttrib(elm, 'cellPadding', cellpadding, true);
|
||||
dom.setAttrib(elm, 'cellSpacing', cellspacing, true);
|
||||
dom.setAttrib(elm, 'border', border);
|
||||
|
||||
if (!isCssSize(border)) {
|
||||
dom.setAttrib(elm, 'border', border);
|
||||
} else {
|
||||
dom.setAttrib(elm, 'border', '');
|
||||
}
|
||||
|
||||
if (border == '') {
|
||||
dom.setStyle(elm, 'border-width', '');
|
||||
dom.setStyle(elm, 'border', '');
|
||||
dom.setAttrib(elm, 'border', '');
|
||||
}
|
||||
|
||||
dom.setAttrib(elm, 'align', align);
|
||||
dom.setAttrib(elm, 'frame', frame);
|
||||
dom.setAttrib(elm, 'rules', rules);
|
||||
|
|
@ -82,7 +92,7 @@ function insertTable() {
|
|||
capEl = elm.ownerDocument.createElement('caption');
|
||||
|
||||
if (!tinymce.isIE)
|
||||
capEl.innerHTML = '<br _mce_bogus="1"/>';
|
||||
capEl.innerHTML = '<br data-mce-bogus="1"/>';
|
||||
|
||||
elm.insertBefore(capEl, elm.firstChild);
|
||||
}
|
||||
|
|
@ -121,7 +131,7 @@ function insertTable() {
|
|||
if (bordercolor != "") {
|
||||
elm.style.borderColor = bordercolor;
|
||||
elm.style.borderStyle = elm.style.borderStyle == "" ? "solid" : elm.style.borderStyle;
|
||||
elm.style.borderWidth = border == "" ? "1px" : border;
|
||||
elm.style.borderWidth = cssSize(border);
|
||||
} else
|
||||
elm.style.borderColor = '';
|
||||
|
||||
|
|
@ -134,7 +144,7 @@ function insertTable() {
|
|||
//elm.outerHTML = elm.outerHTML;
|
||||
|
||||
inst.nodeChanged();
|
||||
inst.execCommand('mceEndUndoLevel');
|
||||
inst.execCommand('mceEndUndoLevel', false, {}, {skip_undo: true});
|
||||
|
||||
// Repaint if dimensions changed
|
||||
if (formObj.width.value != orgTableWidth || formObj.height.value != orgTableHeight)
|
||||
|
|
@ -148,10 +158,13 @@ function insertTable() {
|
|||
html += '<table';
|
||||
|
||||
html += makeAttrib('id', id);
|
||||
html += makeAttrib('border', border);
|
||||
if (!isCssSize(border)) {
|
||||
html += makeAttrib('border', border);
|
||||
}
|
||||
|
||||
html += makeAttrib('cellpadding', cellpadding);
|
||||
html += makeAttrib('cellspacing', cellspacing);
|
||||
html += makeAttrib('_mce_new', '1');
|
||||
html += makeAttrib('data-mce-new', '1');
|
||||
|
||||
if (width && inst.settings.inline_styles) {
|
||||
if (style)
|
||||
|
|
@ -187,7 +200,7 @@ function insertTable() {
|
|||
|
||||
if (caption) {
|
||||
if (!tinymce.isIE)
|
||||
html += '<caption><br _mce_bogus="1"/></caption>';
|
||||
html += '<caption><br data-mce-bogus="1"/></caption>';
|
||||
else
|
||||
html += '<caption></caption>';
|
||||
}
|
||||
|
|
@ -197,7 +210,7 @@ function insertTable() {
|
|||
|
||||
for (var x=0; x<cols; x++) {
|
||||
if (!tinymce.isIE)
|
||||
html += '<td><br _mce_bogus="1"/></td>';
|
||||
html += '<td><br data-mce-bogus="1"/></td>';
|
||||
else
|
||||
html += '<td></td>';
|
||||
}
|
||||
|
|
@ -207,8 +220,6 @@ function insertTable() {
|
|||
|
||||
html += "</table>";
|
||||
|
||||
inst.execCommand('mceBeginUndoLevel');
|
||||
|
||||
// Move table
|
||||
if (inst.settings.fix_table_elements) {
|
||||
var patt = '';
|
||||
|
|
@ -231,17 +242,26 @@ function insertTable() {
|
|||
} else
|
||||
inst.execCommand('mceInsertContent', false, html);
|
||||
|
||||
tinymce.each(dom.select('table[_mce_new]'), function(node) {
|
||||
var td = dom.select('td', node);
|
||||
tinymce.each(dom.select('table[data-mce-new]'), function(node) {
|
||||
var tdorth = dom.select('td,th', node);
|
||||
|
||||
// Fixes a bug in IE where the caret cannot be placed after the table if the table is at the end of the document
|
||||
if (tinymce.isIE && node.nextSibling == null) {
|
||||
dom.insertAfter(dom.create('p'), node);
|
||||
}
|
||||
|
||||
inst.selection.select(td[0], true);
|
||||
inst.selection.collapse();
|
||||
try {
|
||||
// IE9 might fail to do this selection
|
||||
inst.selection.setCursorLocation(tdorth[0], 0);
|
||||
} catch (ex) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
dom.setAttrib(node, '_mce_new', '');
|
||||
dom.setAttrib(node, 'data-mce-new', '');
|
||||
});
|
||||
|
||||
inst.addVisual();
|
||||
inst.execCommand('mceEndUndoLevel');
|
||||
inst.execCommand('mceEndUndoLevel', false, {}, {skip_undo: true});
|
||||
|
||||
tinyMCEPopup.close();
|
||||
}
|
||||
|
|
@ -279,7 +299,7 @@ function init() {
|
|||
|
||||
var cols = 2, rows = 2, border = tinyMCEPopup.getParam('table_default_border', '0'), cellpadding = tinyMCEPopup.getParam('table_default_cellpadding', ''), cellspacing = tinyMCEPopup.getParam('table_default_cellspacing', '');
|
||||
var align = "", width = "", height = "", bordercolor = "", bgcolor = "", className = "";
|
||||
var id = "", summary = "", style = "", dir = "", lang = "", background = "", bgcolor = "", bordercolor = "", rules, frame;
|
||||
var id = "", summary = "", style = "", dir = "", lang = "", background = "", bgcolor = "", bordercolor = "", rules = "", frame = "";
|
||||
var inst = tinyMCEPopup.editor, dom = inst.dom;
|
||||
var formObj = document.forms[0];
|
||||
var elm = dom.getParent(inst.selection.getNode(), "table");
|
||||
|
|
@ -383,6 +403,20 @@ function changedSize() {
|
|||
formObj.style.value = dom.serializeStyle(st);
|
||||
}
|
||||
|
||||
function isCssSize(value) {
|
||||
return /^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)$/.test(value);
|
||||
}
|
||||
|
||||
function cssSize(value, def) {
|
||||
value = tinymce.trim(value || def);
|
||||
|
||||
if (!isCssSize(value)) {
|
||||
return parseInt(value, 10) + 'px';
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function changedBackgroundImage() {
|
||||
var formObj = document.forms[0];
|
||||
var st = dom.parseStyle(formObj.style.value);
|
||||
|
|
@ -397,8 +431,14 @@ function changedBorder() {
|
|||
var st = dom.parseStyle(formObj.style.value);
|
||||
|
||||
// Update border width if the element has a color
|
||||
if (formObj.border.value != "" && formObj.bordercolor.value != "")
|
||||
st['border-width'] = formObj.border.value + "px";
|
||||
if (formObj.border.value != "" && (isCssSize(formObj.border.value) || formObj.bordercolor.value != ""))
|
||||
st['border-width'] = cssSize(formObj.border.value);
|
||||
else {
|
||||
if (!formObj.border.value) {
|
||||
st['border'] = '';
|
||||
st['border-width'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
formObj.style.value = dom.serializeStyle(st);
|
||||
}
|
||||
|
|
@ -414,7 +454,7 @@ function changedColor() {
|
|||
|
||||
// Add border-width if it's missing
|
||||
if (!st['border-width'])
|
||||
st['border-width'] = formObj.border.value == "" ? "1px" : formObj.border.value + "px";
|
||||
st['border-width'] = cssSize(formObj.border.value, 1);
|
||||
}
|
||||
|
||||
formObj.style.value = dom.serializeStyle(st);
|
||||
|
|
|
|||
75
library/tinymce/jscripts/tiny_mce/plugins/table/langs/en_dlg.js
vendored
Executable file → Normal file
75
library/tinymce/jscripts/tiny_mce/plugins/table/langs/en_dlg.js
vendored
Executable file → Normal file
|
|
@ -1,74 +1 @@
|
|||
tinyMCE.addI18n('en.table_dlg',{
|
||||
general_tab:"General",
|
||||
advanced_tab:"Advanced",
|
||||
general_props:"General properties",
|
||||
advanced_props:"Advanced properties",
|
||||
rowtype:"Row in table part",
|
||||
title:"Insert/Modify table",
|
||||
width:"Width",
|
||||
height:"Height",
|
||||
cols:"Cols",
|
||||
rows:"Rows",
|
||||
cellspacing:"Cellspacing",
|
||||
cellpadding:"Cellpadding",
|
||||
border:"Border",
|
||||
align:"Alignment",
|
||||
align_default:"Default",
|
||||
align_left:"Left",
|
||||
align_right:"Right",
|
||||
align_middle:"Center",
|
||||
row_title:"Table row properties",
|
||||
cell_title:"Table cell properties",
|
||||
cell_type:"Cell type",
|
||||
valign:"Vertical alignment",
|
||||
align_top:"Top",
|
||||
align_bottom:"Bottom",
|
||||
bordercolor:"Border color",
|
||||
bgcolor:"Background color",
|
||||
merge_cells_title:"Merge table cells",
|
||||
id:"Id",
|
||||
style:"Style",
|
||||
langdir:"Language direction",
|
||||
langcode:"Language code",
|
||||
mime:"Target MIME type",
|
||||
ltr:"Left to right",
|
||||
rtl:"Right to left",
|
||||
bgimage:"Background image",
|
||||
summary:"Summary",
|
||||
td:"Data",
|
||||
th:"Header",
|
||||
cell_cell:"Update current cell",
|
||||
cell_row:"Update all cells in row",
|
||||
cell_all:"Update all cells in table",
|
||||
row_row:"Update current row",
|
||||
row_odd:"Update odd rows in table",
|
||||
row_even:"Update even rows in table",
|
||||
row_all:"Update all rows in table",
|
||||
thead:"Table Head",
|
||||
tbody:"Table Body",
|
||||
tfoot:"Table Foot",
|
||||
scope:"Scope",
|
||||
rowgroup:"Row Group",
|
||||
colgroup:"Col Group",
|
||||
col_limit:"You've exceeded the maximum number of columns of {$cols}.",
|
||||
row_limit:"You've exceeded the maximum number of rows of {$rows}.",
|
||||
cell_limit:"You've exceeded the maximum number of cells of {$cells}.",
|
||||
missing_scope:"Are you sure you want to continue without specifying a scope for this table header cell. Without it, it may be difficult for some users with disabilities to understand the content or data displayed of the table.",
|
||||
caption:"Table caption",
|
||||
frame:"Frame",
|
||||
frame_none:"none",
|
||||
frame_groups:"groups",
|
||||
frame_rows:"rows",
|
||||
frame_cols:"cols",
|
||||
frame_all:"all",
|
||||
rules:"Rules",
|
||||
rules_void:"void",
|
||||
rules_above:"above",
|
||||
rules_below:"below",
|
||||
rules_hsides:"hsides",
|
||||
rules_lhs:"lhs",
|
||||
rules_rhs:"rhs",
|
||||
rules_vsides:"vsides",
|
||||
rules_box:"box",
|
||||
rules_border:"border"
|
||||
});
|
||||
tinyMCE.addI18n('en.table_dlg',{"rules_border":"border","rules_box":"box","rules_vsides":"vsides","rules_rhs":"rhs","rules_lhs":"lhs","rules_hsides":"hsides","rules_below":"below","rules_above":"above","rules_void":"void",rules:"Rules","frame_all":"all","frame_cols":"cols","frame_rows":"rows","frame_groups":"groups","frame_none":"none",frame:"Frame",caption:"Table Caption","missing_scope":"Are you sure you want to continue without specifying a scope for this table header cell. Without it, it may be difficult for some users with disabilities to understand the content or data displayed of the table.","cell_limit":"You\'ve exceeded the maximum number of cells of {$cells}.","row_limit":"You\'ve exceeded the maximum number of rows of {$rows}.","col_limit":"You\'ve exceeded the maximum number of columns of {$cols}.",colgroup:"Col Group",rowgroup:"Row Group",scope:"Scope",tfoot:"Footer",tbody:"Body",thead:"Header","row_all":"Update All Rows in Table","row_even":"Update Even Rows in Table","row_odd":"Update Odd Rows in Table","row_row":"Update Current Row","cell_all":"Update All Cells in Table","cell_row":"Update All Cells in Row","cell_cell":"Update Current Cell",th:"Header",td:"Data",summary:"Summary",bgimage:"Background Image",rtl:"Right to Left",ltr:"Left to Right",mime:"Target MIME Type",langcode:"Language Code",langdir:"Language Direction",style:"Style",id:"ID","merge_cells_title":"Merge Table Cells",bgcolor:"Background Color",bordercolor:"Border Color","align_bottom":"Bottom","align_top":"Top",valign:"Vertical Alignment","cell_type":"Cell Type","cell_title":"Table Cell Properties","row_title":"Table Row Properties","align_middle":"Center","align_right":"Right","align_left":"Left","align_default":"Default",align:"Alignment",border:"Border",cellpadding:"Cell Padding",cellspacing:"Cell Spacing",rows:"Rows",cols:"Columns",height:"Height",width:"Width",title:"Insert/Edit Table",rowtype:"Row Type","advanced_props":"Advanced Properties","general_props":"General Properties","advanced_tab":"Advanced","general_tab":"General","cell_col":"Update all cells in column"});
|
||||
22
library/tinymce/jscripts/tiny_mce/plugins/table/merge_cells.htm
vendored
Executable file → Normal file
22
library/tinymce/jscripts/tiny_mce/plugins/table/merge_cells.htm
vendored
Executable file → Normal file
|
|
@ -7,20 +7,20 @@
|
|||
<script type="text/javascript" src="../../utils/validate.js"></script>
|
||||
<script type="text/javascript" src="js/merge_cells.js"></script>
|
||||
</head>
|
||||
<body style="margin: 8px">
|
||||
<body style="margin: 8px" role="application">
|
||||
<form onsubmit="MergeCellsDialog.merge();return false;" action="#">
|
||||
<fieldset>
|
||||
<legend>{#table_dlg.merge_cells_title}</legend>
|
||||
<table border="0" cellpadding="0" cellspacing="3" width="100%">
|
||||
<tr>
|
||||
<td>{#table_dlg.cols}:</td>
|
||||
<td align="right"><input type="text" name="numcols" value="" class="number min1 mceFocus" style="width: 30px" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{#table_dlg.rows}:</td>
|
||||
<td align="right"><input type="text" name="numrows" value="" class="number min1" style="width: 30px" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="3" width="100%">
|
||||
<tr>
|
||||
<td><label for="numcols">{#table_dlg.cols}</label>:</td>
|
||||
<td align="right"><input type="text" id="numcols" name="numcols" value="" class="number min1 mceFocus" style="width: 30px" aria-required="true" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="numrows">{#table_dlg.rows}</label>:</td>
|
||||
<td align="right"><input type="text" id="numrows" name="numrows" value="" class="number min1" style="width: 30px" aria-required="true" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
<div class="mceActionPanel">
|
||||
|
|
|
|||
21
library/tinymce/jscripts/tiny_mce/plugins/table/row.htm
vendored
Executable file → Normal file
21
library/tinymce/jscripts/tiny_mce/plugins/table/row.htm
vendored
Executable file → Normal file
|
|
@ -5,16 +5,17 @@
|
|||
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
|
||||
<script type="text/javascript" src="../../utils/mctabs.js"></script>
|
||||
<script type="text/javascript" src="../../utils/form_utils.js"></script>
|
||||
<script type="text/javascript" src="../../utils/validate.js"></script>
|
||||
<script type="text/javascript" src="../../utils/editable_selects.js"></script>
|
||||
<script type="text/javascript" src="js/row.js"></script>
|
||||
<link href="css/row.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body id="tablerow" style="display: none">
|
||||
<body id="tablerow" style="display: none" role="application">
|
||||
<form onsubmit="updateAction();return false;" action="#">
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="general_tab" class="current"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
<li id="general_tab" class="current" aria-controls="general_panel"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab" aria-controls="advanced_panel"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
<fieldset>
|
||||
<legend>{#table_dlg.general_props}</legend>
|
||||
|
||||
<table border="0" cellpadding="4" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="4" cellspacing="0">
|
||||
<tr>
|
||||
<td><label for="rowtype">{#table_dlg.rowtype}</label></td>
|
||||
<td class="col2">
|
||||
|
|
@ -70,7 +71,7 @@
|
|||
|
||||
<tr>
|
||||
<td><label for="height">{#table_dlg.height}</label></td>
|
||||
<td class="col2"><input name="height" type="text" id="height" value="" size="4" maxlength="4" onchange="changedSize();" /></td>
|
||||
<td class="col2"><input name="height" type="text" id="height" value="" size="7" maxlength="7" onchange="changedSize();" class="size" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
|
@ -80,7 +81,7 @@
|
|||
<fieldset>
|
||||
<legend>{#table_dlg.advanced_props}</legend>
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="4">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="4">
|
||||
<tr>
|
||||
<td class="column1"><label for="id">{#table_dlg.id}</label></td>
|
||||
<td><input id="id" name="id" type="text" value="" style="width: 200px" /></td>
|
||||
|
|
@ -112,7 +113,7 @@
|
|||
<tr>
|
||||
<td class="column1"><label for="backgroundimage">{#table_dlg.bgimage}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="backgroundimage" name="backgroundimage" type="text" value="" style="width: 200px" onchange="changedBackgroundImage();" /></td>
|
||||
<td id="backgroundimagebrowsercontainer"> </td>
|
||||
|
|
@ -122,14 +123,16 @@
|
|||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="column1"><label for="bgcolor">{#table_dlg.bgcolor}</label></td>
|
||||
<td class="column1"><label for="bgcolor" id="bgcolor_label">{#table_dlg.bgcolor}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<span role="group" aria-labelledby="bgcolor_label">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="bgcolor" name="bgcolor" type="text" value="" size="9" onchange="updateColor('bgcolor_pick','bgcolor');changedColor();" /></td>
|
||||
<td id="bgcolor_pickcontainer"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
107
library/tinymce/jscripts/tiny_mce/plugins/table/table.htm
vendored
Executable file → Normal file
107
library/tinymce/jscripts/tiny_mce/plugins/table/table.htm
vendored
Executable file → Normal file
|
|
@ -10,12 +10,13 @@
|
|||
<script type="text/javascript" src="js/table.js"></script>
|
||||
<link href="css/table.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body id="table" style="display: none">
|
||||
<body id="table" style="display: none" role="application" aria-labelledby="app_title">
|
||||
<span style="display:none;" id="app_title">{#table_dlg.title}</span>
|
||||
<form onsubmit="insertTable();return false;" action="#">
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="general_tab" class="current"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
<li id="general_tab" aria-controls="general_panel" class="current"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
|
||||
<li id="advanced_tab" aria-controls="advanced_panel"><span><a href="javascript:mcTabs.displayTab('advanced_tab','advanced_panel');" onmousedown="return false;">{#table_dlg.advanced_tab}</a></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -23,48 +24,48 @@
|
|||
<div id="general_panel" class="panel current">
|
||||
<fieldset>
|
||||
<legend>{#table_dlg.general_props}</legend>
|
||||
<table border="0" cellpadding="4" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td><label id="colslabel" for="cols">{#table_dlg.cols}</label></td>
|
||||
<td><input id="cols" name="cols" type="text" value="" size="3" maxlength="3" class="required number min1 mceFocus" /></td>
|
||||
<td><label id="rowslabel" for="rows">{#table_dlg.rows}</label></td>
|
||||
<td><input id="rows" name="rows" type="text" value="" size="3" maxlength="3" class="required number min1" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label id="cellpaddinglabel" for="cellpadding">{#table_dlg.cellpadding}</label></td>
|
||||
<td><input id="cellpadding" name="cellpadding" type="text" value="" size="3" maxlength="3" class="number" /></td>
|
||||
<td><label id="cellspacinglabel" for="cellspacing">{#table_dlg.cellspacing}</label></td>
|
||||
<td><input id="cellspacing" name="cellspacing" type="text" value="" size="3" maxlength="3" class="number" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label id="alignlabel" for="align">{#table_dlg.align}</label></td>
|
||||
<td><select id="align" name="align">
|
||||
<option value="">{#not_set}</option>
|
||||
<option value="center">{#table_dlg.align_middle}</option>
|
||||
<option value="left">{#table_dlg.align_left}</option>
|
||||
<option value="right">{#table_dlg.align_right}</option>
|
||||
</select></td>
|
||||
<td><label id="borderlabel" for="border">{#table_dlg.border}</label></td>
|
||||
<td><input id="border" name="border" type="text" value="" size="3" maxlength="3" onchange="changedBorder();" class="number" /></td>
|
||||
</tr>
|
||||
<tr id="width_row">
|
||||
<td><label id="widthlabel" for="width">{#table_dlg.width}</label></td>
|
||||
<td><input name="width" type="text" id="width" value="" size="4" maxlength="4" onchange="changedSize();" class="size" /></td>
|
||||
<td><label id="heightlabel" for="height">{#table_dlg.height}</label></td>
|
||||
<td><input name="height" type="text" id="height" value="" size="4" maxlength="4" onchange="changedSize();" class="size" /></td>
|
||||
</tr>
|
||||
<tr id="styleSelectRow">
|
||||
<td><label id="classlabel" for="class">{#class_name}</label></td>
|
||||
<td colspan="3">
|
||||
<select id="class" name="class" class="mceEditableSelect">
|
||||
<option value="" selected="selected">{#not_set}</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="column1"><label for="caption">{#table_dlg.caption}</label></td>
|
||||
<td><input id="caption" name="caption" type="checkbox" class="checkbox" value="true" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table role="presentation" border="0" cellpadding="4" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td><label id="colslabel" for="cols">{#table_dlg.cols}</label></td>
|
||||
<td><input id="cols" name="cols" type="text" value="" size="3" maxlength="3" class="required number min1 mceFocus" aria-required="true" /></td>
|
||||
<td><label id="rowslabel" for="rows">{#table_dlg.rows}</label></td>
|
||||
<td><input id="rows" name="rows" type="text" value="" size="3" maxlength="3" class="required number min1" aria-required="true" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label id="cellpaddinglabel" for="cellpadding">{#table_dlg.cellpadding}</label></td>
|
||||
<td><input id="cellpadding" name="cellpadding" type="text" value="" size="3" maxlength="3" class="number" /></td>
|
||||
<td><label id="cellspacinglabel" for="cellspacing">{#table_dlg.cellspacing}</label></td>
|
||||
<td><input id="cellspacing" name="cellspacing" type="text" value="" size="3" maxlength="3" class="number" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label id="alignlabel" for="align">{#table_dlg.align}</label></td>
|
||||
<td><select id="align" name="align">
|
||||
<option value="">{#not_set}</option>
|
||||
<option value="center">{#table_dlg.align_middle}</option>
|
||||
<option value="left">{#table_dlg.align_left}</option>
|
||||
<option value="right">{#table_dlg.align_right}</option>
|
||||
</select></td>
|
||||
<td><label id="borderlabel" for="border">{#table_dlg.border}</label></td>
|
||||
<td><input id="border" name="border" type="text" value="" size="3" maxlength="5" onchange="changedBorder();" class="size" /></td>
|
||||
</tr>
|
||||
<tr id="width_row">
|
||||
<td><label id="widthlabel" for="width">{#table_dlg.width}</label></td>
|
||||
<td><input name="width" type="text" id="width" value="" size="7" maxlength="7" onchange="changedSize();" class="size" /></td>
|
||||
<td><label id="heightlabel" for="height">{#table_dlg.height}</label></td>
|
||||
<td><input name="height" type="text" id="height" value="" size="7" maxlength="7" onchange="changedSize();" class="size" /></td>
|
||||
</tr>
|
||||
<tr id="styleSelectRow" >
|
||||
<td><label id="classlabel" for="class">{#class_name}</label></td>
|
||||
<td colspan="3" >
|
||||
<select id="class" name="class" class="mceEditableSelect">
|
||||
<option value="" selected="selected">{#not_set}</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="column1" ><label for="caption">{#table_dlg.caption}</label></td>
|
||||
<td><input id="caption" name="caption" type="checkbox" class="checkbox" value="true" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
|
|
@ -72,7 +73,7 @@
|
|||
<fieldset>
|
||||
<legend>{#table_dlg.advanced_props}</legend>
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="4">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="4">
|
||||
<tr>
|
||||
<td class="column1"><label for="id">{#table_dlg.id}</label></td>
|
||||
<td><input id="id" name="id" type="text" value="" class="advfield" /></td>
|
||||
|
|
@ -98,7 +99,7 @@
|
|||
<tr>
|
||||
<td class="column1"><label for="backgroundimage">{#table_dlg.bgimage}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" aria-labelledby="backgroundimage_label" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="backgroundimage" name="backgroundimage" type="text" value="" class="advfield" onchange="changedBackgroundImage();" /></td>
|
||||
<td id="backgroundimagebrowsercontainer"> </td>
|
||||
|
|
@ -150,10 +151,10 @@
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="column1"><label for="bordercolor">{#table_dlg.bordercolor}</label></td>
|
||||
<tr role="group" aria-labelledby="bordercolor_label">
|
||||
<td class="column1"><label id="bordercolor_label" for="bordercolor">{#table_dlg.bordercolor}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="bordercolor" name="bordercolor" type="text" value="" size="9" onchange="updateColor('bordercolor_pick','bordercolor');changedColor();" /></td>
|
||||
<td id="bordercolor_pickcontainer"> </td>
|
||||
|
|
@ -162,10 +163,10 @@
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="column1"><label for="bgcolor">{#table_dlg.bgcolor}</label></td>
|
||||
<tr role="group" aria-labelledby="bgcolor_label">
|
||||
<td class="column1"><label id="bgcolor_label" for="bgcolor">{#table_dlg.bgcolor}</label></td>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td><input id="bgcolor" name="bgcolor" type="text" value="" size="9" onchange="updateColor('bgcolor_pick','bgcolor');changedColor();" /></td>
|
||||
<td id="bgcolor_pickcontainer"> </td>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue