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 getFocusedCell( 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 deleteColumns( selectionOrCell )
\r
253 if ( selectionOrCell instanceof CKEDITOR.dom.selection )
\r
255 var colsToDelete = getSelectedCells( selectionOrCell );
\r
256 for ( var i = colsToDelete.length ; i >= 0 ; i-- )
\r
258 if ( colsToDelete[ i ] )
\r
259 deleteColumns( colsToDelete[ i ] );
\r
262 else if ( selectionOrCell instanceof CKEDITOR.dom.element )
\r
264 // Get the cell's table.
\r
265 var table = selectionOrCell.getAscendant( 'table' );
\r
267 // Get the cell index.
\r
268 var cellIndex = selectionOrCell.$.cellIndex;
\r
271 * Loop through all rows from down to up, coz it's possible that some rows
\r
274 for ( i = table.$.rows.length - 1 ; i >= 0 ; i-- )
\r
277 var row = new CKEDITOR.dom.element( table.$.rows[ i ] );
\r
279 // If the cell to be removed is the first one and the row has just one cell.
\r
280 if ( !cellIndex && row.$.cells.length == 1 )
\r
286 // Else, just delete the cell.
\r
287 if ( row.$.cells[ cellIndex ] )
\r
288 row.$.removeChild( row.$.cells[ cellIndex ] );
\r
293 function insertCell( selection, insertBefore )
\r
295 var startElement = selection.getStartElement();
\r
296 var cell = startElement.getAscendant( 'td', true ) || startElement.getAscendant( 'th', true );
\r
301 // Create the new cell element to be added.
\r
302 var newCell = cell.clone();
\r
303 if ( !CKEDITOR.env.ie )
\r
304 newCell.appendBogus();
\r
306 if ( insertBefore )
\r
307 newCell.insertBefore( cell );
\r
309 newCell.insertAfter( cell );
\r
312 function deleteCells( selectionOrCell )
\r
314 if ( selectionOrCell instanceof CKEDITOR.dom.selection )
\r
316 var cellsToDelete = getSelectedCells( selectionOrCell );
\r
317 var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' );
\r
318 var cellToFocus = getFocusedCell( cellsToDelete );
\r
320 for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- )
\r
321 deleteCells( cellsToDelete[ i ] );
\r
324 placeCursorInCell( cellToFocus, true );
\r
328 else if ( selectionOrCell instanceof CKEDITOR.dom.element )
\r
330 var tr = selectionOrCell.getParent();
\r
331 if ( tr.getChildCount() == 1 )
\r
334 selectionOrCell.remove();
\r
338 // Remove filler at end and empty spaces around the cell content.
\r
339 function trimCell( cell )
\r
341 var bogus = cell.getBogus();
\r
342 bogus && bogus.remove();
\r
346 function placeCursorInCell( cell, placeAtEnd )
\r
348 var range = new CKEDITOR.dom.range( cell.getDocument() );
\r
349 if ( !range[ 'moveToElementEdit' + ( placeAtEnd ? 'End' : 'Start' ) ]( cell ) )
\r
351 range.selectNodeContents( cell );
\r
352 range.collapse( placeAtEnd ? false : true );
\r
354 range.select( true );
\r
357 function buildTableMap( table )
\r
360 var aRows = table.$.rows ;
\r
362 // Row and Column counters.
\r
367 for ( var i = 0 ; i < aRows.length ; i++ )
\r
370 !aMap[r] && ( aMap[r] = [] );
\r
374 for ( var j = 0 ; j < aRows[i].cells.length ; j++ )
\r
376 var oCell = aRows[i].cells[j] ;
\r
379 while ( aMap[r][c] )
\r
382 var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;
\r
383 var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;
\r
385 for ( var rs = 0 ; rs < iRowSpan ; rs++ )
\r
387 if ( !aMap[r + rs] )
\r
388 aMap[r + rs] = new Array() ;
\r
390 for ( var cs = 0 ; cs < iColSpan ; cs++ )
\r
392 aMap[r + rs][c + cs] = aRows[i].cells[j] ;
\r
396 c += iColSpan - 1 ;
\r
402 function cellInRow( tableMap, rowIndex, cell )
\r
404 var oRow = tableMap[ rowIndex ];
\r
405 if ( typeof cell == 'undefined' )
\r
408 for ( var c = 0 ; oRow && c < oRow.length ; c++ )
\r
410 if ( cell.is && oRow[c] == cell.$ )
\r
412 else if ( c == cell )
\r
413 return new CKEDITOR.dom.element( oRow[ c ] );
\r
415 return cell.is ? -1 : null;
\r
418 function cellInCol( tableMap, colIndex, cell )
\r
421 for ( var r = 0; r < tableMap.length; r++ )
\r
423 var row = tableMap[ r ];
\r
424 if ( typeof cell == 'undefined' )
\r
425 oCol.push( row[ colIndex ] );
\r
426 else if ( cell.is && row[ colIndex ] == cell.$ )
\r
428 else if ( r == cell )
\r
429 return new CKEDITOR.dom.element( row[ colIndex ] );
\r
432 return ( typeof cell == 'undefined' )? oCol : cell.is ? -1 : null;
\r
435 function mergeCells( selection, mergeDirection, isDetect )
\r
437 var cells = getSelectedCells( selection );
\r
439 // Invalid merge request if:
\r
440 // 1. In batch mode despite that less than two selected.
\r
441 // 2. In solo mode while not exactly only one selected.
\r
442 // 3. Cells distributed in different table groups (e.g. from both thead and tbody).
\r
443 var commonAncestor;
\r
444 if ( ( mergeDirection ? cells.length != 1 : cells.length < 2 )
\r
445 || ( commonAncestor = selection.getCommonAncestor() )
\r
446 && commonAncestor.type == CKEDITOR.NODE_ELEMENT
\r
447 && commonAncestor.is( 'table' ) )
\r
453 firstCell = cells[ 0 ],
\r
454 table = firstCell.getAscendant( 'table' ),
\r
455 map = buildTableMap( table ),
\r
456 mapHeight = map.length,
\r
457 mapWidth = map[ 0 ].length,
\r
458 startRow = firstCell.getParent().$.rowIndex,
\r
459 startColumn = cellInRow( map, startRow, firstCell );
\r
461 if ( mergeDirection )
\r
467 map[ mergeDirection == 'up' ?
\r
469 mergeDirection == 'down' ? ( startRow + 1 ) : startRow ] [
\r
470 mergeDirection == 'left' ?
\r
471 ( startColumn - 1 ):
\r
472 mergeDirection == 'right' ? ( startColumn + 1 ) : startColumn ];
\r
480 // 1. No cell could be merged.
\r
481 // 2. Same cell actually.
\r
482 if ( !targetCell || firstCell.$ == targetCell )
\r
485 // Sort in map order regardless of the DOM sequence.
\r
486 cells[ ( mergeDirection == 'up' || mergeDirection == 'left' ) ?
\r
487 'unshift' : 'push' ]( new CKEDITOR.dom.element( targetCell ) );
\r
490 // Start from here are merging way ignorance (merge up/right, batch merge).
\r
491 var doc = firstCell.getDocument(),
\r
492 lastRowIndex = startRow,
\r
495 // Use a documentFragment as buffer when appending cell contents.
\r
496 frag = !isDetect && new CKEDITOR.dom.documentFragment( doc ),
\r
499 for ( var i = 0; i < cells.length; i++ )
\r
503 var tr = cell.getParent(),
\r
504 cellFirstChild = cell.getFirst(),
\r
505 colSpan = cell.$.colSpan,
\r
506 rowSpan = cell.$.rowSpan,
\r
507 rowIndex = tr.$.rowIndex,
\r
508 colIndex = cellInRow( map, rowIndex, cell );
\r
510 // Accumulated the actual places taken by all selected cells.
\r
511 dimension += colSpan * rowSpan;
\r
512 // Accumulated the maximum virtual spans from column and row.
\r
513 totalColSpan = Math.max( totalColSpan, colIndex - startColumn + colSpan ) ;
\r
514 totalRowSpan = Math.max( totalRowSpan, rowIndex - startRow + rowSpan );
\r
518 // Trim all cell fillers and check to remove empty cells.
\r
519 if ( trimCell( cell ), cell.getChildren().count() )
\r
521 // Merge vertically cells as two separated paragraphs.
\r
522 if ( rowIndex != lastRowIndex
\r
524 && !( cellFirstChild.isBlockBoundary
\r
525 && cellFirstChild.isBlockBoundary( { br : 1 } ) ) )
\r
527 var last = frag.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
\r
528 if ( last && !( last.is && last.is( 'br' ) ) )
\r
529 frag.append( new CKEDITOR.dom.element( 'br' ) );
\r
532 cell.moveChildren( frag );
\r
534 i ? cell.remove() : cell.setHtml( '' );
\r
536 lastRowIndex = rowIndex;
\r
541 frag.moveChildren( firstCell );
\r
543 if ( !CKEDITOR.env.ie )
\r
544 firstCell.appendBogus();
\r
546 if ( totalColSpan >= mapWidth )
\r
547 firstCell.removeAttribute( 'rowSpan' );
\r
549 firstCell.$.rowSpan = totalRowSpan;
\r
551 if ( totalRowSpan >= mapHeight )
\r
552 firstCell.removeAttribute( 'colSpan' );
\r
554 firstCell.$.colSpan = totalColSpan;
\r
556 // Swip empty <tr> left at the end of table due to the merging.
\r
557 var trs = new CKEDITOR.dom.nodeList( table.$.rows ),
\r
558 count = trs.count();
\r
560 for ( i = count - 1; i >= 0; i-- )
\r
562 var tailTr = trs.getItem( i );
\r
563 if ( !tailTr.$.cells.length )
\r
573 // Be able to merge cells only if actual dimension of selected
\r
574 // cells equals to the caculated rectangle.
\r
576 return ( totalRowSpan * totalColSpan ) == dimension;
\r
579 function verticalSplitCell ( selection, isDetect )
\r
581 var cells = getSelectedCells( selection );
\r
582 if ( cells.length > 1 )
\r
584 else if ( isDetect )
\r
587 var cell = cells[ 0 ],
\r
588 tr = cell.getParent(),
\r
589 table = tr.getAscendant( 'table' ),
\r
590 map = buildTableMap( table ),
\r
591 rowIndex = tr.$.rowIndex,
\r
592 colIndex = cellInRow( map, rowIndex, cell ),
\r
593 rowSpan = cell.$.rowSpan,
\r
601 newRowSpan = Math.ceil( rowSpan / 2 );
\r
602 newCellRowSpan = Math.floor( rowSpan / 2 );
\r
603 newRowIndex = rowIndex + newRowSpan;
\r
604 var newCellTr = new CKEDITOR.dom.element( table.$.rows[ newRowIndex ] ),
\r
605 newCellRow = cellInRow( map, newRowIndex ),
\r
608 newCell = cell.clone();
\r
610 // Figure out where to insert the new cell by checking the vitual row.
\r
611 for ( var c = 0; c < newCellRow.length; c++ )
\r
613 candidateCell = newCellRow[ c ];
\r
614 // Catch first cell actually following the column.
\r
615 if ( candidateCell.parentNode == newCellTr.$
\r
618 newCell.insertBefore( new CKEDITOR.dom.element( candidateCell ) );
\r
622 candidateCell = null;
\r
625 // The destination row is empty, append at will.
\r
626 if ( !candidateCell )
\r
627 newCellTr.append( newCell, true );
\r
631 newCellRowSpan = newRowSpan = 1;
\r
633 newCellTr = tr.clone();
\r
634 newCellTr.insertAfter( tr );
\r
635 newCellTr.append( newCell = cell.clone() );
\r
637 var cellsInSameRow = cellInRow( map, rowIndex );
\r
638 for ( var i = 0; i < cellsInSameRow.length; i++ )
\r
639 cellsInSameRow[ i ].rowSpan++;
\r
642 if ( !CKEDITOR.env.ie )
\r
643 newCell.appendBogus();
\r
645 cell.$.rowSpan = newRowSpan;
\r
646 newCell.$.rowSpan = newCellRowSpan;
\r
647 if ( newRowSpan == 1 )
\r
648 cell.removeAttribute( 'rowSpan' );
\r
649 if ( newCellRowSpan == 1 )
\r
650 newCell.removeAttribute( 'rowSpan' );
\r
655 function horizontalSplitCell( selection, isDetect )
\r
657 var cells = getSelectedCells( selection );
\r
658 if ( cells.length > 1 )
\r
660 else if ( isDetect )
\r
663 var cell = cells[ 0 ],
\r
664 tr = cell.getParent(),
\r
665 table = tr.getAscendant( 'table' ),
\r
666 map = buildTableMap( table ),
\r
667 rowIndex = tr.$.rowIndex,
\r
668 colIndex = cellInRow( map, rowIndex, cell ),
\r
669 colSpan = cell.$.colSpan,
\r
676 newColSpan = Math.ceil( colSpan / 2 );
\r
677 newCellColSpan = Math.floor( colSpan / 2 );
\r
681 newCellColSpan = newColSpan = 1;
\r
682 var cellsInSameCol = cellInCol( map, colIndex );
\r
683 for ( var i = 0; i < cellsInSameCol.length; i++ )
\r
684 cellsInSameCol[ i ].colSpan++;
\r
686 newCell = cell.clone();
\r
687 newCell.insertAfter( cell );
\r
688 if ( !CKEDITOR.env.ie )
\r
689 newCell.appendBogus();
\r
691 cell.$.colSpan = newColSpan;
\r
692 newCell.$.colSpan = newCellColSpan;
\r
693 if ( newColSpan == 1 )
\r
694 cell.removeAttribute( 'colSpan' );
\r
695 if ( newCellColSpan == 1 )
\r
696 newCell.removeAttribute( 'colSpan' );
\r
700 // Context menu on table caption incorrect (#3834)
\r
701 var contextMenuTags = { thead : 1, tbody : 1, tfoot : 1, td : 1, tr : 1, th : 1 };
\r
703 CKEDITOR.plugins.tabletools =
\r
705 init : function( editor )
\r
707 var lang = editor.lang.table;
\r
709 editor.addCommand( 'cellProperties', new CKEDITOR.dialogCommand( 'cellProperties' ) );
\r
710 CKEDITOR.dialog.add( 'cellProperties', this.path + 'dialogs/tableCell.js' );
\r
712 editor.addCommand( 'tableDelete',
\r
714 exec : function( editor )
\r
716 var selection = editor.getSelection();
\r
717 var startElement = selection && selection.getStartElement();
\r
718 var table = startElement && startElement.getAscendant( 'table', true );
\r
723 // Maintain the selection point at where the table was deleted.
\r
724 selection.selectElement( table );
\r
725 var range = selection.getRanges()[0];
\r
727 selection.selectRanges( [ range ] );
\r
729 // If the table's parent has only one child, remove it as well.
\r
730 if ( table.getParent().getChildCount() == 1 )
\r
731 table.getParent().remove();
\r
737 editor.addCommand( 'rowDelete',
\r
739 exec : function( editor )
\r
741 var selection = editor.getSelection();
\r
742 placeCursorInCell( deleteRows( selection ) );
\r
746 editor.addCommand( 'rowInsertBefore',
\r
748 exec : function( editor )
\r
750 var selection = editor.getSelection();
\r
751 insertRow( selection, true );
\r
755 editor.addCommand( 'rowInsertAfter',
\r
757 exec : function( editor )
\r
759 var selection = editor.getSelection();
\r
760 insertRow( selection );
\r
764 editor.addCommand( 'columnDelete',
\r
766 exec : function( editor )
\r
768 var selection = editor.getSelection();
\r
769 deleteColumns( selection );
\r
773 editor.addCommand( 'columnInsertBefore',
\r
775 exec : function( editor )
\r
777 var selection = editor.getSelection();
\r
778 insertColumn( selection, true );
\r
782 editor.addCommand( 'columnInsertAfter',
\r
784 exec : function( editor )
\r
786 var selection = editor.getSelection();
\r
787 insertColumn( selection );
\r
791 editor.addCommand( 'cellDelete',
\r
793 exec : function( editor )
\r
795 var selection = editor.getSelection();
\r
796 deleteCells( selection );
\r
800 editor.addCommand( 'cellMerge',
\r
802 exec : function( editor )
\r
804 placeCursorInCell( mergeCells( editor.getSelection() ), true );
\r
808 editor.addCommand( 'cellMergeRight',
\r
810 exec : function( editor )
\r
812 placeCursorInCell( mergeCells( editor.getSelection(), 'right' ), true );
\r
816 editor.addCommand( 'cellMergeDown',
\r
818 exec : function( editor )
\r
820 placeCursorInCell( mergeCells( editor.getSelection(), 'down' ), true );
\r
824 editor.addCommand( 'cellVerticalSplit',
\r
826 exec : function( editor )
\r
828 placeCursorInCell( verticalSplitCell( editor.getSelection() ) );
\r
832 editor.addCommand( 'cellHorizontalSplit',
\r
834 exec : function( editor )
\r
836 placeCursorInCell( horizontalSplitCell( editor.getSelection() ) );
\r
840 editor.addCommand( 'cellInsertBefore',
\r
842 exec : function( editor )
\r
844 var selection = editor.getSelection();
\r
845 insertCell( selection, true );
\r
849 editor.addCommand( 'cellInsertAfter',
\r
851 exec : function( editor )
\r
853 var selection = editor.getSelection();
\r
854 insertCell( selection );
\r
858 // If the "menu" plugin is loaded, register the menu items.
\r
859 if ( editor.addMenuItems )
\r
861 editor.addMenuItems(
\r
865 label : lang.cell.menu,
\r
866 group : 'tablecell',
\r
868 getItems : function()
\r
870 var selection = editor.getSelection(),
\r
871 cells = getSelectedCells( selection );
\r
873 tablecell_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
874 tablecell_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
875 tablecell_delete : CKEDITOR.TRISTATE_OFF,
\r
876 tablecell_merge : mergeCells( selection, null, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
877 tablecell_merge_right : mergeCells( selection, 'right', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
878 tablecell_merge_down : mergeCells( selection, 'down', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
879 tablecell_split_vertical : verticalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
880 tablecell_split_horizontal : horizontalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
\r
881 tablecell_properties : cells.length > 0 ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
\r
886 tablecell_insertBefore :
\r
888 label : lang.cell.insertBefore,
\r
889 group : 'tablecell',
\r
890 command : 'cellInsertBefore',
\r
894 tablecell_insertAfter :
\r
896 label : lang.cell.insertAfter,
\r
897 group : 'tablecell',
\r
898 command : 'cellInsertAfter',
\r
904 label : lang.cell.deleteCell,
\r
905 group : 'tablecell',
\r
906 command : 'cellDelete',
\r
912 label : lang.cell.merge,
\r
913 group : 'tablecell',
\r
914 command : 'cellMerge',
\r
918 tablecell_merge_right :
\r
920 label : lang.cell.mergeRight,
\r
921 group : 'tablecell',
\r
922 command : 'cellMergeRight',
\r
926 tablecell_merge_down :
\r
928 label : lang.cell.mergeDown,
\r
929 group : 'tablecell',
\r
930 command : 'cellMergeDown',
\r
934 tablecell_split_horizontal :
\r
936 label : lang.cell.splitHorizontal,
\r
937 group : 'tablecell',
\r
938 command : 'cellHorizontalSplit',
\r
942 tablecell_split_vertical :
\r
944 label : lang.cell.splitVertical,
\r
945 group : 'tablecell',
\r
946 command : 'cellVerticalSplit',
\r
950 tablecell_properties :
\r
952 label : lang.cell.title,
\r
953 group : 'tablecellproperties',
\r
954 command : 'cellProperties',
\r
960 label : lang.row.menu,
\r
961 group : 'tablerow',
\r
963 getItems : function()
\r
966 tablerow_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
967 tablerow_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
968 tablerow_delete : CKEDITOR.TRISTATE_OFF
\r
973 tablerow_insertBefore :
\r
975 label : lang.row.insertBefore,
\r
976 group : 'tablerow',
\r
977 command : 'rowInsertBefore',
\r
981 tablerow_insertAfter :
\r
983 label : lang.row.insertAfter,
\r
984 group : 'tablerow',
\r
985 command : 'rowInsertAfter',
\r
991 label : lang.row.deleteRow,
\r
992 group : 'tablerow',
\r
993 command : 'rowDelete',
\r
999 label : lang.column.menu,
\r
1000 group : 'tablecolumn',
\r
1002 getItems : function()
\r
1005 tablecolumn_insertBefore : CKEDITOR.TRISTATE_OFF,
\r
1006 tablecolumn_insertAfter : CKEDITOR.TRISTATE_OFF,
\r
1007 tablecolumn_delete : CKEDITOR.TRISTATE_OFF
\r
1012 tablecolumn_insertBefore :
\r
1014 label : lang.column.insertBefore,
\r
1015 group : 'tablecolumn',
\r
1016 command : 'columnInsertBefore',
\r
1020 tablecolumn_insertAfter :
\r
1022 label : lang.column.insertAfter,
\r
1023 group : 'tablecolumn',
\r
1024 command : 'columnInsertAfter',
\r
1028 tablecolumn_delete :
\r
1030 label : lang.column.deleteColumn,
\r
1031 group : 'tablecolumn',
\r
1032 command : 'columnDelete',
\r
1038 // If the "contextmenu" plugin is laoded, register the listeners.
\r
1039 if ( editor.contextMenu )
\r
1041 editor.contextMenu.addListener( function( element, selection )
\r
1048 if ( element.getName() in contextMenuTags )
\r
1051 tablecell : CKEDITOR.TRISTATE_OFF,
\r
1052 tablerow : CKEDITOR.TRISTATE_OFF,
\r
1053 tablecolumn : CKEDITOR.TRISTATE_OFF
\r
1056 element = element.getParent();
\r
1064 getSelectedCells : getSelectedCells
\r
1067 CKEDITOR.plugins.add( 'tabletools', CKEDITOR.plugins.tabletools );
\r