X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ftabletools%2Fplugin.js;h=b06f59a50bb24696386a277c0e5c69011bad5355;hb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7;hp=1f2224cffb479a54d9bb226e9f4cb1a5f4030434;hpb=8665a7c6c60586526e32e8941fe2896739b6ebfb;p=ckeditor.git diff --git a/_source/plugins/tabletools/plugin.js b/_source/plugins/tabletools/plugin.js index 1f2224c..b06f59a 100644 --- a/_source/plugins/tabletools/plugin.js +++ b/_source/plugins/tabletools/plugin.js @@ -148,12 +148,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Create a clone of the row. var newRow = row.clone( true ); - // Insert the new row before of it. - newRow.insertBefore( row ); + insertBefore ? + newRow.insertBefore( row ) : + newRow.insertAfter( row ); - // Clean one of the rows to produce the illusion of inserting an empty row - // before or after. - clearRow( insertBefore ? newRow.$ : row.$ ); + // Clean the new row. + clearRow( newRow.$ ); } function deleteRows( selectionOrRow ) @@ -234,7 +234,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( $row.cells.length < ( cellIndex + 1 ) ) continue; - cell = new CKEDITOR.dom.element( $row.cells[ cellIndex ].cloneNode( false ) ); + cell = ( new CKEDITOR.dom.element( $row.cells[ cellIndex ] ) ).clone( false ); if ( !CKEDITOR.env.ie ) cell.appendBogus(); @@ -400,51 +400,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range.select( true ); } - function buildTableMap( table ) - { - - var aRows = table.$.rows ; - - // Row and Column counters. - var r = -1 ; - - var aMap = []; - - for ( var i = 0 ; i < aRows.length ; i++ ) - { - r++ ; - !aMap[r] && ( aMap[r] = [] ); - - var c = -1 ; - - for ( var j = 0 ; j < aRows[i].cells.length ; j++ ) - { - var oCell = aRows[i].cells[j] ; - - c++ ; - while ( aMap[r][c] ) - c++ ; - - var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ; - var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ; - - for ( var rs = 0 ; rs < iRowSpan ; rs++ ) - { - if ( !aMap[r + rs] ) - aMap[r + rs] = new Array() ; - - for ( var cs = 0 ; cs < iColSpan ; cs++ ) - { - aMap[r + rs][c + cs] = aRows[i].cells[j] ; - } - } - - c += iColSpan - 1 ; - } - } - return aMap ; - } - function cellInRow( tableMap, rowIndex, cell ) { var oRow = tableMap[ rowIndex ]; @@ -498,7 +453,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var cell, firstCell = cells[ 0 ], table = firstCell.getAscendant( 'table' ), - map = buildTableMap( table ), + map = CKEDITOR.tools.buildTableMap( table ), mapHeight = map.length, mapWidth = map[ 0 ].length, startRow = firstCell.getParent().$.rowIndex, @@ -633,7 +588,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var cell = cells[ 0 ], tr = cell.getParent(), table = tr.getAscendant( 'table' ), - map = buildTableMap( table ), + map = CKEDITOR.tools.buildTableMap( table ), rowIndex = tr.$.rowIndex, colIndex = cellInRow( map, rowIndex, cell ), rowSpan = cell.$.rowSpan, @@ -709,7 +664,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var cell = cells[ 0 ], tr = cell.getParent(), table = tr.getAscendant( 'table' ), - map = buildTableMap( table ), + map = CKEDITOR.tools.buildTableMap( table ), rowIndex = tr.$.rowIndex, colIndex = cellInRow( map, rowIndex, cell ), colSpan = cell.$.colSpan, @@ -1088,7 +1043,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { editor.contextMenu.addListener( function( element, selection ) { - if ( !element ) + if ( !element || element.isReadOnly() ) return null; while ( element ) @@ -1114,3 +1069,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }; CKEDITOR.plugins.add( 'tabletools', CKEDITOR.plugins.tabletools ); })(); + +/** + * Create a two-dimension array that reflects the actual layout of table cells, + * with cell spans, with mappings to the original td elements. + * @param table {CKEDITOR.dom.element} + */ +CKEDITOR.tools.buildTableMap = function ( table ) +{ + var aRows = table.$.rows ; + + // Row and Column counters. + var r = -1 ; + + var aMap = []; + + for ( var i = 0 ; i < aRows.length ; i++ ) + { + r++ ; + !aMap[r] && ( aMap[r] = [] ); + + var c = -1 ; + + for ( var j = 0 ; j < aRows[i].cells.length ; j++ ) + { + var oCell = aRows[i].cells[j] ; + + c++ ; + while ( aMap[r][c] ) + c++ ; + + var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ; + var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ; + + for ( var rs = 0 ; rs < iRowSpan ; rs++ ) + { + if ( !aMap[r + rs] ) + aMap[r + rs] = []; + + for ( var cs = 0 ; cs < iColSpan ; cs++ ) + { + aMap[r + rs][c + cs] = aRows[i].cells[j] ; + } + } + + c += iColSpan - 1 ; + } + } + return aMap ; +};