|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/* |
|
|
|
|
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
|
|
|
|
* Copyright (C) 2003-2008 Frederico Caldeira Knabben |
|
|
|
|
* Copyright (C) 2003-2009 Frederico Caldeira Knabben |
|
|
|
|
* |
|
|
|
|
* == BEGIN LICENSE == |
|
|
|
|
* |
|
|
|
@ -52,7 +52,7 @@ FCKTableHandler.DeleteRows = function( row ) |
|
|
|
|
//queue up the rows -- it's possible ( and likely ) that we may get duplicates
|
|
|
|
|
for ( var i = 0; i < aCells.length; i++ ) |
|
|
|
|
{ |
|
|
|
|
var oRow = FCKTools.GetElementAscensor( aCells[i],'TR' ) ; |
|
|
|
|
var oRow = aCells[i].parentNode ; |
|
|
|
|
aRowsToDelete[oRow.rowIndex] = oRow ; |
|
|
|
|
} |
|
|
|
|
for ( var i = aRowsToDelete.length; i >= 0; i-- ) |
|
|
|
@ -118,13 +118,13 @@ FCKTableHandler.InsertColumn = function( insertBefore ) |
|
|
|
|
|
|
|
|
|
var iIndex = oCell.cellIndex ; |
|
|
|
|
|
|
|
|
|
// Loop throw all rows available in the table.
|
|
|
|
|
// Loop through all rows available in the table.
|
|
|
|
|
for ( var i = 0 ; i < oTable.rows.length ; i++ ) |
|
|
|
|
{ |
|
|
|
|
// Get the row.
|
|
|
|
|
var oRow = oTable.rows[i] ; |
|
|
|
|
|
|
|
|
|
// If the row doens't have enough cells, ignore it.
|
|
|
|
|
// If the row doesn't have enough cells, ignore it.
|
|
|
|
|
if ( oRow.cells.length < ( iIndex + 1 ) ) |
|
|
|
|
continue ; |
|
|
|
|
|
|
|
|
@ -136,12 +136,7 @@ FCKTableHandler.InsertColumn = function( insertBefore ) |
|
|
|
|
// Get back the currently selected cell.
|
|
|
|
|
var oBaseCell = oRow.cells[iIndex] ; |
|
|
|
|
|
|
|
|
|
if ( insertBefore ) |
|
|
|
|
oRow.insertBefore( oCell, oBaseCell ) ; |
|
|
|
|
else if ( oBaseCell.nextSibling ) |
|
|
|
|
oRow.insertBefore( oCell, oBaseCell.nextSibling ) ; |
|
|
|
|
else |
|
|
|
|
oRow.appendChild( oCell ) ; |
|
|
|
|
oRow.insertBefore( oCell, ( insertBefore ? oBaseCell : oBaseCell.nextSibling ) ) ; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -218,7 +213,7 @@ FCKTableHandler.DeleteCell = function( cell ) |
|
|
|
|
if ( cell.parentNode.cells.length == 1 ) |
|
|
|
|
{ |
|
|
|
|
// Delete the entire row.
|
|
|
|
|
FCKTableHandler.DeleteRows( FCKTools.GetElementAscensor( cell, 'TR' ) ) ; |
|
|
|
|
FCKTableHandler.DeleteRows( cell.parentNode ) ; |
|
|
|
|
return ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -246,10 +241,7 @@ FCKTableHandler._UnmarkCells = function( cells, label ) |
|
|
|
|
{ |
|
|
|
|
for ( var i = 0 ; i < cells.length ; i++ ) |
|
|
|
|
{ |
|
|
|
|
if ( FCKBrowserInfo.IsIE ) |
|
|
|
|
cells[i].removeAttribute( label ) ; |
|
|
|
|
else |
|
|
|
|
delete cells[i][label] ; |
|
|
|
|
FCKDomTools.ClearElementJSProperty(cells[i], label ) ; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -385,12 +377,12 @@ FCKTableHandler.MergeCells = function() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ( rowChildNodesCount > 0 ) |
|
|
|
|
cellContents.appendChild( FCKTools.GetElementDocument( refCell ).createElement( 'br' ) ) ; |
|
|
|
|
cellContents.appendChild( FCK.EditorDocument.createElement( 'br' ) ) ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ; |
|
|
|
|
this._UnmarkCells( cells, '_SelectedCells' ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ; |
|
|
|
|
refCell.appendChild( cellContents ) ; |
|
|
|
|
|
|
|
|
|
if ( FCKBrowserInfo.IsGeckoLike && ( ! refCell.firstChild ) ) |
|
|
|
@ -416,7 +408,7 @@ FCKTableHandler.MergeRight = function() |
|
|
|
|
refCell.appendChild( cellContents ) ; |
|
|
|
|
this._MarkCells( [nextCell], '_Replace' ) ; |
|
|
|
|
this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ; |
|
|
|
|
|
|
|
|
|
this._MoveCaretToCell( refCell, false ) ; |
|
|
|
|
} |
|
|
|
@ -434,11 +426,11 @@ FCKTableHandler.MergeDown = function() |
|
|
|
|
while ( nextCell && nextCell.childNodes && nextCell.childNodes.length > 0 ) |
|
|
|
|
cellContents.appendChild( nextCell.removeChild( nextCell.firstChild ) ) ; |
|
|
|
|
if ( cellContents.firstChild ) |
|
|
|
|
cellContents.insertBefore( FCKTools.GetElementDocument( nextCell ).createElement( 'br' ), cellContents.firstChild ) ; |
|
|
|
|
cellContents.insertBefore( FCK.EditorDocument.createElement( 'br' ), cellContents.firstChild ) ; |
|
|
|
|
refCell.appendChild( cellContents ) ; |
|
|
|
|
this._MarkCells( [nextCell], '_Replace' ) ; |
|
|
|
|
this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ; |
|
|
|
|
|
|
|
|
|
this._MoveCaretToCell( refCell, false ) ; |
|
|
|
|
} |
|
|
|
@ -504,7 +496,7 @@ FCKTableHandler.HorizontalSplitCell = function() |
|
|
|
|
tableMap = newTableMap ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ; |
|
|
|
|
this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FCKTableHandler.VerticalSplitCell = function() |
|
|
|
@ -518,7 +510,7 @@ FCKTableHandler.VerticalSplitCell = function() |
|
|
|
|
var currentRowIndex = currentCell.parentNode.rowIndex ; |
|
|
|
|
var cellIndex = FCKTableHandler._GetCellIndexSpan( tableMap, currentRowIndex, currentCell ) ; |
|
|
|
|
// Save current cell colSpan
|
|
|
|
|
var currentColSpan = isNaN( currentCell.colSpan ) ? 1 : currentCell.colSpan ;
|
|
|
|
|
var currentColSpan = isNaN( currentCell.colSpan ) ? 1 : currentCell.colSpan ; |
|
|
|
|
var currentRowSpan = currentCell.rowSpan ; |
|
|
|
|
if ( isNaN( currentRowSpan ) ) |
|
|
|
|
currentRowSpan = 1 ; |
|
|
|
@ -548,18 +540,18 @@ FCKTableHandler.VerticalSplitCell = function() |
|
|
|
|
newCell.colSpan = currentColSpan ; |
|
|
|
|
if ( FCKBrowserInfo.IsGeckoLike ) |
|
|
|
|
FCKTools.AppendBogusBr( newCell ) ; |
|
|
|
|
currentCell.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ; |
|
|
|
|
currentCell.parentNode.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// 1. Insert a new row.
|
|
|
|
|
var newCellRowIndex = currentRowIndex + 1 ; |
|
|
|
|
var newSectionRowIdx = currentCell.parentNode.sectionRowIndex + 1 ; |
|
|
|
|
var newRow = FCK.EditorDocument.createElement( 'tr' ) ; |
|
|
|
|
var tBody = currentCell.parentNode.parentNode ; |
|
|
|
|
if ( tBody.rows.length > newCellRowIndex ) |
|
|
|
|
tBody.insertBefore( newRow, tBody.rows[newCellRowIndex] ) ; |
|
|
|
|
var tSection = currentCell.parentNode.parentNode ; |
|
|
|
|
if ( tSection.rows.length > newSectionRowIdx ) |
|
|
|
|
tSection.insertBefore( newRow, tSection.rows[newSectionRowIdx] ) ; |
|
|
|
|
else |
|
|
|
|
tBody.appendChild( newRow ) ; |
|
|
|
|
tSection.appendChild( newRow ) ; |
|
|
|
|
|
|
|
|
|
// 2. +1 to rowSpan for all cells crossing currentCell's row.
|
|
|
|
|
for ( var i = 0 ; i < tableMap[currentRowIndex].length ; ) |
|
|
|
@ -582,7 +574,7 @@ FCKTableHandler.VerticalSplitCell = function() |
|
|
|
|
// 3. Insert a new cell to new row. Set colSpan on the new cell.
|
|
|
|
|
var newCell = FCK.EditorDocument.createElement( currentCell.nodeName ) ; |
|
|
|
|
if ( currentColSpan > 1 ) |
|
|
|
|
newCell.colSpan = currentColSpan ;
|
|
|
|
|
newCell.colSpan = currentColSpan ; |
|
|
|
|
if ( FCKBrowserInfo.IsGeckoLike ) |
|
|
|
|
FCKTools.AppendBogusBr( newCell ) ; |
|
|
|
|
newRow.appendChild( newCell ) ; |
|
|
|
@ -619,31 +611,16 @@ FCKTableHandler._GetCellLocation = function( tableMap, cell ) |
|
|
|
|
return null ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get the cells available in a column of a TableMap.
|
|
|
|
|
FCKTableHandler._GetColumnCells = function( tableMap, columnIndex ) |
|
|
|
|
{ |
|
|
|
|
var aCollCells = new Array() ; |
|
|
|
|
|
|
|
|
|
for ( var r = 0 ; r < tableMap.length ; r++ ) |
|
|
|
|
{ |
|
|
|
|
var oCell = tableMap[r][columnIndex] ; |
|
|
|
|
if ( oCell && ( aCollCells.length == 0 || aCollCells[ aCollCells.length - 1 ] != oCell ) ) |
|
|
|
|
aCollCells[ aCollCells.length ] = oCell ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return aCollCells ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This function is quite hard to explain. It creates a matrix representing all cells in a table.
|
|
|
|
|
// The difference here is that the "spanned" cells (colSpan and rowSpan) are duplicated on the matrix
|
|
|
|
|
// cells that are "spanned". For example, a row with 3 cells where the second cell has colSpan=2 and rowSpan=3
|
|
|
|
|
// will produce a bi-dimensional matrix with the following values (representing the cells):
|
|
|
|
|
// Cell1, Cell2, Cell2, Cell2, Cell 3
|
|
|
|
|
// Cell4, Cell2, Cell2, Cell2, Cell 5
|
|
|
|
|
// Cell1, Cell2, Cell2, Cell3
|
|
|
|
|
// Cell4, Cell2, Cell2, Cell5
|
|
|
|
|
// Cell6, Cell2, Cell2, Cell7
|
|
|
|
|
FCKTableHandler._CreateTableMap = function( refCell ) |
|
|
|
|
{ |
|
|
|
|
// It's really a tbody, thead or tfoot. This is only temporary.
|
|
|
|
|
var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode ) ; |
|
|
|
|
var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode.parentNode ) ; |
|
|
|
|
|
|
|
|
|
var aRows = table.rows ; |
|
|
|
|
|
|
|
|
@ -696,13 +673,6 @@ FCKTableHandler._InstallTableMap = function( tableMap, table ) |
|
|
|
|
// for storing the calculated rowSpan in IE.
|
|
|
|
|
var rowSpanAttr = FCKBrowserInfo.IsIE ? "_fckrowspan" : "rowSpan" ; |
|
|
|
|
|
|
|
|
|
// Clear the table of all rows first.
|
|
|
|
|
while ( table.rows.length > 0 ) |
|
|
|
|
{ |
|
|
|
|
var row = table.rows[0] ; |
|
|
|
|
row.parentNode.removeChild( row ) ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Disconnect all the cells in tableMap from their parents, set all colSpan and rowSpan attributes to 1.
|
|
|
|
|
for ( var i = 0 ; i < tableMap.length ; i++ ) |
|
|
|
|
{ |
|
|
|
@ -758,23 +728,15 @@ FCKTableHandler._InstallTableMap = function( tableMap, table ) |
|
|
|
|
for ( var j = 0 ; j < tableMap[i].length ; j++) |
|
|
|
|
{ |
|
|
|
|
var cell = tableMap[i][j] ; |
|
|
|
|
if ( FCKBrowserInfo.IsIE ) |
|
|
|
|
{ |
|
|
|
|
cell.removeAttribute( '_colScanned' ) ; |
|
|
|
|
cell.removeAttribute( '_rowScanned' ) ; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
delete cell._colScanned ; |
|
|
|
|
delete cell._rowScanned ; |
|
|
|
|
} |
|
|
|
|
FCKDomTools.ClearElementJSProperty(cell, '_colScanned' ) ; |
|
|
|
|
FCKDomTools.ClearElementJSProperty(cell, '_rowScanned' ) ; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Insert physical rows and columns to the table.
|
|
|
|
|
for ( var i = 0 ; i < tableMap.length ; i++ ) |
|
|
|
|
{ |
|
|
|
|
var rowObj = FCKTools.GetElementDocument( table ).createElement( 'tr' ) ; |
|
|
|
|
var rowObj = FCK.EditorDocument.createElement( 'tr' ) ; |
|
|
|
|
for ( var j = 0 ; j < tableMap[i].length ; ) |
|
|
|
|
{ |
|
|
|
|
var cell = tableMap[i][j] ; |
|
|
|
@ -795,7 +757,15 @@ FCKTableHandler._InstallTableMap = function( tableMap, table ) |
|
|
|
|
if ( cell.rowSpan == 1 ) |
|
|
|
|
cell.removeAttribute( 'rowspan' ) ; |
|
|
|
|
} |
|
|
|
|
table.appendChild( rowObj ) ; |
|
|
|
|
if ( FCKBrowserInfo.IsIE ) |
|
|
|
|
{ |
|
|
|
|
table.rows[i].replaceNode( rowObj ) ; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
table.rows[i].innerHTML = '' ; |
|
|
|
|
FCKDomTools.MoveChildren( rowObj, table.rows[i] ) ; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|