Ticket #2430: 2430.patch

File 2430.patch, 8.2 KB (added by Alfonso Martínez de Lizarrondo, 16 years ago)

Updated patch

  • editor/_source/internals/fckdomtools.js

     
    10531053                }
    10541054
    10551055                return currentBlocks ;
     1056        },
     1057
     1058        // Replaces a tag with another one, keeping its contents:
     1059        // for example TD --> TH, and TH --> TD.
     1060        // input: the original node, and the new tag name
     1061        // http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-renameNode
     1062        RenameNode : function( oNode , newTag )
     1063        {
     1064                // TODO: if the browser natively supports document.renameNode call it.
     1065                // does any browser currently support it in order to test?
     1066
     1067                // Only rename element nodes.
     1068                if ( oNode.nodeType != 1 )
     1069                        return null ;
     1070
     1071                // If it's already correct exit here.
     1072                if ( oNode.nodeName == newTag )
     1073                        return oNode ;
     1074
     1075                var oDoc = oNode.ownerDocument ;
     1076                // Create the new node
     1077                var newNode = oDoc.createElement( newTag ) ;
     1078
     1079                // Copy all attributes
     1080                var at = oNode.attributes ;
     1081                for( var i=0 ; i < at.length ; i++ )
     1082                {
     1083                        if ( at[i] && at[i].nodeValue != "" && at[i].nodeValue != null )
     1084                                newNode.setAttribute( at[i].nodeName, at[i].nodeValue ) ;
     1085                }
     1086
     1087                // Move children to the new node
     1088                while( oNode.firstChild )
     1089                        newNode.appendChild( oNode.firstChild ) ;
     1090
     1091                // Finally replace the node and return the new one
     1092                oNode.parentNode.replaceChild( newNode, oNode ) ;
     1093
     1094                return newNode ;
    10561095        }
     1096
    10571097} ;
  • editor/dialog/fck_table.html

     
    3535
    3636// Gets the document DOM
    3737var oDOM = oEditor.FCK.EditorDocument ;
     38var FCKDomTools = oEditor.FCKDomTools ;
    3839
    3940// Gets the table if there is one selected.
    4041var table ;
     
    8788
    8889                var eCaption = oEditor.FCKDomTools.GetFirstChild( table, 'CAPTION' ) ;
    8990                if ( eCaption ) document.getElementById('txtCaption').value = eCaption.innerHTML ;
     91               
     92                // Check if the table contains <thead>
     93                if (table.tHead)
     94                        GetE('chkThead').checked = true ;
    9095
     96                // Check if all the first cells in every row are TH
     97                GetE('HeaderCol').value = 1 ;
     98                GetE('chkFirstColTh').checked = true ;
     99                for (var row=0; row<table.rows.length; row++)
     100                {
     101                        // If just one cell isn't a TH then it isn't a header column
     102                        if ( table.rows[row].cells[0].nodeName != 'TH' )
     103                        {
     104                                GetE('chkFirstColTh').checked = false ;
     105                                GetE('HeaderCol').value = 0 ;
     106                               
     107                                break;
     108                        }
     109                }
     110
    91111                document.getElementById('txtRows').disabled    = true ;
    92112                document.getElementById('txtColumns').disabled = true ;
    93113                SelectField( 'txtWidth' ) ;
     
    104124{
    105125        var bExists = ( table != null ) ;
    106126
     127        var oDoc = oEditor.FCK.EditorDocument ;
    107128        if ( ! bExists )
    108                 table = oEditor.FCK.EditorDocument.createElement( "TABLE" ) ;
     129                table = oDoc.createElement( "TABLE" ) ;
    109130
    110131        // Removes the Width and Height styles
    111132        if ( bExists && table.style.width )             table.style.width = null ; //.removeAttribute("width") ;
     
    129150        {
    130151                if ( !eCaption )
    131152                {
    132                         eCaption = oEditor.FCK.EditorDocument.createElement( 'CAPTION' ) ;
     153                        eCaption = oDoc.createElement( 'CAPTION' ) ;
    133154                        table.insertBefore( eCaption, table.firstChild ) ;
    134155                }
    135156
     
    145166                        eCaption.parentNode.removeChild( eCaption ) ;
    146167        }
    147168
     169        if ( bExists )
     170        {
     171                // Should we make a <thead>?
     172                if ( table.tHead==null && GetE('chkThead').checked )
     173                {
     174                        var oThead = table.createTHead() ;
     175                        var tbody = FCKDomTools.GetFirstChild( table, 'TBODY' ) ;
     176                        var theRow= FCKDomTools.GetFirstChild( tbody, 'TR' ) ;
     177
     178                        //now change TD to TH:
     179                        for (var i = 0; i<theRow.childNodes.length ; i++)
     180                        {
     181                                var th = FCKDomTools.RenameNode(theRow.childNodes[i], 'TH') ;
     182                                if (th != null)
     183                                        th.scope='col' ;
     184                        }
     185                        oThead.appendChild( theRow ) ;
     186                }
     187
     188                if ( table.tHead!=null && !GetE('chkThead').checked )
     189                {
     190                        // Move the row out of the THead and put it in the TBody:
     191                        var tHead = table.tHead ;
     192                        var tbody = FCKDomTools.GetFirstChild( table, 'TBODY' ) ;
     193
     194                        var previousFirstRow = tbody.firstChild ;
     195                        while ( tHead.firstChild )
     196                        {
     197                                var theRow = tHead.firstChild ;
     198                                for (var i = 0; i < theRow.childNodes.length ; i++ )
     199                                {
     200                                        var newCell = FCKDomTools.RenameNode( theRow.childNodes[i], 'TD' ) ;
     201                                        if ( newCell != null )
     202                                                newCell.removeAttribute( 'scope' ) ;
     203                                }
     204                                tbody.insertBefore( theRow, previousFirstRow ) ;
     205                        }
     206                        table.removeChild( tHead ) ;
     207                }
     208
     209                // Should we make all first cells in a row TH?
     210                if ( (GetE('HeaderCol').value == 0)  && GetE('chkFirstColTh').checked )
     211                {
     212                        for( var row=0 ; row < table.rows.length ; row++ )
     213                        {
     214                                var newCell = FCKDomTools.RenameNode(table.rows[row].cells[0], 'TH') ;
     215                                if ( newCell != null )
     216                                        newCell.scope = 'col' ;
     217                        }
     218                }
     219
     220                // Should we make all first TH-cells in a row make TD? If 'yes' we do it the other way round :-)
     221                if ( (GetE('HeaderCol').value == 1)  && !GetE('chkFirstColTh').checked )
     222                {
     223                        for( var row=0 ; row < table.rows.length ; row++ )
     224                        {
     225                                var newCell = FCKDomTools.RenameNode(table.rows[row].cells[0], 'TD') ;
     226                                if (newCell != null)
     227                                        newCell.removeAttribute( 'scope' ) ;
     228                        }
     229                }
     230        }
     231
    148232        if (! bExists)
    149233        {
    150                 var iRows = document.getElementById('txtRows').value ;
    151                 var iCols = document.getElementById('txtColumns').value ;
     234                var iRows = GetE('txtRows').value ;
     235                var iCols = GetE('txtColumns').value ;
    152236
    153                 for ( var r = 0 ; r < iRows ; r++ )
     237                var startRow = 0 ;
     238                // Should we make a <thead> ?
     239                if (GetE('chkThead').checked)
    154240                {
     241                        startRow++ ;
     242                        var oThead = table.createTHead() ;
    155243                        var oRow = table.insertRow(-1) ;
     244                        oThead.appendChild(oRow);
     245                       
    156246                        for ( var c = 0 ; c < iCols ; c++ )
    157247                        {
     248                                var oThcell = oDoc.createElement( 'TH' ) ;
     249                                oThcell.scope = 'col' ;
     250                                oRow.appendChild( oThcell ) ;
     251                                if ( oEditor.FCKBrowserInfo.IsGeckoLike )
     252                                        oEditor.FCKTools.AppendBogusBr( oThcell ) ;
     253                        }
     254                }
     255
     256                var oTbody = oDoc.createElement( 'TBODY' ) ; // make TBODY
     257                table.appendChild( oTbody ) ;
     258
     259                for ( var r = startRow ; r < iRows; r++ )
     260                {
     261                        var oRow = oDoc.createElement( 'TR' ) ;
     262                        oTbody.appendChild(oRow) ;
     263
     264                        var startCol = 0 ;
     265                        // Is the first column a header?
     266                        if (GetE('chkFirstColTh').checked)
     267                        {
     268                                var oThcell = oDoc.createElement( 'TH' ) ;
     269                                oThcell.scope = 'row' ;
     270                                oRow.appendChild( oThcell ) ;
     271                                if ( oEditor.FCKBrowserInfo.IsGeckoLike )
     272                                        oEditor.FCKTools.AppendBogusBr( oThcell ) ;
     273
     274                                startCol++ ;
     275                        }
     276                        for ( var c = startCol ; c < iCols ; c++ )
     277                        {
    158278                                var oCell = oRow.insertCell(-1) ;
    159279                                if ( oEditor.FCKBrowserInfo.IsGeckoLike )
    160280                                        oEditor.FCKTools.AppendBogusBr( oCell ) ;
    161281                        }
    162282                }
    163 
    164283                oEditor.FCKUndo.SaveUndoStep() ;
    165284
    166285                oEditor.FCK.InsertElement( table ) ;
     
    194313                                                                                        onkeypress="return IsDigit(event);" /></td>
    195314                                                                </tr>
    196315                                                                <tr>
    197                                                                         <td>
    198                                                                                 &nbsp;</td>
    199                                                                         <td>
    200                                                                                 &nbsp;</td>
     316                                                                        <td><span fckLang="DlgThead">Table Header</span>:</td>
     317                                                                        <td><input id="chkThead" type="checkbox"></td>
    201318                                                                </tr>
    202319                                                                <tr>
     320                                                                        <td><span fckLang="DlgFirstColTh">First column header</span>:</td>
     321                                                                        <td><input id="chkFirstColTh" type="checkbox"><input type="hidden" id="HeaderCol" value="0" /></td>
     322                                                                </tr>
     323                                                                <tr>
    203324                                                                        <td>
    204325                                                                                <span fcklang="DlgTableBorder">Border size</span>:</td>
    205326                                                                        <td>
     
    244365                                                                                &nbsp;<span fcklang="DlgTableWidthPx">pixels</span></td>
    245366                                                                </tr>
    246367                                                                <tr>
    247                                                                         <td>
    248                                                                                 &nbsp;</td>
    249                                                                         <td>
    250                                                                                 &nbsp;</td>
    251                                                                         <td>
    252                                                                                 &nbsp;</td>
     368                                                                        <td>&nbsp;</td>
     369                                                                        <td>&nbsp;</td>
     370                                                                        <td>&nbsp;</td>
    253371                                                                </tr>
    254372                                                                <tr>
     373                                                                        <td>&nbsp;</td>
     374                                                                        <td>&nbsp;</td>
     375                                                                        <td>&nbsp;</td>
     376                                                                </tr>
     377                                                                <tr>
    255378                                                                        <td nowrap="nowrap">
    256379                                                                                <span fcklang="DlgTableCellSpace">Cell spacing</span>:</td>
    257380                                                                        <td>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy