| | |
| | | /**
|
| | | * $Id: editor_plugin_src.js 768 2008-04-04 13:52:49Z spocke $
|
| | | * $Id: editor_plugin_src.js 853 2008-05-27 08:05:35Z spocke $
|
| | | *
|
| | | * @author Moxiecode
|
| | | * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
|
| | |
| | |
|
| | | // Add undo level when new rows are created using the tab key
|
| | | ed.onKeyDown.add(function(ed, e) {
|
| | | if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE'))
|
| | | if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE')) {
|
| | | if (!tinymce.isGecko && !tinymce.isOpera) {
|
| | | tinyMCE.execInstanceCommand(ed.editorId, "mceTableMoveToNextRow", true);
|
| | | return tinymce.dom.Event.cancel(e);
|
| | | }
|
| | |
|
| | | ed.undoManager.add();
|
| | | }
|
| | | });
|
| | |
|
| | | // Select whole table is a table border is clicked
|
| | | if (!tinymce.isIE) {
|
| | | if (ed.getParam('table_selection', true)) {
|
| | | ed.onClick.add(function(ed, e) {
|
| | | e = e.target;
|
| | |
|
| | | if (e.nodeName === 'TABLE')
|
| | | ed.selection.select(e);
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | | ed.onNodeChange.add(function(ed, cm, n) {
|
| | | var p = ed.dom.getParent(n, 'td,th,caption');
|
| | |
|
| | | cm.setActive('table', !!p);
|
| | | cm.setActive('table', n.nodeName === 'TABLE' || !!p);
|
| | | if (p && p.nodeName === 'CAPTION')
|
| | | p = null;
|
| | |
|
| | |
| | |
|
| | | // Is table command
|
| | | switch (cmd) {
|
| | | case "mceTableMoveToNextRow":
|
| | | case "mceInsertTable":
|
| | | case "mceTableRowProps":
|
| | | case "mceTableCellProps":
|
| | |
| | | return grid[row][col];
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | function getNextCell(table, cell) {
|
| | | var cells = [], x = 0, i, j, cell, nextCell;
|
| | |
|
| | | for (i = 0; i < table.rows.length; i++)
|
| | | for (j = 0; j < table.rows[i].cells.length; j++, x++)
|
| | | cells[x] = table.rows[i].cells[j];
|
| | |
|
| | | for (i = 0; i < cells.length; i++)
|
| | | if (cells[i] == cell)
|
| | | if (nextCell = cells[i+1])
|
| | | return nextCell;
|
| | | }
|
| | |
|
| | | function getTableGrid(table) {
|
| | |
| | |
|
| | | // Handle commands
|
| | | switch (command) {
|
| | | case "mceTableMoveToNextRow":
|
| | | var nextCell = getNextCell(tableElm, tdElm);
|
| | |
|
| | | if (!nextCell) {
|
| | | inst.execCommand("mceTableInsertRowAfter", tdElm);
|
| | | nextCell = getNextCell(tableElm, tdElm);
|
| | | }
|
| | |
|
| | | inst.selection.select(nextCell);
|
| | | inst.selection.collapse(true);
|
| | |
|
| | | return true;
|
| | |
|
| | | case "mceTableRowProps":
|
| | | if (trElm == null)
|
| | | return true;
|
| | |
| | | var cpos = getCellPos(grid, tdElm);
|
| | |
|
| | | // Only one row, remove whole table
|
| | | if (grid.length == 1) {
|
| | | if (grid.length == 1 && tableElm.nodeName == 'TBODY') {
|
| | | inst.dom.remove(inst.dom.getParent(tableElm, "table"));
|
| | | return true;
|
| | | }
|
| | |
| | | var lastTDElm = null;
|
| | |
|
| | | // Only one col, remove whole table
|
| | | if (grid.length > 1 && grid[0].length <= 1) {
|
| | | if ((grid.length > 1 && grid[0].length <= 1) && tableElm.nodeName == 'TBODY') {
|
| | | inst.dom.remove(inst.dom.getParent(tableElm, "table"));
|
| | | return true;
|
| | | }
|
| | |
| | | if (!tdElm)
|
| | | break;
|
| | |
|
| | | if (tdElm.nodeName == "TD")
|
| | | if (tdElm.nodeName == "TD" || tdElm.nodeName == "TH")
|
| | | cells[cells.length] = tdElm;
|
| | | }
|
| | |
|