2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 function removeRawAttribute( $node, attr )
\r
10 if ( CKEDITOR.env.ie )
\r
11 $node.removeAttribute( attr );
\r
13 delete $node[ attr ];
\r
16 var cellNodeRegex = /^(?:td|th)$/;
\r
18 function getSelectedCells( selection )
\r
20 // Walker will try to split text nodes, which will make the current selection
\r
21 // invalid. So save bookmarks before doing anything.
\r
22 var bookmarks = selection.createBookmarks();
\r
24 var ranges = selection.getRanges();
\r
28 function moveOutOfCellGuard( node )
\r
30 // Apply to the first cell only.
\r
31 if ( retval.length > 0 )
\r
34 // If we are exiting from the first </td>, then the td should definitely be
\r
36 if ( node.type == CKEDITOR.NODE_ELEMENT && cellNodeRegex.test( node.getName() )
\r
37 && !node.getCustomData( 'selected_cell' ) )
\r
39 CKEDITOR.dom.element.setMarker( database, node, 'selected_cell', true );
\r
40 retval.push( node );
\r
44 for ( var i = 0 ; i < ranges.length ; i++ )
\r
46 var range = ranges[ i ];
\r
48 if ( range.collapsed )
\r
50 // Walker does not handle collapsed ranges yet - fall back to old API.
\r
51 var startNode = range.getCommonAncestor();
\r
52 var nearestCell = startNode.getAscendant( 'td', true ) || startNode.getAscendant( 'th', true );
\r
54 retval.push( nearestCell );
\r
58 var walker = new CKEDITOR.dom.walker( range );
\r
60 walker.guard = moveOutOfCellGuard;
\r
62 while ( ( node = walker.next() ) )
\r
64 // If may be possible for us to have a range like this:
\r
65 // <td>^1</td><td>^2</td>
\r
66 // The 2nd td shouldn't be included.
\r
68 // So we have to take care to include a td we've entered only when we've
\r
69 // walked into its children.
\r
71 var parent = node.getParent();
\r
72 if ( parent && cellNodeRegex.test( parent.getName() ) && !parent.getCustomData( 'selected_cell' ) )
\r
74 CKEDITOR.dom.element.setMarker( database, parent, 'selected_cell', true );
\r
75 retval.push( parent );
\r
81 CKEDITOR.dom.element.clearAllMarkers( database );
\r
83 // Restore selection position.
\r
84 selection.selectBookmarks( bookmarks );
\r
89 function getFocusElementAfterDelCells( cellsToDelete ) {
\r
91 last = cellsToDelete.length - 1,
\r
96 while ( ( cell = cellsToDelete[ i++ ] ) )
\r
97 CKEDITOR.dom.element.setMarker( database, cell, 'delete_cell', true );
\r
99 // 1.first we check left or right side focusable cell row by row;
\r
101 while ( ( cell = cellsToDelete[ i++ ] ) )
\r
103 if ( ( focusedCell = cell.getPrevious() ) && !focusedCell.getCustomData( 'delete_cell' )
\r
104 || ( focusedCell = cell.getNext() ) && !focusedCell.getCustomData( 'delete_cell' ) )
\r
106 CKEDITOR.dom.element.clearAllMarkers( database );
\r
107 return focusedCell;
\r
111 CKEDITOR.dom.element.clearAllMarkers( database );
\r
113 // 2. then we check the toppest row (outside the selection area square) focusable cell
\r
114 tr = cellsToDelete[ 0 ].getParent();
\r
115 if ( ( tr = tr.getPrevious() ) )
\r
116 return tr.getLast();
\r
118 // 3. last we check the lowerest row focusable cell
\r
119 tr = cellsToDelete[ last ].getParent();
\r
120 if ( ( tr = tr.getNext() ) )
\r
121 return tr.getChild( 0 );
\r
126 function clearRow( $tr )
\r
128 // Get the array of row's cells.
\r
129 var $cells = $tr.cells;
\r
131 // Empty all cells.
\r
132 for ( var i = 0 ; i < $cells.length ; i++ )
\r
134 $cells[ i ].innerHTML = '';
\r
136 if ( !CKEDITOR.env.ie )
\r
137 ( new CKEDITOR.dom.element( $cells[ i ] ) ).appendBogus();
\r
141 function insertRow( selection, insertBefore )
\r
143 // Get the row where the selection is placed in.
\r
144 var row = selection.getStartElement().getAscendant( 'tr' );
\r
148 // Create a clone of the row.
\r
149 var newRow = row.clone( true );
\r
151 // Insert the new row before of it.
\r
152 newRow.insertBefore( row );
\r
154 // Clean one of the rows to produce the illusion of inserting an empty row
\r
155 // before or after.
\r
156 clearRow( insertBefore ? newRow.$ : row.$ );
\r
159 function deleteRows( selectionOrRow )
\r
161 if ( selectionOrRow instanceof CKEDITOR.dom.selection )
\r
163 var cells = getSelectedCells( selectionOrRow ),
\r
164 cellsCount = cells.length,
\r
170 // Queue up the rows - it's possible and likely that we have duplicates.
\r
171 for ( var i = 0 ; i < cellsCount ; i++ )
\r
173 var row = cells[ i ].getParent(),
\r
174 rowIndex = row.$.rowIndex;
\r
176 !i && ( previousRowIndex = rowIndex - 1 );
\r
177 rowsToDelete[ rowIndex ] = row;
\r
178 i == cellsCount - 1 && ( nextRowIndex = rowIndex + 1 );
\r
181 var table = row.getAscendant( 'table' ),
\r
182 rows = table.$.rows,
\r
183 rowCount = rows.length;
\r
185 // Where to put the cursor after rows been deleted?
\r
186 // 1. Into next sibling row if any;
\r
187 // 2. Into previous sibling row if any;
\r
188 // 3. Into table's parent element if it's the very last row.
\r
189 cursorPosition = new CKEDITOR.dom.element(
\r
190 nextRowIndex < rowCount && table.$.rows[ nextRowIndex ] ||
\r
191 previousRowIndex > 0 && table.$.rows[ previousRowIndex ] ||
\r
192 table.$.parentNode );
\r
194 for ( i = rowsToDelete.length ; i >= 0 ; i-- )
\r
196 if ( rowsToDelete[ i ] )
\r
197 deleteRows( rowsToDelete[ i ] );
\r
200 return cursorPosition;
\r
202 else if ( selectionOrRow instanceof CKEDITOR.dom.element )
\r
204 table = selectionOrRow.getAscendant( 'table' );
\r
206 if ( table.$.rows.length == 1 )
\r
209 selectionOrRow.remove();
\r
215 function insertColumn( selection, insertBefore )
\r
217 // Get the cell where the selection is placed in.
\r
218 var startElement = selection.getStartElement();
\r
219 var cell = startElement.getAscendant( 'td', true ) || startElement.getAscendant( 'th', true );
\r
224 // Get the cell's table.
\r
225 var table = cell.getAscendant( 'table' );
\r
226 var cellIndex = cell.$.cellIndex;
\r
228 // Loop through all rows available in the table.
\r
229 for ( var i = 0 ; i < table.$.rows.length ; i++ )
\r
231 var $row = table.$.rows[ i ];
\r
233 // If the row doesn't have enough cells, ignore it.
\r
234 if ( $row.cells.length < ( cellIndex + 1 ) )
\r
237 cell = new CKEDITOR.dom.element( $row.cells[ cellIndex ].cloneNode( false ) );
\r
239 if ( !CKEDITOR.env.ie )
\r
240 cell.appendBogus();
\r
242 // Get back the currently selected cell.
\r
243 var baseCell = new CKEDITOR.dom.element( $row.cells[ cellIndex ] );
\r
244 if ( insertBefore )
\r
245 cell.insertBefore( baseCell );
\r
247 cell.insertAfter( baseCell );
\r
251 function getFocusElementAfterDelCols( cells )
\r
253 var cellIndexList = [],
\r
254 table = cells[ 0 ] && cells[ 0 ].getAscendant( 'table' ),
\r
256 targetIndex, targetCell;
\r
258 // get the cellIndex list of delete cells
\r
259 for ( i = 0, length = cells.length; i < length; i++ )
\r
260 cellIndexList.push( cells[i].$.cellIndex );
\r
262 // get the focusable column index
\r
263 cellIndexList.sort();
\r
264 for ( i = 1, length = cellIndexList.length; i < length; i++ )
\r
266 if ( cellIndexList[ i ] - cellIndexList[ i - 1 ] > 1 )
\r
268 targetIndex = cellIndexList[ i - 1 ] + 1;
\r
273 if ( !targetIndex )
\r
274 targetIndex = cellIndexList[ 0 ] > 0 ? ( cellIndexList[ 0 ] - 1 )
\r
275 : ( cellIndexList[ cellIndexList.length - 1 ] + 1 );
\r
277 // scan row by row to get the target cell
\r
278 var rows = table.$.rows;
\r
279 for ( i = 0, length = rows.length; i < length ; i++ )
\r
281 targetCell = rows[ i ].cells[ targetIndex ];
\r
286 return targetCell ? new CKEDITOR.dom.element( targetCell ) : table.getPrevious();
\r
289 function deleteColumns( selectionOrCell )
\r
291 if ( selectionOrCell instanceof CKEDITOR.dom.selection )
\r
293 var colsToDelete = getSelectedCells( selectionOrCell ),
\r
294 elementToFocus = getFocusElementAfterDelCols( colsToDelete );
\r
296 for ( var i = colsToDelete.length - 1 ; i >= 0 ; i-- )
\r
298 if ( colsToDelete[ i ] )
\r
299 deleteColumns( colsToDelete[ i ] );
\r
302 return elementToFocus;
\r
304 else if ( selectionOrCell instanceof CKEDITOR.dom.element )
\r
306 // Get the cell's table.
\r
307 var table = selectionOrCell.getAscendant( 'table' );
\r
311 // Get the cell index.
\r
312 var cellIndex = selectionOrCell.$.cellIndex;
\r
315 * Loop through all rows from down to up, coz it's possible that some rows
\r
318 for ( i = table.$.rows.length - 1 ; i >= 0 ; i-- )
\r
321 var row = new CKEDITOR.dom.element( table.$.rows[ i ] );
\r
323 // If the cell to be removed is the first one and the row has just one cell.
\r
324 if ( !cellIndex && row.$.cells.length == 1 )
\r
330 // Else, just delete the cell.
\r
331 if ( row.$.cells[ cellIndex ] )
\r
332 row.$.removeChild( row.$.cells[ cellIndex ] );
\r
339 function insertCell( selection, insertBefore )
\r
341 var startElement = selection.getStartElement();
\r
342 var cell = startElement.getAscendant( 'td', true ) || startElement.getAscendant( 'th', true );
\r
347 // Create the new cell element to be added.
\r
348 var newCell = cell.clone();
\r
349 if ( !CKEDITOR.env.ie )
\r
350 newCell.appendBogus();
\r
352 if ( insertBefore )
\r
353 newCell.insertBefore( cell );
\r
355 newCell.insertAfter( cell );
\r
358 function deleteCells( selectionOrCell )
\r
360 if ( selectionOrCell instanceof CKEDITOR.dom.selection )
\r
362 var cellsToDelete = getSelectedCells( selectionOrCell );
\r
363 var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' );
\r
364 var cellToFocus = getFocusElementAfterDelCells( cellsToDelete );
\r
366 for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- )
\r
367 deleteCells( cellsToDelete[ i ] );
\r
370 placeCursorInCell( cellToFocus, true );
\r
374 else if ( selectionOrCell instanceof CKEDITOR.dom.element )
\r
376 var tr = selectionOrCell.getParent();
\r
377 if ( tr.getChildCount() == 1 )
\r
380 selectionOrCell.remove();
\r
384 // Remove filler at end and empty spaces around the cell content.
\r
385 function trimCell( cell )
\r
387 var bogus = cell.getBogus();
\r
388 bogus && bogus.remove();
\r
392 function placeCursorInCell( cell, placeAtEnd )
\r
394 var range = new CKEDITOR.dom.range( cell.getDocument() );
\r
395 if ( !range[ 'moveToElementEdit' + ( placeAtEnd ? 'End' : 'Start' ) ]( cell ) )
\r
397 range.selectNodeContents( cell );
\r
398 range.collapse( placeAtEnd ? false : true );
\r
400 range.select( true );
\r
403 function buildTableMap( table )
\r
406 var aRows = table.$.rows ;
\r
408 // Row and Column counters.
\r
413 for ( var i = 0 ; i < aRows.length ; i++ )
\r
416 !aMap[r] && ( aMap[r] = [] );
\r
420 for ( var j = 0 ; j < aRows[i].cells.length ; j++ )
\r
422 var oCell = aRows[i].cells[j] ;
\r
425 while ( aMap[r][c] )
\r
428 var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;
\r
429 var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;
\r
431 for ( var rs = 0 ; rs < iRowSpan ; rs++ )
\r
433 if ( !aMap[r + rs] )
\r
434 aMap[r + rs] = new Array() ;
\r
436 for ( var cs = 0 ; cs < iColSpan ; cs++ )
\r
438 aMap[r + rs][c + cs] = aRows[i].cells[j] ;
\r
442 c += iColSpan - 1 ;
\r
448 function cellInRow( tableMap, rowIndex, cell )
\r
450 var oRow = tableMap[ rowIndex ];
\r
451 if ( typeof cell == 'undefined' )
\r
454 for ( var c = 0 ; oRow && c < oRow.length ; c++ )
\r
456 if ( cell.is && oRow[c] == cell.$ )
\r
458 else if ( c == cell )
\r
459 return new CKEDITOR.dom.element( oRow[ c ] );
\r
461 return cell.is ? -1 : null;
\r
464 function cellInCol( tableMap, colIndex, cell )
\r
467 for ( var r = 0; r < tableMap.length; r++ )
\r
469 var row = tableMap[ r ];
\r
470 if ( typeof cell == 'undefined' )
\r
471 oCol.push( row[ colIndex ] );
\r
472 else if ( cell.is && row[ colIndex ] == cell.$ )
\r
474 else if ( r == cell )
\r
475 return new CKEDITOR.dom.element( row[ colIndex ] );
\r
478 return ( typeof cell == 'undefined' )? oCol : cell.is ? -1 : null;
\r
481 function mergeCells( selection, mergeDirection, isDetect )
\r
483 var cells = getSelectedCells( selection );
\r
485 // Invalid merge request if:
\r
486 // 1. In batch mode despite that less than two selected.
\r
487 // 2. In solo mode while not exactly only one selected.
\r
488 // 3. Cells distributed in different table groups (e.g. from both thead and tbody).
\r
489 var commonAncestor;
\r
490 if ( ( mergeDirection ? cells.length != 1 : cells.length < 2 )
\r
491 || ( commonAncestor = selection.getCommonAncestor() )
\r
492 && commonAncestor.type == CKEDITOR.NODE_ELEMENT
\r
493 && commonAncestor.is( 'table' ) )
\r
499 firstCell = cells[ 0 ],
\r
500 table = firstCell.getAscendant( 'table' ),
\r
501 map = buildTableMap( table ),
\r
502 mapHeight = map.length,
\r
503 mapWidth = map[ 0 ].length,
\r
504 startRow = firstCell.getParent().$.rowIndex,
\r
505 startColumn = cellInRow( map, startRow, firstCell );
\r
507 if ( mergeDirection )
\r
513 map[ mergeDirection == 'up' ?
\r
515 mergeDirection == 'down' ? ( startRow + 1 ) : startRow ] [
\r
516 mergeDirection == 'left' ?
\r
517 ( startColumn - 1 ):
\r
518 mergeDirection == 'right' ? ( startColumn + 1 ) : startColumn ];
\r
526 // 1. No cell could be merged.
\r
527 // 2. Same cell actually.
\r
528 if ( !targetCell || firstCell.$ == targetCell )
\r
531 // Sort in map order regardless of the DOM sequence.
\r
532 cells[ ( mergeDirection == 'up' || mergeDirection == 'left' ) ?
\r
533 'unshift' : 'push' ]( new CKEDITOR.dom.element( targetCell ) );
\r
536 // Start from here are merging way ignorance (merge up/right, batch merge).
\r
537 var doc = firstCell.getDocument(),
\r
538 lastRowIndex = startRow,
\r
541 // Use a documentFragment as buffer when appending cell contents.
\r
542 frag = !isDetect && new CKEDITOR.dom.documentFragment( doc ),
\r
545 for ( var i = 0; i < cells.length; i++ )
\r
549 var tr = cell.getParent(),
\r
550 cellFirstChild = cell.getFirst(),
\r
551 colSpan = cell.$.colSpan,
\r
552 rowSpan = cell.$.rowSpan,
\r
553 rowIndex = tr.$.rowIndex,
\r
554 colIndex = cellInRow( map, rowIndex, cell );
\r
556 // Accumulated the actual places taken by all selected cells.
\r
557 dimension += colSpan * rowSpan;
\r
558 // Accumulated the maximum virtual spans from column and row.
\r
559 totalColSpan = Math.max( totalColSpan, colIndex - startColumn + colSpan ) ;
\r
560 totalRowSpan = Math.max( totalRowSpan, rowIndex - startRow + rowSpan );
\r
564 // Trim all cell fillers and check to remove empty cells.
\r
565 if ( trimCell( cell ), cell.getChildren().count() )
\r
567 // Merge vertically cells as two separated paragraphs.
\r
568 if ( rowIndex != lastRowIndex
\r
570 && !( cellFirstChild.isBlockBoundary
\r
571 && cellFirstChild.isBlockBoundary( { br : 1 } ) ) )
\r
573 var last = frag.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
\r
574 if ( last && !( last.is && last.is( 'br' ) ) )
\r
575 frag.append( new CKEDITOR.dom.element( 'br' ) );
\r
578 cell.moveChildren( frag );
\r
580 i ? cell.remove() : cell.setHtml( '' );
\r
582 lastRowIndex = rowIndex;
\r
587 frag.moveChildren( firstCell );
\r
589 if ( !CKEDITOR.env.ie )
\r
590 firstCell.appendBogus();
\r
592 if ( totalColSpan >= mapWidth )
\r
593 firstCell.removeAttribute( 'rowSpan' );
\r
595 firstCell.$.rowSpan = totalRowSpan;
\r
597 if ( totalRowSpan >= mapHeight )
\r
598 firstCell.removeAttribute( 'colSpan' );
\r
600 firstCell.$.colSpan = totalColSpan;
\r
602 // Swip empty <tr> left at the end of table due to the merging.
\r
603 var trs = new CKEDITOR.dom.nodeList( table.$.rows ),
\r
604 count = trs.count();
\r
606 for ( i = count - 1; i >= 0; i-- )
\r
608 var tailTr = trs.getItem( i );
\r
609 if ( !tailTr.$.cells.length )
\r
619 // Be able to merge cells only if actual dimension of selected
\r
620 // cells equals to the caculated rectangle.
\r
622 return ( totalRowSpan * totalColSpan ) == dimension;
\r
625 function verticalSplitCell ( selection, isDetect )
\r
627 var cells = getSelectedCells( selection );
\r
628 if ( cells.length > 1 )
\r
630 else if ( isDetect )
\r
633 var cell = cells[ 0 ],
\r
634 tr = cell.getParent(),
\r
635 table = tr.getAscendant( 'table' ),
\r
636 map = buildTableMap( table ),
\r
637 rowIndex = tr.$.rowIndex,
\r
638 colIndex = cellInRow( map, rowIndex, cell ),
\r
639 rowSpan = cell.$.rowSpan,
\r
647 newRowSpan = Math.ceil( rowSpan / 2 );
\r
648 newCellRowSpan = Math.floor( rowSpan / 2 );
\r
649 newRowIndex = rowIndex + newRowSpan;
\r
650 var newCellTr = new CKEDITOR.dom.element( table.$.rows[ newRowIndex ] ),
\r
651 newCellRow = cellInRow( map, newRowIndex ),
\r
654 newCell = cell.clone();
\r
656 // Figure out where to insert the new cell by checking the vitual row.
\r
657 for ( var c = 0; c < newCellRow.length; c++ )
\r
659 candidateCell = newCellRow[ c ];
\r
660 // Catch first cell actually following the column.
\r
661 if ( candidateCell.parentNode == newCellTr.$
\r
664 newCell.insertBefore( new CKEDITOR.dom.element( candidateCell ) );
\r
668 candidateCell = null;
\r
671 // The destination row is empty, append at will.
\r
672 if ( !candidateCell )
\r
673 newCellTr.append( newCell, true );
\r
677 newCellRowSpan = newRowSpan = 1;
\r
679 newCellTr = tr.clone();
\r
680 newCellTr.insertAfter( tr );
\r
681 newCellTr.append( newCell = cell.clone() );
\r
683 var cellsInSameRow = cellInRow( map, rowIndex );
\r
684 for ( var i = 0; i < cellsInSameRow.length; i++ )
\r
685 cellsInSameRow[ i ].rowSpan++;
\r
688 if ( !CKEDITOR.env.ie )
\r
689 newCell.appendBogus();
\r
691 cell.$.rowSpan = newRowSpan;
\r
692 newCell.$.rowSpan = newCellRowSpan;
\r
693 if ( newRowSpan == 1 )
\r
694 cell.removeAttribute( 'rowSpan' );
\r
695 if ( newCellRowSpan == 1 )
\r
696 newCell.removeAttribute( 'rowSpan' );
\r
701 function horizontalSplitCell( selection, isDetect )
\r
703 var cells = getSelectedCells( selection );
\r
704 if ( cells.length > 1 )
\r
706 else if ( isDetect )
\r
709 var cell = cells[ 0 ],
\r
710 tr = cell.getParent(),
\r
711 table = tr.getAscendant( 'table' ),
\r
712 map = buildTableMap( table ),
\r
713 rowIndex = tr.$.rowIndex,
\r
714 colIndex = cellInRow( map, rowIndex, cell ),
\r
715 colSpan = cell.$.colSpan,
\r
722 newColSpan = Math.ceil( colSpan / 2 );
\r
723 newCellColSpan = Math.floor( colSpan / 2 );
\r
727 newCellColSpan = newColSpan = 1;
\r
728 var cellsInSameCol = cellInCol( map, colIndex );
\r
729 for ( var i = 0; i < cellsInSameCol.length; i++ )
\r
730 cellsInSameCol[ i ].colSpan++;
\r
732 newCell = cell.clone();
\r
733 newCell.insertAfter( cell );
\r
734 if ( !CKEDITOR.env.ie )
\r
735 newCell.appendBogus();
\r
737 cell.$.colSpan = newColSpan;
\r
738 newCell.$.colSpan = newCellColSpan;
\r
739 if ( newColSpan == 1 )
\r
740 cell.removeAttribute( 'colSpan' );
\r
741 if ( newCellColSpan == 1 )
\r
742 newCell.removeAttribute( 'colSpan' );
\r
746 // Context menu on table caption incorrect (#3834)
\r
747 var contextMenuTags = { thead : 1, tbody : 1, tfoot : 1, td : 1, tr : 1, th : 1 };
\r
749 CKEDITOR.plugins.tabletools =
\r
751 init : function( editor )
\r
753 var lang = editor.lang.table;
\r
755 editor.addCommand( 'cellProperties', new CKEDITOR.dialogCommand( 'cellProperties' ) );
\r
756 CKEDITOR.dialog.add( 'cellProperties', this.path + 'dialogs/tableCell.js' );
\r
758 editor.addCommand( 'tableDelete',
\r
760 exec : function( editor )
\r
762 var selection = editor.getSelection();
\r
763 var startElement = selection && selection.getStartElement();
\r
764 var table = startElement && startElement.getAscendant( 'table', true );
\r
769 // Maintain the selection point at where the table was deleted.
\r
770 selection.selectElement( table );
\r
771 var range = selection.getRanges()[0];
\r
773 selection.selectRanges( [ range ] );
\r
775 // If the table's parent has only one child, remove it,except body,as well.( #5416 )
\r
776 var parent = table.getParent();
\r
777 if ( parent.getChildCount() == 1 && parent.getName() != 'body' )
\r
784 editor.addCommand( 'rowDelete',
\r
786 exec : function( editor )
\r
788 var selection = editor.getSelection();
\r
789 placeCursorInCell( deleteRows( selection ) );
\r
793 editor.addCommand( 'rowInsertBefore',
\r
795 exec : function( editor )
\r
797 var selection = editor.getSelection();
\r
798 insertRow( selection, true );
\r
802 editor.addCommand( 'rowInsertAfter',
\r
804 exec : function( editor )
\r
806 var selection = editor.getSelection();
\r
807 insertRow( selection );
\r
811 editor.addCommand( 'columnDelete',
\r
813 exec : function( editor )
\r
815 var selection = editor.getSelection();
\r
816 var element = deleteColumns( selection );
\r
817 element && placeCursorInCell( element, true );
\r
821 editor.addCommand( 'columnInsertBefore',
\r
823 exec : function( editor )
\r
825 var selection = editor.getSelection();
\r
826 insertColumn( selection, true );
\r
830 editor.addCommand( 'columnInsertAfter',
\r
832 exec : function( editor )
\r
834 var selection = editor.getSelection();
\r
835 insertColumn( selection );
\r
839 editor.addCommand( 'cellDelete',
\r
841 exec : function( editor )
\r
843 var selection = editor.getSelection();
\r
844 deleteCells( selection );
\r
848 editor.addCommand( 'cellMerge',
\r
850 exec : function( editor )
\r
852 placeCursorInCell( mergeCells( editor.getSelection() ), true );
\r
856 editor.addCommand( 'cellMergeRight',
\r
858 exec : function( editor )
\r
860 placeCursorInCell( mergeCells( editor.getSelection(), 'right' ), true );
\r
864 editor.addCommand( 'cellMergeDown',
\r
866 exec : function( editor )
\r
868 placeCursorInCell( mergeCells( editor.getSelection(), 'down' ), true );
\r
872 editor.addCommand( 'cellVerticalSplit',
\r
874 exec : function( editor )
\r
876 placeCursorInCell( verticalSplitCell( editor.getSelection() ) );
\r
880 editor.addCommand( 'cellHorizontalSplit',
\r
882 exec : function( editor )
\r
884 placeCursorInCell( horizontalSplitCell( editor.getSelection() ) );
\r
888 editor.addCommand( 'cellInsertBefore',
\r
890 exec : function( editor )
\r
892 var selection = editor.getSelection();
\r
893 insertCell( selection, true );
\r
897 editor.addCommand( 'cellInsertAfter',
\r
899 exec : function( editor )
\r
901 var selection = editor.getSelection();
\r
902 insertCell( selection );
\r
906 // If the "menu" plugin is loaded, register the menu items.
\r
907 if ( editor.addMenuItems )
\r
909 editor.addMenuItems(
\r
913 label : lang.cell.menu,
\r
914 group : 'tablecell',
\r
916 getItems : function()
\r
918 var selection = editor.getSelection(),
\r
919 cells = getSelectedCells( selection );
\r
921 tablecell_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
922 tablecell_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
923 tablecell_delete : CKEDITOR.TRISTATE_OFF,
\r
924 tablecell_merge : mergeCells( selection, null, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
925 tablecell_merge_right : mergeCells( selection, 'right', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
926 tablecell_merge_down : mergeCells( selection, 'down', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
927 tablecell_split_vertical : verticalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
928 tablecell_split_horizontal : horizontalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
929 tablecell_properties : cells.length > 0 ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
\r
934 tablecell_insertBefore :
\r
936 label : lang.cell.insertBefore,
\r
937 group : 'tablecell',
\r
938 command : 'cellInsertBefore',
\r
942 tablecell_insertAfter :
\r
944 label : lang.cell.insertAfter,
\r
945 group : 'tablecell',
\r
946 command : 'cellInsertAfter',
\r
952 label : lang.cell.deleteCell,
\r
953 group : 'tablecell',
\r
954 command : 'cellDelete',
\r
960 label : lang.cell.merge,
\r
961 group : 'tablecell',
\r
962 command : 'cellMerge',
\r
966 tablecell_merge_right :
\r
968 label : lang.cell.mergeRight,
\r
969 group : 'tablecell',
\r
970 command : 'cellMergeRight',
\r
974 tablecell_merge_down :
\r
976 label : lang.cell.mergeDown,
\r
977 group : 'tablecell',
\r
978 command : 'cellMergeDown',
\r
982 tablecell_split_horizontal :
\r
984 label : lang.cell.splitHorizontal,
\r
985 group : 'tablecell',
\r
986 command : 'cellHorizontalSplit',
\r
990 tablecell_split_vertical :
\r
992 label : lang.cell.splitVertical,
\r
993 group : 'tablecell',
\r
994 command : 'cellVerticalSplit',
\r
998 tablecell_properties :
\r
1000 label : lang.cell.title,
\r
1001 group : 'tablecellproperties',
\r
1002 command : 'cellProperties',
\r
1008 label : lang.row.menu,
\r
1009 group : 'tablerow',
\r
1011 getItems : function()
\r
1014 tablerow_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
1015 tablerow_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
1016 tablerow_delete : CKEDITOR.TRISTATE_OFF
\r
1021 tablerow_insertBefore :
\r
1023 label : lang.row.insertBefore,
\r
1024 group : 'tablerow',
\r
1025 command : 'rowInsertBefore',
\r
1029 tablerow_insertAfter :
\r
1031 label : lang.row.insertAfter,
\r
1032 group : 'tablerow',
\r
1033 command : 'rowInsertAfter',
\r
1039 label : lang.row.deleteRow,
\r
1040 group : 'tablerow',
\r
1041 command : 'rowDelete',
\r
1047 label : lang.column.menu,
\r
1048 group : 'tablecolumn',
\r
1050 getItems : function()
\r
1053 tablecolumn_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
1054 tablecolumn_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
1055 tablecolumn_delete : CKEDITOR.TRISTATE_OFF
\r
1060 tablecolumn_insertBefore :
\r
1062 label : lang.column.insertBefore,
\r
1063 group : 'tablecolumn',
\r
1064 command : 'columnInsertBefore',
\r
1068 tablecolumn_insertAfter :
\r
1070 label : lang.column.insertAfter,
\r
1071 group : 'tablecolumn',
\r
1072 command : 'columnInsertAfter',
\r
1076 tablecolumn_delete :
\r
1078 label : lang.column.deleteColumn,
\r
1079 group : 'tablecolumn',
\r
1080 command : 'columnDelete',
\r
1086 // If the "contextmenu" plugin is laoded, register the listeners.
\r
1087 if ( editor.contextMenu )
\r
1089 editor.contextMenu.addListener( function( element, selection )
\r
1096 if ( element.getName() in contextMenuTags )
\r
1099 tablecell : CKEDITOR.TRISTATE_OFF,
\r
1100 tablerow : CKEDITOR.TRISTATE_OFF,
\r
1101 tablecolumn : CKEDITOR.TRISTATE_OFF
\r
1104 element = element.getParent();
\r
1112 getSelectedCells : getSelectedCells
\r
1115 CKEDITOR.plugins.add( 'tabletools', CKEDITOR.plugins.tabletools );
\r