Ticket #2430: 2430.patch
File 2430.patch, 8.2 KB (added by , 16 years ago) |
---|
-
editor/_source/internals/fckdomtools.js
1053 1053 } 1054 1054 1055 1055 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 ; 1056 1095 } 1096 1057 1097 } ; -
editor/dialog/fck_table.html
35 35 36 36 // Gets the document DOM 37 37 var oDOM = oEditor.FCK.EditorDocument ; 38 var FCKDomTools = oEditor.FCKDomTools ; 38 39 39 40 // Gets the table if there is one selected. 40 41 var table ; … … 87 88 88 89 var eCaption = oEditor.FCKDomTools.GetFirstChild( table, 'CAPTION' ) ; 89 90 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 ; 90 95 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 91 111 document.getElementById('txtRows').disabled = true ; 92 112 document.getElementById('txtColumns').disabled = true ; 93 113 SelectField( 'txtWidth' ) ; … … 104 124 { 105 125 var bExists = ( table != null ) ; 106 126 127 var oDoc = oEditor.FCK.EditorDocument ; 107 128 if ( ! bExists ) 108 table = o Editor.FCK.EditorDocument.createElement( "TABLE" ) ;129 table = oDoc.createElement( "TABLE" ) ; 109 130 110 131 // Removes the Width and Height styles 111 132 if ( bExists && table.style.width ) table.style.width = null ; //.removeAttribute("width") ; … … 129 150 { 130 151 if ( !eCaption ) 131 152 { 132 eCaption = o Editor.FCK.EditorDocument.createElement( 'CAPTION' ) ;153 eCaption = oDoc.createElement( 'CAPTION' ) ; 133 154 table.insertBefore( eCaption, table.firstChild ) ; 134 155 } 135 156 … … 145 166 eCaption.parentNode.removeChild( eCaption ) ; 146 167 } 147 168 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 148 232 if (! bExists) 149 233 { 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 ; 152 236 153 for ( var r = 0 ; r < iRows ; r++ ) 237 var startRow = 0 ; 238 // Should we make a <thead> ? 239 if (GetE('chkThead').checked) 154 240 { 241 startRow++ ; 242 var oThead = table.createTHead() ; 155 243 var oRow = table.insertRow(-1) ; 244 oThead.appendChild(oRow); 245 156 246 for ( var c = 0 ; c < iCols ; c++ ) 157 247 { 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 { 158 278 var oCell = oRow.insertCell(-1) ; 159 279 if ( oEditor.FCKBrowserInfo.IsGeckoLike ) 160 280 oEditor.FCKTools.AppendBogusBr( oCell ) ; 161 281 } 162 282 } 163 164 283 oEditor.FCKUndo.SaveUndoStep() ; 165 284 166 285 oEditor.FCK.InsertElement( table ) ; … … 194 313 onkeypress="return IsDigit(event);" /></td> 195 314 </tr> 196 315 <tr> 197 <td> 198 </td> 199 <td> 200 </td> 316 <td><span fckLang="DlgThead">Table Header</span>:</td> 317 <td><input id="chkThead" type="checkbox"></td> 201 318 </tr> 202 319 <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> 203 324 <td> 204 325 <span fcklang="DlgTableBorder">Border size</span>:</td> 205 326 <td> … … 244 365 <span fcklang="DlgTableWidthPx">pixels</span></td> 245 366 </tr> 246 367 <tr> 247 <td> 248 </td> 249 <td> 250 </td> 251 <td> 252 </td> 368 <td> </td> 369 <td> </td> 370 <td> </td> 253 371 </tr> 254 372 <tr> 373 <td> </td> 374 <td> </td> 375 <td> </td> 376 </tr> 377 <tr> 255 378 <td nowrap="nowrap"> 256 379 <span fcklang="DlgTableCellSpace">Cell spacing</span>:</td> 257 380 <td>