return;\r
\r
// Create a clone of the row.\r
- var newRow = row.clone( true );\r
+ var newRow = row.clone( 1 );\r
\r
- // Insert the new row before of it.\r
- newRow.insertBefore( row );\r
+ insertBefore ?\r
+ newRow.insertBefore( row ) :\r
+ newRow.insertAfter( row );\r
\r
- // Clean one of the rows to produce the illusion of inserting an empty row\r
- // before or after.\r
- clearRow( insertBefore ? newRow.$ : row.$ );\r
+ // Clean the new row.\r
+ clearRow( newRow.$ );\r
}\r
\r
function deleteRows( selectionOrRow )\r
{\r
// Get the cell where the selection is placed in.\r
var startElement = selection.getStartElement();\r
- var cell = startElement.getAscendant( 'td', true ) || startElement.getAscendant( 'th', true );\r
+ var cell = startElement.getAscendant( 'td', 1 ) || startElement.getAscendant( 'th', 1 );\r
\r
if ( !cell )\r
return;\r
if ( $row.cells.length < ( cellIndex + 1 ) )\r
continue;\r
\r
- cell = ( new CKEDITOR.dom.element( $row.cells[ cellIndex ] ) ).clone( false );\r
+ cell = ( new CKEDITOR.dom.element( $row.cells[ cellIndex ] ) ).clone( 0 );\r
\r
if ( !CKEDITOR.env.ie )\r
cell.appendBogus();\r
function insertCell( selection, insertBefore )\r
{\r
var startElement = selection.getStartElement();\r
- var cell = startElement.getAscendant( 'td', true ) || startElement.getAscendant( 'th', true );\r
+ var cell = startElement.getAscendant( 'td', 1 ) || startElement.getAscendant( 'th', 1 );\r
\r
if ( !cell )\r
return;\r
range.select( true );\r
}\r
\r
- function buildTableMap( table )\r
- {\r
-\r
- var aRows = table.$.rows ;\r
-\r
- // Row and Column counters.\r
- var r = -1 ;\r
-\r
- var aMap = [];\r
-\r
- for ( var i = 0 ; i < aRows.length ; i++ )\r
- {\r
- r++ ;\r
- !aMap[r] && ( aMap[r] = [] );\r
-\r
- var c = -1 ;\r
-\r
- for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
- {\r
- var oCell = aRows[i].cells[j] ;\r
-\r
- c++ ;\r
- while ( aMap[r][c] )\r
- c++ ;\r
-\r
- var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
- var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
-\r
- for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
- {\r
- if ( !aMap[r + rs] )\r
- aMap[r + rs] = new Array() ;\r
-\r
- for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
- {\r
- aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
- }\r
- }\r
-\r
- c += iColSpan - 1 ;\r
- }\r
- }\r
- return aMap ;\r
- }\r
-\r
function cellInRow( tableMap, rowIndex, cell )\r
{\r
var oRow = tableMap[ rowIndex ];\r
var cell,\r
firstCell = cells[ 0 ],\r
table = firstCell.getAscendant( 'table' ),\r
- map = buildTableMap( table ),\r
+ map = CKEDITOR.tools.buildTableMap( table ),\r
mapHeight = map.length,\r
mapWidth = map[ 0 ].length,\r
startRow = firstCell.getParent().$.rowIndex,\r
var cell = cells[ 0 ],\r
tr = cell.getParent(),\r
table = tr.getAscendant( 'table' ),\r
- map = buildTableMap( table ),\r
+ map = CKEDITOR.tools.buildTableMap( table ),\r
rowIndex = tr.$.rowIndex,\r
colIndex = cellInRow( map, rowIndex, cell ),\r
rowSpan = cell.$.rowSpan,\r
var cell = cells[ 0 ],\r
tr = cell.getParent(),\r
table = tr.getAscendant( 'table' ),\r
- map = buildTableMap( table ),\r
+ map = CKEDITOR.tools.buildTableMap( table ),\r
rowIndex = tr.$.rowIndex,\r
colIndex = cellInRow( map, rowIndex, cell ),\r
colSpan = cell.$.colSpan,\r
{\r
exec : function( editor )\r
{\r
- var selection = editor.getSelection();\r
- var startElement = selection && selection.getStartElement();\r
- var table = startElement && startElement.getAscendant( 'table', true );\r
+ var selection = editor.getSelection(),\r
+ startElement = selection && selection.getStartElement(),\r
+ table = startElement && startElement.getAscendant( 'table', 1 );\r
\r
if ( !table )\r
return;\r
range.collapse();\r
selection.selectRanges( [ range ] );\r
\r
- // If the table's parent has only one child, remove it,except body,as well.( #5416 )\r
+ // If the table's parent has only one child remove it as well (unless it's the body or a table cell) (#5416, #6289)\r
var parent = table.getParent();\r
- if ( parent.getChildCount() == 1 && parent.getName() != 'body' )\r
+ if ( parent.getChildCount() == 1 && !parent.is( 'body', 'td', 'th' ) )\r
parent.remove();\r
else\r
table.remove();\r
{\r
editor.contextMenu.addListener( function( element, selection )\r
{\r
- if ( !element )\r
+ if ( !element || element.isReadOnly() )\r
return null;\r
\r
while ( element )\r
};\r
CKEDITOR.plugins.add( 'tabletools', CKEDITOR.plugins.tabletools );\r
})();\r
+\r
+/**\r
+ * Create a two-dimension array that reflects the actual layout of table cells,\r
+ * with cell spans, with mappings to the original td elements.\r
+ * @param table {CKEDITOR.dom.element}\r
+ */\r
+CKEDITOR.tools.buildTableMap = function ( table )\r
+{\r
+ var aRows = table.$.rows ;\r
+\r
+ // Row and Column counters.\r
+ var r = -1 ;\r
+\r
+ var aMap = [];\r
+\r
+ for ( var i = 0 ; i < aRows.length ; i++ )\r
+ {\r
+ r++ ;\r
+ !aMap[r] && ( aMap[r] = [] );\r
+\r
+ var c = -1 ;\r
+\r
+ for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
+ {\r
+ var oCell = aRows[i].cells[j] ;\r
+\r
+ c++ ;\r
+ while ( aMap[r][c] )\r
+ c++ ;\r
+\r
+ var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
+ var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
+\r
+ for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
+ {\r
+ if ( !aMap[r + rs] )\r
+ aMap[r + rs] = [];\r
+\r
+ for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
+ {\r
+ aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
+ }\r
+ }\r
+\r
+ c += iColSpan - 1 ;\r
+ }\r
+ }\r
+ return aMap ;\r
+};\r